Skip to content

Commit 4cf71db

Browse files
committed
Update pyproject.toml and MANIFEST.in.
1 parent 8874226 commit 4cf71db

25 files changed

+1318
-1367
lines changed

.github/workflows/test-package.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ jobs:
4343
4444
- name: Run tests
4545
run: |
46-
coverage run --append --source=codicefiscale -m unittest
47-
coverage report --show-missing
48-
coverage xml -o ./coverage.xml
46+
pytest tests --cov=codicefiscale --cov-report=term-missing --cov-fail-under=90
4947
5048
- name: Upload coverage to Codecov
5149
uses: codecov/codecov-action@v4

MANIFEST.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include LICENSE.txt
22
include README.md
3-
recursive-include codicefiscale *
3+
recursive-include src *
4+
recursive-include tests *
45
recursive-exclude * *.pyc __pycache__ .DS_Store

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ pre-commit install --install-hooks
134134
# run tests using tox
135135
tox
136136

137-
# or run tests using unittest
138-
python -m unittest tests.tests
137+
# or run tests using pytest
138+
pytest
139139
```
140140

141141
## License

pyproject.toml

+8-3
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ exclude = '''
7777
'''
7878

7979
[tool.mypy]
80-
files = ["codicefiscale"]
80+
files = ["src"]
8181
ignore_missing_imports = true
8282
install_types = true
8383
non_interactive = true
8484
strict = true
8585

86+
[tool.pytest.ini_options]
87+
pythonpath = "src"
88+
testpaths = ["tests"]
89+
8690
[tool.ruff]
8791
line-length = 88
8892

@@ -93,8 +97,9 @@ select = ["B", "B9", "C", "E", "F", "I", "W"]
9397
[tool.ruff.lint.mccabe]
9498
max-complexity = 10
9599

96-
[tool.setuptools.packages.find]
97-
include = ["codicefiscale*"]
100+
[tool.setuptools]
101+
package-dir = {"" = "src"}
102+
packages = ["codicefiscale"]
98103

99104
[tool.setuptools.dynamic.version]
100105
attr = "codicefiscale.metadata.__version__"

requirements-test.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
-e .
12
coverage == 7.6.*
23
mypy == 1.11.*
34
pre-commit == 4.0.*
5+
pytest==8.3.*
6+
pytest-cov == 6.0.*
47
tox == 4.22.*

tests/issues/__init__.py

Whitespace-only changes.

tests/issues/test_issue_0016.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from codicefiscale import codicefiscale
2+
3+
4+
def test_issue_0016():
5+
"""
6+
Decode return GIRGENTI (soppresso) instead of AGRIGENTO
7+
"""
8+
data = codicefiscale.decode("LNNFNC80A01A089K")
9+
expected_birthplace = {
10+
"code": "A089",
11+
"province": "AG",
12+
"name": "AGRIGENTO",
13+
}
14+
birthplace = data["birthplace"]
15+
assert birthplace["code"] == expected_birthplace["code"]
16+
assert birthplace["name"].upper() == expected_birthplace["name"]
17+
assert birthplace["province"] == expected_birthplace["province"]

tests/issues/test_issue_0036.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from codicefiscale import codicefiscale
4+
5+
test_data = [
6+
("CCCFBA85D03Z105P", "Cecoslovacchia"),
7+
("CCCFBA85D03Z111D", "Repubblica Democratica Tedesca"),
8+
("CCCFBA85D03Z118W", "Jugoslavia"),
9+
("CCCFBA85D03Z135S", "Unione Repubbliche Socialiste Sovietiche"),
10+
("CCCFBA05D03Z157G", "Serbia e Montenegro"),
11+
("CCCFBA75D03Z201F", "Federazione dell'Arabia Meridionale"),
12+
("CCCFBA75D03Z202K", "Protettorato dell'Arabia Meridionale"),
13+
("CCCFBA85D03Z250N", "Yemen del Sud"),
14+
]
15+
16+
17+
@pytest.mark.parametrize("code, expected_country", test_data)
18+
def test_issue_0036(code, expected_country):
19+
"""
20+
Test for decoding fiscal codes with historical country names.
21+
"""
22+
data = codicefiscale.decode(code)
23+
assert data["birthplace"]["name"] == expected_country

tests/issues/test_issue_0037.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from codicefiscale import codicefiscale
2+
3+
4+
def test_issue_0037():
5+
"""
6+
Test for encoding a Codice Fiscale for a person born in Vignola (MO).
7+
Ensures the correct birthplace code (L885) is used instead of L884.
8+
"""
9+
data = {
10+
"lastname": "Caccamo",
11+
"firstname": "Fabio",
12+
"gender": "M",
13+
"birthdate": "03/04/1885",
14+
"birthplace": "Vignola",
15+
}
16+
code = codicefiscale.encode(**data)
17+
decoded_data = codicefiscale.decode(code)
18+
birthplace = decoded_data["birthplace"]
19+
assert birthplace is not None
20+
assert isinstance(birthplace, dict)
21+
assert birthplace["code"] == "L885"
22+
assert birthplace["name"] == "Vignola"
23+
assert birthplace["province"] == "MO"

tests/issues/test_issue_0079.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import datetime
2+
3+
from codicefiscale import codicefiscale
4+
5+
6+
def test_issue_0079():
7+
"""
8+
Test for encoding and decoding fiscal codes
9+
when year of birth (excluding century) < 10 (e.g., 2004).
10+
"""
11+
code = codicefiscale.encode(
12+
lastname="Rossi",
13+
firstname="Mario",
14+
gender="M",
15+
birthdate="29/11/2004",
16+
birthplace="Torino",
17+
)
18+
assert code == "RSSMRA04S29L219G"
19+
code_data = codicefiscale.decode("RSSMRA00S29L219C")
20+
code_data.pop("omocodes")
21+
expected_code_data = {
22+
"code": "RSSMRA00S29L219C",
23+
"gender": "M",
24+
"birthdate": datetime.datetime(2000, 11, 29, 0, 0),
25+
"birthplace": {
26+
"active": True,
27+
"code": "L219",
28+
"date_created": "1889-08-12T00:00:00",
29+
"date_deleted": "",
30+
"name": "Torino",
31+
"name_alt": "",
32+
"name_alt_trans": "",
33+
"name_slugs": ["torino"],
34+
"name_trans": "Torino",
35+
"province": "TO",
36+
},
37+
"raw": {
38+
"code": "RSSMRA00S29L219C",
39+
"lastname": "RSS",
40+
"firstname": "MRA",
41+
"birthdate": "00S29",
42+
"birthdate_year": "00",
43+
"birthdate_month": "S",
44+
"birthdate_day": "29",
45+
"birthplace": "L219",
46+
"cin": "C",
47+
},
48+
}
49+
assert code_data == expected_code_data

tests/issues/test_issue_0113.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import datetime
2+
3+
import pytest
4+
5+
from codicefiscale import codicefiscale
6+
7+
test_data = [
8+
("XXXXXX39D44G133O", datetime.datetime(1939, 4, 4, 0, 0)),
9+
("XXXXXX46D11F383M", datetime.datetime(1946, 4, 11, 0, 0)),
10+
("XXXXXX50H18F383N", datetime.datetime(1950, 6, 18, 0, 0)),
11+
("XXXXXX38C71L513V", datetime.datetime(1938, 3, 31, 0, 0)),
12+
("XXXXXX43C14G133F", datetime.datetime(1943, 3, 14, 0, 0)),
13+
]
14+
15+
16+
@pytest.mark.parametrize("code, expected_birthdate", test_data)
17+
def test_issue_0113(code, expected_birthdate):
18+
"""
19+
Test for wrong birthplace code error (missing date-range in the data-source).
20+
"""
21+
code_data = codicefiscale.decode(code)
22+
code_data.pop("omocodes")
23+
code_data.pop("raw")
24+
assert code_data["birthdate"] == expected_birthdate

tests/issues/test_issue_0162.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import datetime
2+
3+
from codicefiscale import codicefiscale
4+
5+
6+
def test_issue_0162():
7+
"""
8+
Test for wrong birthplace code error (missing date-range in the data-source).
9+
"""
10+
code = "DFLNTN42T20B860H"
11+
assert codicefiscale.is_valid(code)
12+
code_data = codicefiscale.decode(code)
13+
code_data.pop("omocodes")
14+
expected_code_data = {
15+
"code": "DFLNTN42T20B860H",
16+
"gender": "M",
17+
"birthdate": datetime.datetime(1942, 12, 20, 0, 0),
18+
"birthplace": {
19+
"active": False,
20+
"code": "B860",
21+
"date_created": "1927-01-12T00:00:00",
22+
"date_deleted": "1928-06-27T00:00:00",
23+
"name": "Casagiove",
24+
"name_alt": "",
25+
"name_alt_trans": "",
26+
"name_slugs": ["casagiove"],
27+
"name_trans": "Casagiove",
28+
"province": "NA",
29+
},
30+
"raw": {
31+
"code": "DFLNTN42T20B860H",
32+
"lastname": "DFL",
33+
"firstname": "NTN",
34+
"birthdate": "42T20",
35+
"birthdate_year": "42",
36+
"birthdate_month": "T",
37+
"birthdate_day": "20",
38+
"birthplace": "B860",
39+
"cin": "H",
40+
},
41+
}
42+
assert code_data == expected_code_data

tests/test_checks.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
3+
from codicefiscale import codicefiscale
4+
5+
6+
@pytest.fixture
7+
def omocode_test_cases():
8+
return [
9+
("CCCFBA85D03L219P", False),
10+
("CCCFBA85D03L21VE", True),
11+
("CCCFBA85D03L2MVP", True),
12+
("CCCFBA85D03LNMVE", True),
13+
("CCCFBA85D0PLNMVA", True),
14+
("CCCFBA85DLPLNMVL", True),
15+
("CCCFBA8RDLPLNMVX", True),
16+
("CCCFBAURDLPLNMVU", True),
17+
]
18+
19+
20+
@pytest.fixture
21+
def valid_fiscal_code_test_cases():
22+
return [
23+
("CCCFBA85D03L219P", True),
24+
("CCC FBA 85 D03 L219 P", True),
25+
("CCC-FBA-85-D03-L219-P", True),
26+
("CCCFBA85D03L219PP", False), # too long
27+
("CCCFBA85D03L219B", False), # wrong CIN
28+
("CCCFBA85D03L219", False), # too short
29+
("CCCFBA85D00L219", False), # wrong birthdate day
30+
("CCCFBA85D99L219", False), # wrong birthdate day
31+
]
32+
33+
34+
def test_is_omocode(omocode_test_cases):
35+
"""
36+
Test the `is_omocode` function to verify if a fiscal code is an omocode.
37+
"""
38+
for fiscal_code, expected_result in omocode_test_cases:
39+
assert codicefiscale.is_omocode(fiscal_code) == expected_result
40+
41+
42+
def test_is_valid(valid_fiscal_code_test_cases):
43+
"""
44+
Test the `is_valid` function to verify if a fiscal code is valid.
45+
"""
46+
for fiscal_code, expected_result in valid_fiscal_code_test_cases:
47+
assert codicefiscale.is_valid(fiscal_code) == expected_result

0 commit comments

Comments
 (0)