Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/mypy-eq-1.5.star
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocaccamo authored Sep 5, 2023
2 parents dcf93fb + 0304b3c commit 7946159
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
repos:

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.10.1
hooks:
- id: pyupgrade
args: ["--py38-plus"]
Expand All @@ -14,7 +14,7 @@ repos:
- id: fix-future-annotations

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
rev: v0.0.287
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![](https://img.shields.io/pypi/pyversions/python-codicefiscale.svg?logoColor=white&color=blue&logo=python)](https://www.python.org/)
[![](https://img.shields.io/pypi/v/python-codicefiscale.svg?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/python-codicefiscale/)
[![](https://pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale)
[![](https://static.pepy.tech/badge/python-codicefiscale/month)](https://pepy.tech/project/python-codicefiscale)
[![](https://img.shields.io/github/stars/fabiocaccamo/python-codicefiscale?logo=github)](https://github.com/fabiocaccamo/python-codicefiscale/stargazers)
[![](https://img.shields.io/pypi/l/python-codicefiscale.svg?color=blue&)](https://github.com/fabiocaccamo/python-codicefiscale/blob/main/LICENSE)

Expand Down
2 changes: 2 additions & 0 deletions codicefiscale/data/countries-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
44 changes: 44 additions & 0 deletions codicefiscale/data/municipalities-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"active": false,
"code": "F383",
"date_created": "1928-05-12T00:00:00",
"date_deleted": "1991-12-09T00:00:00",
"name": "Monserrato",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"monserrato"
],
"name_trans": "Monserrato",
"province": "CA"
},
{
"active": false,
"code": "G133",
"date_created": "1928-11-28T00:00:00",
"date_deleted": "1948-04-07T00:00:00",
"name": "Ortacesus",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"ortacesus"
],
"name_trans": "Ortacesus",
"province": "CA"
},
{
"active": false,
"code": "L513",
"date_created": "1927-11-04T00:00:00",
"date_deleted": "1946-02-27T00:00:00",
"name": "Ussaramanna",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"ussaramanna"
],
"name_trans": "Ussaramanna",
"province": "CA"
}
]
42 changes: 42 additions & 0 deletions codicefiscale/data/municipalities.json
Original file line number Diff line number Diff line change
Expand Up @@ -139084,6 +139084,20 @@
"name_trans": "Monserrato",
"province": "CA"
},
{
"active": false,
"code": "F383",
"date_created": "1928-05-12T00:00:00",
"date_deleted": "1991-12-09T00:00:00",
"name": "Monserrato",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"monserrato"
],
"name_trans": "Monserrato",
"province": "CA"
},
{
"active": false,
"code": "F384",
Expand Down Expand Up @@ -158555,6 +158569,20 @@
"name_trans": "Ortacesus",
"province": "SU"
},
{
"active": false,
"code": "G133",
"date_created": "1928-11-28T00:00:00",
"date_deleted": "1948-04-07T00:00:00",
"name": "Ortacesus",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"ortacesus"
],
"name_trans": "Ortacesus",
"province": "CA"
},
{
"active": false,
"code": "G135",
Expand Down Expand Up @@ -251715,6 +251743,20 @@
"name_trans": "Ussaramanna",
"province": "SU"
},
{
"active": false,
"code": "L513",
"date_created": "1927-11-04T00:00:00",
"date_deleted": "1946-02-27T00:00:00",
"name": "Ussaramanna",
"name_alt": "",
"name_alt_trans": "",
"name_slugs": [
"ussaramanna"
],
"name_trans": "Ussaramanna",
"province": "CA"
},
{
"active": false,
"code": "L514",
Expand Down
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coverage == 7.2.*
coverage == 7.3.*
mypy == 1.5.*
pre-commit == 3.3.*
tox == 4.6.*
tox == 4.11.*
31 changes: 25 additions & 6 deletions scripts/updatedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from benedict import benedict
from slugify import slugify

DATA_DIR = fsutil.join_path(__file__, "../codicefiscale/data/")


def _expect_keys(d, keys):
missing_keys = list(set(keys) - set(d.keys()))
Expand Down Expand Up @@ -71,9 +73,12 @@ def map_item(item):
"province": province,
}

items_data = [map_item(benedict(item)) for item in data["values"]]
items_data_patch = _read_data_json("countries-patch.json")

_write_data_json(
filepath="../codicefiscale/data/countries.json",
data=[map_item(benedict(item)) for item in data["values"]],
filepath="countries.json",
data=items_data + items_data_patch,
)


Expand Down Expand Up @@ -142,17 +147,31 @@ def map_item(item):
"province": province,
}

items_data = [map_item(benedict(item)) for item in data["values"]]
items_data_patch = _read_data_json("municipalities-patch.json")

_write_data_json(
filepath="../codicefiscale/data/municipalities.json",
data=[map_item(benedict(item)) for item in data["values"]],
filepath="municipalities.json",
data=items_data + items_data_patch,
)


def _read_data_json(filepath):
data = fsutil.read_file_json(
fsutil.join_filepath(DATA_DIR, filepath),
)
return data


def _write_data_json(filepath, data):
data = list(filter(bool, data))
data = sorted(data, key=lambda item: item["name"])
data_filepath = fsutil.join_path(__file__, filepath)
fsutil.write_file_json(data_filepath, data, indent=4, sort_keys=True)
fsutil.write_file_json(
fsutil.join_filepath(DATA_DIR, filepath),
data,
indent=4,
sort_keys=True,
)


def main():
Expand Down
32 changes: 32 additions & 0 deletions tests/test_issue_0113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import datetime
import unittest

from codicefiscale import codicefiscale


class Issue0113TestCase(unittest.TestCase):
def test_issue_0113(self):
"""
Wrong birthplace code error (missing date-range in the data-source).
"""
codes = [
"XXXXXX39D44G133O",
"XXXXXX46D11F383M",
"XXXXXX50H18F383N",
"XXXXXX38C71L513V",
"XXXXXX43C14G133F",
]
expected_birthdates = [
datetime.datetime(1939, 4, 4, 0, 0),
datetime.datetime(1946, 4, 11, 0, 0),
datetime.datetime(1950, 6, 18, 0, 0),
datetime.datetime(1938, 3, 31, 0, 0),
datetime.datetime(1943, 3, 14, 0, 0),
]
for index, code in enumerate(codes):
with self.subTest(f"code: {code}"):
code_data = codicefiscale.decode(code)
code_data.pop("omocodes")
code_data.pop("raw")
# print(code_data)
self.assertEqual(code_data["birthdate"], expected_birthdates[index])

0 comments on commit 7946159

Please sign in to comment.