Skip to content

maint: improves i18n package #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bandit = "^1.7.5"
[tool.poetry.group.tests.dependencies]
pytest = "^7.2.2"

[tool.poetry.group.type-lint-fmt.dependencies]
[tool.poetry.group.type-lint-format.dependencies]
black = "^23.1.0"
flake8 = "^5.0.4"
flake8-docstrings = "^1.7.0"
Expand All @@ -56,26 +56,24 @@ pyright = "^1.1.299"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

################################
# formatters, linters, testers #
################################
#######################
# misc configurations #
#######################

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

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

[tool.isort]
ensure_newline_before_comments = true
extend_skip_glob = ["**/i18n/*"]
force_grid_wrap = 0
force_sort_within_sections = true
import_heading_localfolder = "local"
import_heading_stdlib = "standard"
import_heading_thirdparty = "external"
import_heading_localfolder = "local"
include_trailing_comma = true
known_local_folder = ["validators"]
length_sort = true
Expand All @@ -89,7 +87,7 @@ use_parentheses = true

[tool.pyright]
include = ["validators", "tests"]
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", "site/", "**/i18n/*"]
exclude = ["**/__pycache__", ".pytest_cache/", ".tox/", "site/"]
pythonVersion = "3.8"
pythonPlatform = "All"
typeCheckingMode = "strict"
Expand All @@ -100,22 +98,22 @@ legacy_tox_ini = """
min_version = 4.0
env_list =
py{38,39,310,311}
fmt_black
fmt_isort
format_black
format_isort
lint
type
type_check

[testenv]
description = run unit tests
deps = pytest
commands = pytest tests/

[testenv:fmt_black]
[testenv:format_black]
description = run formatter
deps = black
commands = black .

[testenv:fmt_isort]
[testenv:format_isort]
description = run formatter
deps = isort
commands = isort .
Expand All @@ -125,7 +123,7 @@ description = run linters
deps = flake8
commands = flake8

[testenv:type]
[testenv:type_check]
description = run type checker
deps =
pyright
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

[flake8]
docstring-convention = google
exclude = __pycache__,.github,.pytest_cache,.tox,.venv,.vscode,site,i18n
exclude = __pycache__,.github,.pytest_cache,.tox,.venv,.vscode,site
max-line-length = 100
4 changes: 4 additions & 0 deletions tests/i18n/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Test i18n."""
# -*- coding: utf-8 -*-

# isort: skip_file
191 changes: 109 additions & 82 deletions tests/i18n/test_es.py
Original file line number Diff line number Diff line change
@@ -1,105 +1,132 @@
"""Test i18n/es."""
# -*- coding: utf-8 -*-

# external
import pytest

from validators import ValidationFailure
from validators.i18n.es import es_cif, es_doi, es_nie, es_nif
# local
from validators import es_nif, es_nie, es_doi, es_cif, ValidationFailure


@pytest.mark.parametrize(('value',), [
('B25162520',),
('U4839822F',),
('B96817697',),
('P7067074J',),
('Q7899705C',),
('C75098681',),
('G76061860',),
('C71345375',),
('G20558169',),
('U5021960I',),
])
def test_returns_true_on_valid_cif(value):
@pytest.mark.parametrize(
("value",),
[
("B25162520",),
("U4839822F",),
("B96817697",),
("P7067074J",),
("Q7899705C",),
("C75098681",),
("G76061860",),
("C71345375",),
("G20558169",),
("U5021960I",),
],
)
def test_returns_true_on_valid_cif(value: str):
"""Test returns true on valid cif."""
assert es_cif(value)


@pytest.mark.parametrize(('value',), [
('12345',),
('ABCDEFGHI',),
('Z5021960I',),
])
def test_returns_false_on_invalid_cif(value):
@pytest.mark.parametrize(
("value",),
[
("12345",),
("ABCDEFGHI",),
("Z5021960I",),
],
)
def test_returns_false_on_invalid_cif(value: str):
"""Test returns false on invalid cif."""
result = es_cif(value)
assert isinstance(result, ValidationFailure)


@pytest.mark.parametrize(('value',), [
('X0095892M',),
('X8868108K',),
('X2911154K',),
('Y2584969J',),
('X7536157T',),
('Y5840388N',),
('Z2915723H',),
('Y4002236C',),
('X7750702R',),
('Y0408759V',),
])
def test_returns_true_on_valid_nie(value):
@pytest.mark.parametrize(
("value",),
[
("X0095892M",),
("X8868108K",),
("X2911154K",),
("Y2584969J",),
("X7536157T",),
("Y5840388N",),
("Z2915723H",),
("Y4002236C",),
("X7750702R",),
("Y0408759V",),
],
)
def test_returns_true_on_valid_nie(value: str):
"""Test returns true on valid nie."""
assert es_nie(value)


@pytest.mark.parametrize(('value',), [
('K0000023T',),
('L0000024R',),
('M0000025W',),
('00000026A',),
('00000027G',),
('00000028M',),
('00000029Y',),
('00000030F',),
('00000031P',),
('00000032D',),
('00000033X',),
('00000034B',),
('00000035N',),
('00000036J',),
('00000037Z',),
('00000038S',),
('00000039Q',),
('00000040V',),
('00000041H',),
('00000042L',),
('00000043C',),
('00000044K',),
('00000045E',),
])
def test_returns_true_on_valid_nif(value):
@pytest.mark.parametrize(
("value",),
[
("K0000023T",),
("L0000024R",),
("M0000025W",),
("00000026A",),
("00000027G",),
("00000028M",),
("00000029Y",),
("00000030F",),
("00000031P",),
("00000032D",),
("00000033X",),
("00000034B",),
("00000035N",),
("00000036J",),
("00000037Z",),
("00000038S",),
("00000039Q",),
("00000040V",),
("00000041H",),
("00000042L",),
("00000043C",),
("00000044K",),
("00000045E",),
],
)
def test_returns_true_on_valid_nif(value: str):
"""Test returns true on valid nif."""
assert es_nif(value)


@pytest.mark.parametrize(('value',), [
('12345',),
('X0000000T',),
('00000000T',),
('00000001R',),
])
def test_returns_false_on_invalid_nif(value):
@pytest.mark.parametrize(
("value",),
[
("12345",),
("X0000000T",),
("00000000T",),
("00000001R",),
],
)
def test_returns_false_on_invalid_nif(value: str):
"""Test returns false on invalid nif."""
result = es_nif(value)
assert isinstance(result, ValidationFailure)


@pytest.mark.parametrize(('value',), [
# CIFs
('B25162520',),
('U4839822F',),
('B96817697',),
# NIEs
('X0095892M',),
('X8868108K',),
('X2911154K',),
# NIFs
('26643189N',),
('07060225F',),
('49166693F',),
])
def test_returns_true_on_valid_doi(value):
@pytest.mark.parametrize(
("value",),
[
# CIFs
("B25162520",),
("U4839822F",),
("B96817697",),
# NIEs
("X0095892M",),
("X8868108K",),
("X2911154K",),
# NIFs
("26643189N",),
("07060225F",),
("49166693F",),
],
)
def test_returns_true_on_valid_doi(value: str):
"""Test returns true on valid doi."""
assert es_doi(value)
Loading