Skip to content

Commit e04b4e1

Browse files
authored
Merge pull request #252 from joe733/workshop
maint: improves `i18n` package
2 parents 664b705 + b13b2f6 commit e04b4e1

File tree

9 files changed

+416
-343
lines changed

9 files changed

+416
-343
lines changed

pyproject.toml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bandit = "^1.7.5"
4545
[tool.poetry.group.tests.dependencies]
4646
pytest = "^7.2.2"
4747

48-
[tool.poetry.group.type-lint-fmt.dependencies]
48+
[tool.poetry.group.type-lint-format.dependencies]
4949
black = "^23.1.0"
5050
flake8 = "^5.0.4"
5151
flake8-docstrings = "^1.7.0"
@@ -56,26 +56,24 @@ pyright = "^1.1.299"
5656
requires = ["poetry-core"]
5757
build-backend = "poetry.core.masonry.api"
5858

59-
################################
60-
# formatters, linters, testers #
61-
################################
59+
#######################
60+
# misc configurations #
61+
#######################
6262

6363
[tool.black]
6464
line-length = 100
6565
target-version = ["py38", "py39", "py310", "py311"]
66-
extend-exclude = "i18n"
6766

6867
[tool.bandit]
6968
exclude_dirs = [".github", ".pytest_cache", ".tox", ".vscode", "site", "tests"]
7069

7170
[tool.isort]
7271
ensure_newline_before_comments = true
73-
extend_skip_glob = ["**/i18n/*"]
7472
force_grid_wrap = 0
7573
force_sort_within_sections = true
74+
import_heading_localfolder = "local"
7675
import_heading_stdlib = "standard"
7776
import_heading_thirdparty = "external"
78-
import_heading_localfolder = "local"
7977
include_trailing_comma = true
8078
known_local_folder = ["validators"]
8179
length_sort = true
@@ -89,7 +87,7 @@ use_parentheses = true
8987

