Skip to content

Commit 7946159

Browse files
authored
Merge branch 'main' into dependabot/pip/mypy-eq-1.5.star
2 parents dcf93fb + 0304b3c commit 7946159

File tree

8 files changed

+150
-11
lines changed

8 files changed

+150
-11
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
repos:
44

55
- repo: https://github.com/asottile/pyupgrade
6-
rev: v3.9.0
6+
rev: v3.10.1
77
hooks:
88
- id: pyupgrade
99
args: ["--py38-plus"]
@@ -14,7 +14,7 @@ repos:
1414
- id: fix-future-annotations
1515

1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.0.278
17+
rev: v0.0.287
1818
hooks:
1919
- id: ruff
2020
args: [--fix, --exit-non-zero-on-fix]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![](https://img.shields.io/pypi/pyversions/python-codicefiscale.svg?logoColor=white&color=blue&logo=python)](https://www.python.org/)
22
[![](https://img.shields.io/pypi/v/python-codicefiscale.svg?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/python-codicefiscale/)
3-
[![](https://pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale)
3+
[![](https://static.pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale)
44
[![](https://img.shields.io/github/stars/fabiocaccamo/python-codicefiscale?logo=github)](https://github.com/fabiocaccamo/python-codicefiscale/stargazers)
55
[![](https://img.shields.io/pypi/l/python-codicefiscale.svg?color=blue&)](https://github.com/fabiocaccamo/python-codicefiscale/blob/main/LICENSE)
66

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"active": false,
4+
"code": "F383",
5+
"date_created": "1928-05-12T00:00:00",
6+
"date_deleted": "1991-12-09T00:00:00",
7+
"name": "Monserrato",
8+
"name_alt": "",
9+
"name_alt_trans": "",
10+
"name_slugs": [
11+
"monserrato"
12+
],
13+
"name_trans": "Monserrato",
14+
"province": "CA"
15+
},
16+
{
17+
"active": false,
18+
"code": "G133",
19+
"date_created": "1928-11-28T00:00:00",
20+
"date_deleted": "1948-04-07T00:00:00",
21+
"name": "Ortacesus",
22+
"name_alt": "",
23+
"name_alt_trans": "",
24+
"name_slugs": [
25+
"ortacesus"
26+
],
27+
"name_trans": "Ortacesus",
28+
"province": "CA"
29+
},
30+
{
31+
"active": false,
32+
"code": "L513",
33+
"date_created": "1927-11-04T00:00:00",
34+
"date_deleted": "1946-02-27T00:00:00",
35+
"name": "Ussaramanna",
36+
"name_alt": "",
37+
"name_alt_trans": "",
38+
"name_slugs": [
39+
"ussaramanna"
40+
],
41+
"name_trans": "Ussaramanna",
42+
"province": "CA"
43+
}
44+
]

codicefiscale/data/municipalities.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139084,6 +139084,20 @@
139084139084
"name_trans": "Monserrato",
139085139085
"province": "CA"
139086139086
},
139087+
{
139088+
"active": false,
139089+
"code": "F383",
139090+
"date_created": "1928-05-12T00:00:00",
139091+
"date_deleted": "1991-12-09T00:00:00",
139092+
"name": "Monserrato",
139093+
"name_alt": "",
139094+
"name_alt_trans": "",
139095+
"name_slugs": [
139096+
"monserrato"
139097+
],
139098+
"name_trans": "Monserrato",
139099+
"province": "CA"
139100+
},
139087139101
{
139088139102
"active": false,
139089139103
"code": "F384",
@@ -158555,6 +158569,20 @@
158555158569
"name_trans": "Ortacesus",
158556158570
"province": "SU"
158557158571
},
158572+
{
158573+
"active": false,
158574+
"code": "G133",
158575+
"date_created": "1928-11-28T00:00:00",
158576+
"date_deleted": "1948-04-07T00:00:00",
158577+
"name": "Ortacesus",
158578+
"name_alt": "",
158579+
"name_alt_trans": "",
158580+
"name_slugs": [
158581+
"ortacesus"
158582+
],
158583+
"name_trans": "Ortacesus",
158584+
"province": "CA"
158585+
},
158558158586
{
158559158587
"active": false,
158560158588
"code": "G135",
@@ -251715,6 +251743,20 @@
251715251743
"name_trans": "Ussaramanna",
251716251744
"province": "SU"
251717251745
},
251746+
{
251747+
"active": false,
251748+
"code": "L513",
251749+
"date_created": "1927-11-04T00:00:00",
251750+
"date_deleted": "1946-02-27T00:00:00",
251751+
"name": "Ussaramanna",
251752+
"name_alt": "",
251753+
"name_alt_trans": "",
251754+
"name_slugs": [
251755+
"ussaramanna"
251756+
],
251757+
"name_trans": "Ussaramanna",
251758+
"province": "CA"
251759+
},
251718251760
{
251719251761
"active": false,
251720251762
"code": "L514",

requirements-test.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
coverage == 7.2.*
1+
coverage == 7.3.*
22
mypy == 1.5.*
33
pre-commit == 3.3.*
4-
tox == 4.6.*
4+
tox == 4.11.*

scripts/updatedata.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from benedict import benedict
33
from slugify import slugify
44

5+
DATA_DIR = fsutil.join_path(__file__, "../codicefiscale/data/")
6+
57

68
def _expect_keys(d, keys):
79
missing_keys = list(set(keys) - set(d.keys()))
@@ -71,9 +73,12 @@ def map_item(item):
7173
"province": province,
7274
}
7375

76+
items_data = [map_item(benedict(item)) for item in data["values"]]
77+
items_data_patch = _read_data_json("countries-patch.json")
78+
7479
_write_data_json(
75-
filepath="../codicefiscale/data/countries.json",
76-
data=[map_item(benedict(item)) for item in data["values"]],
80+
filepath="countries.json",
81+
data=items_data + items_data_patch,
7782
)
7883

7984

@@ -142,17 +147,31 @@ def map_item(item):
142147
"province": province,
143148
}
144149

150+
items_data = [map_item(benedict(item)) for item in data["values"]]
151+
items_data_patch = _read_data_json("municipalities-patch.json")
152+
145153
_write_data_json(
146-
filepath="../codicefiscale/data/municipalities.json",
147-
data=[map_item(benedict(item)) for item in data["values"]],
154+
filepath="municipalities.json",
155+
data=items_data + items_data_patch,
148156
)
149157

150158

159+
def _read_data_json(filepath):
160+
data = fsutil.read_file_json(
161+
fsutil.join_filepath(DATA_DIR, filepath),
162+
)
163+
return data
164+
165+
151166
def _write_data_json(filepath, data):
152167
data = list(filter(bool, data))
153168
data = sorted(data, key=lambda item: item["name"])
154-
data_filepath = fsutil.join_path(__file__, filepath)
155-
fsutil.write_file_json(data_filepath, data, indent=4, sort_keys=True)
169+
fsutil.write_file_json(
170+
fsutil.join_filepath(DATA_DIR, filepath),
171+
data,
172+
indent=4,
173+
sort_keys=True,
174+
)
156175

157176

158177
def main():

tests/test_issue_0113.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import datetime
2+
import unittest
3+
4+
from codicefiscale import codicefiscale
5+
6+
7+
class Issue0113TestCase(unittest.TestCase):
8+
def test_issue_0113(self):
9+
"""
10+
Wrong birthplace code error (missing date-range in the data-source).
11+
"""
12+
codes = [
13+
"XXXXXX39D44G133O",
14+
"XXXXXX46D11F383M",
15+
"XXXXXX50H18F383N",
16+
"XXXXXX38C71L513V",
17+
"XXXXXX43C14G133F",
18+
]
19+
expected_birthdates = [
20+
datetime.datetime(1939, 4, 4, 0, 0),
21+
datetime.datetime(1946, 4, 11, 0, 0),
22+
datetime.datetime(1950, 6, 18, 0, 0),
23+
datetime.datetime(1938, 3, 31, 0, 0),
24+
datetime.datetime(1943, 3, 14, 0, 0),
25+
]
26+
for index, code in enumerate(codes):
27+
with self.subTest(f"code: {code}"):
28+
code_data = codicefiscale.decode(code)
29+
code_data.pop("omocodes")
30+
code_data.pop("raw")
31+
# print(code_data)
32+
self.assertEqual(code_data["birthdate"], expected_birthdates[index])

0 commit comments

Comments
 (0)