-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add language code definitions and test
- Loading branch information
1 parent
f6dba1e
commit 393f4e9
Showing
2 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
from typing import Literal | ||
|
||
# language code definition as defined in ISO 639-3 https://en.wikipedia.org/wiki/ISO_639-3 | ||
LanguageCode = Literal[ | ||
'aar', | ||
'abk', | ||
'afr', | ||
'aka', | ||
'alb', | ||
'amh', | ||
'ara', | ||
'arg', | ||
'arm', | ||
'asm', | ||
'ava', | ||
'ave', | ||
'aym', | ||
'aze', | ||
'bak', | ||
'bam', | ||
'baq', | ||
'bel', | ||
'ben', | ||
'bih', | ||
'bis', | ||
'bos', | ||
'bre', | ||
'bul', | ||
'bur', | ||
'cat', | ||
'cha', | ||
'che', | ||
'chi', | ||
'chu', | ||
'chv', | ||
'cor', | ||
'cos', | ||
'cre', | ||
'cze', | ||
'dan', | ||
'div', | ||
'dut', | ||
'dzo', | ||
'eng', | ||
'epo', | ||
'est', | ||
'ewe', | ||
'fao', | ||
'fij', | ||
'fin', | ||
'fre', | ||
'fry', | ||
'ful', | ||
'geo', | ||
'ger', | ||
'gla', | ||
'gle', | ||
'glg', | ||
'glv', | ||
'gre', | ||
'grn', | ||
'guj', | ||
'hat', | ||
'hau', | ||
'heb', | ||
'her', | ||
'hin', | ||
'hmo', | ||
'hrv', | ||
'hun', | ||
'ibo', | ||
'ice', | ||
'ido', | ||
'iii', | ||
'iku', | ||
'ile', | ||
'ina', | ||
'ind', | ||
'ipk', | ||
'ita', | ||
'jav', | ||
'jpn', | ||
'kal', | ||
'kan', | ||
'kas', | ||
'kau', | ||
'kaz', | ||
'khm', | ||
'kik', | ||
'kin', | ||
'kir', | ||
'kom', | ||
'kon', | ||
'kor', | ||
'kua', | ||
'kur', | ||
'lao', | ||
'lat', | ||
'lav', | ||
'lim', | ||
'lin', | ||
'lit', | ||
'ltz', | ||
'lub', | ||
'lug', | ||
'mac', | ||
'mah', | ||
'mal', | ||
'mao', | ||
'mar', | ||
'may', | ||
'mlg', | ||
'mlt', | ||
'mon', | ||
'nau', | ||
'nav', | ||
'nbl', | ||
'nde', | ||
'ndo', | ||
'nep', | ||
'nno', | ||
'nob', | ||
'nor', | ||
'nya', | ||
'oci', | ||
'oji', | ||
'ori', | ||
'orm', | ||
'oss', | ||
'pan', | ||
'per', | ||
'pli', | ||
'pol', | ||
'por', | ||
'pus', | ||
'que', | ||
'roh', | ||
'rum', | ||
'run', | ||
'rus', | ||
'sag', | ||
'san', | ||
'sin', | ||
'slo', | ||
'slv', | ||
'sme', | ||
'smo', | ||
'sna', | ||
'snd', | ||
'som', | ||
'sot', | ||
'spa', | ||
'srd', | ||
'srp', | ||
'ssw', | ||
'sun', | ||
'swa', | ||
'swe', | ||
'tah', | ||
'tam', | ||
'tat', | ||
'tel', | ||
'tgk', | ||
'tgl', | ||
'tha', | ||
'tib', | ||
'tir', | ||
'ton', | ||
'tsn', | ||
'tso', | ||
'tuk', | ||
'tur', | ||
'twi', | ||
'uig', | ||
'ukr', | ||
'urd', | ||
'uzb', | ||
'ven', | ||
'vie', | ||
'vol', | ||
'wel', | ||
'wln', | ||
'wol', | ||
'xho', | ||
'yid', | ||
'yor', | ||
'zha', | ||
'zul' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
from pydantic import BaseModel, ValidationError | ||
|
||
from pydantic_extra_types.language_code import LanguageCode | ||
|
||
|
||
class CheckingModel(BaseModel): | ||
lang: LanguageCode | ||
|
||
|
||
def test_language_ok(): | ||
model = CheckingModel(lang='eng') | ||
assert model.lang == 'eng' | ||
|
||
|
||
def test_language_fail(): | ||
with pytest.raises(ValidationError): | ||
CheckingModel(lang='en-US') |