9088
[tool.pyright]
9189
include = ["validators", "tests"]
92-
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", "site/", "**/i18n/*"]
90+
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", "site/"]
9391
pythonVersion = "3.8"
9492
pythonPlatform = "All"
9593
typeCheckingMode = "strict"
@@ -100,22 +98,22 @@ legacy_tox_ini = """
10098
min_version = 4.0
10199
env_list =
102100
py{38,39,310,311}
103-
fmt_black
104-
fmt_isort
101+
format_black
102+
format_isort
105103
lint
106-
type
104+
type_check
107105
108106
[testenv]
109107
description = run unit tests
110108
deps = pytest
111109
commands = pytest tests/
112110
113-
[testenv:fmt_black]
111+
[testenv:format_black]
114112
description = run formatter
115113
deps = black
116114
commands = black .
117115
118-
[testenv:fmt_isort]
116+
[testenv:format_isort]
119117
description = run formatter
120118
deps = isort
121119
commands = isort .
@@ -125,7 +123,7 @@ description = run linters
125123
deps = flake8
126124
commands = flake8
127125
128-
[testenv:type]
126+
[testenv:type_check]
129127
description = run type checker
130128
deps =
131129
pyright

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
[flake8]
44
docstring-convention = google
5-
exclude = __pycache__,.github,.pytest_cache,.tox,.venv,.vscode,site,i18n
5+
exclude = __pycache__,.github,.pytest_cache,.tox,.venv,.vscode,site
66
max-line-length = 100

tests/i18n/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Test i18n."""
2+
# -*- coding: utf-8 -*-
3+
4+
# isort: skip_file

tests/i18n/test_es.py

Lines changed: 109 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,132 @@
1+
"""Test i18n/es."""
12
# -*- coding: utf-8 -*-
3+
4+
# external
25
import pytest
36

4-
from validators import ValidationFailure
5-
from validators.i18n.es import es_cif, es_doi, es_nie, es_nif
7+
# local
8+
from validators import es_nif, es_nie, es_doi, es_cif, ValidationFailure
69

710

8-
@pytest.mark.parametrize(('value',), [
9-
('B25162520',),
10-
('U4839822F',),
11-
('B96817697',),
12-
('P7067074J',),
13-
('Q7899705C',),
14-
('C75098681',),
15-
('G76061860',),
16-
('C71345375',),
17-
('G20558169',),
18-
('U5021960I',),
19-
])
20-
def test_returns_true_on_valid_cif(value):
11+
@pytest.mark.parametrize(
12+
("value",),
13+
[
14+
("B25162520",),
15+
("U4839822F",),
16+
("B96817697",),
17+
("P7067074J",),
18+
("Q7899705C",),
19+
("C75098681",),
20+
("G76061860",),
21+
("C71345375",),
22+
("G20558169",),
23+
("U5021960I",),
24+
],
25+
)
26+
def test_returns_true_on_valid_cif(value: str):
27+
"""Test returns true on valid cif."""
2128
assert es_cif(value)
2229

2330

24-
@pytest.mark.parametrize(('value',), [
25-
('12345',),
26-
('ABCDEFGHI',),
27-
('Z5021960I',),
28-
])
29-
def test_returns_false_on_invalid_cif(value):
31+
@pytest.mark.parametrize(
32+
("value",),
33+
[
34+
("12345",),
35+
("ABCDEFGHI",),
36+
("Z5021960I",),
37+
],
38+
)
39+
def test_returns_false_on_invalid_cif(value: str):
40+
"""Test returns false on invalid cif."""
3041
result = es_cif(value)
3142
assert isinstance(result, ValidationFailure)
3243

3344

34-
@pytest.mark.parametrize(('value',), [
35-
('X0095892M',),
36-
('X8868108K',),
37-
('X2911154K',),
38-
('Y2584969J',),
39-
('X7536157T',),
40-
('Y5840388N',),
41-
('Z2915723H',),
42-
('Y4002236C',),
43-
('X7750702R',),
44-
('Y0408759V',),
45-
])
46-
def test_returns_true_on_valid_nie(value):
45+
@pytest.mark.parametrize(
46+
("value",),
47+
[
48+
("X0095892M",),
49+
("X8868108K",),
50+
("X2911154K",),
51+
("Y2584969J",),
52+
("X7536157T",),
53+
("Y5840388N",),
54+
("Z2915723H",),
55+
("Y4002236C",),
56+
("X7750702R",),
57+
("Y0408759V",),
58+
],
59+
)
60+
def test_returns_true_on_valid_nie(value: str):
61+
"""Test returns true on valid nie."""
4762
assert es_nie(value)
4863

4964

50-
@pytest.mark.parametrize(('value',), [
51-
('K0000023T',),
52-
('L0000024R',),
53-
('M0000025W',),
54-
('00000026A',),
55-
('00000027G',),
56-
('00000028M',),
57-
('00000029Y',),
58-
('00000030F',),
59-
('00000031P',),
60-
('00000032D',),
61-
('00000033X',),
62-
('00000034B',),
63-
('00000035N',),
64-
('00000036J',),
65-
('00000037Z',),
66-
('00000038S',),
67-
('00000039Q',),
68-
('00000040V',),
69-
('00000041H',),
70-
('00000042L',),
71-
('00000043C',),
72-
('00000044K',),
73-
('00000045E',),
74-
])
75-
def test_returns_true_on_valid_nif(value):
65+
@pytest.mark.parametrize(
66+
("value",),
67+
[
68+
("K0000023T",),
69+
("L0000024R",),
70+
("M0000025W",),
71+
("00000026A",),
72+
("00000027G",),
73+
("00000028M",),
74+
("00000029Y",),
75+
("00000030F",),
76+
("00000031P",),
77+
("00000032D",),
78+
("00000033X",),
79+
("00000034B",),
80+
("00000035N",),
81+
("00000036J",),
82+
("00000037Z",),
83+
("00000038S",),
84+
("00000039Q",),
85+
("00000040V",),
86+
("00000041H",),
87+
("00000042L",),
88+
("00000043C",),
89+
("00000044K",),
90+
("00000045E",),
91+
],
92+
)
93+
def test_returns_true_on_valid_nif(value: str):
94+
"""Test returns true on valid nif."""
7695
assert es_nif(value)
7796

7897

79-
@pytest.mark.parametrize(('value',), [
80-
('12345',),
81-
('X0000000T',),
82-
('00000000T',),
83-
('00000001R',),
84-
])
85-
def test_returns_false_on_invalid_nif(value):
98+
@pytest.mark.parametrize(
99+
("value",),
100+
[
101+
("12345",),
102+
("X0000000T",),
103+
("00000000T",),
104+
("00000001R",),
105+
],
106+
)
107+
def test_returns_false_on_invalid_nif(value: str):
108+
"""Test returns false on invalid nif."""
86109
result = es_nif(value)
87110
assert isinstance(result, ValidationFailure)
88111

89112

90-
@pytest.mark.parametrize(('value',), [
91-
# CIFs
92-
('B25162520',),
93-
('U4839822F',),
94-
('B96817697',),
95-
# NIEs
96-
('X0095892M',),
97-
('X8868108K',),
98-
('X2911154K',),
99-
# NIFs
100-
('26643189N',),
101-
('07060225F',),
102-
('49166693F',),
103-
])
104-
def test_returns_true_on_valid_doi(value):
113+
@pytest.mark.parametrize(
114+
("value",),
115+
[
116+
# CIFs
117+
("B25162520",),
118+
("U4839822F",),
119+
("B96817697",),
120+
# NIEs
121+
("X0095892M",),
122+
("X8868108K",),
123+
("X2911154K",),
124+
# NIFs
125+
("26643189N",),
126+
("07060225F",),
127+
("49166693F",),
128+
],
129+
)
130+
def test_returns_true_on_valid_doi(value: str):
131+
"""Test returns true on valid doi."""
105132
assert es_doi(value)

0 commit comments

Comments
 (0)