From fb669dcf02d53dc3e0f3050a1f86d8e008d0edb9 Mon Sep 17 00:00:00 2001 From: Alexandre van Beurden Date: Sat, 10 Aug 2024 21:59:12 +0200 Subject: [PATCH] Fix details deserialization error --- pyproject.toml | 2 +- regexsolver/__init__.py | 2 +- regexsolver/details.py | 2 +- setup.py | 2 +- tests/assets/response_getDetails_infinite.json | 12 ++++++++++++ tests/term_operation_test.py | 17 +++++++++++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tests/assets/response_getDetails_infinite.json diff --git a/pyproject.toml b/pyproject.toml index a6a3ca5..828398f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "regexsolver" -version = "1.0.1" +version = "1.0.2" authors = [ { name = "RegexSolver", email = "contact@regexsolver.com" } ] diff --git a/regexsolver/__init__.py b/regexsolver/__init__.py index a8ab6c2..3ea8239 100644 --- a/regexsolver/__init__.py +++ b/regexsolver/__init__.py @@ -28,7 +28,7 @@ def __init__(self): self.base_url = "https://api.regexsolver.com/" self.api_token = None self.headers = { - 'User-Agent': 'RegexSolver Python / 1.0.1', + 'User-Agent': 'RegexSolver Python / 1.0.2', 'Content-Type': 'application/json' } diff --git a/regexsolver/details.py b/regexsolver/details.py index a5b26ae..e9d9c3d 100644 --- a/regexsolver/details.py +++ b/regexsolver/details.py @@ -8,7 +8,7 @@ class Cardinality(BaseModel): Class that represent the number of possible values. """ type: str - value: Optional[int] + value: Optional[int] = None def is_infinite(self) -> bool: """ diff --git a/setup.py b/setup.py index bfbbd41..17a5235 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="regexsolver", - version="1.0.1", + version="1.0.2", description="RegexSolver allows you to manipulate regular expressions as sets, enabling operations such as intersection, union, and subtraction.", long_description=open('README.md').read(), long_description_content_type='text/markdown', diff --git a/tests/assets/response_getDetails_infinite.json b/tests/assets/response_getDetails_infinite.json new file mode 100644 index 0000000..190e173 --- /dev/null +++ b/tests/assets/response_getDetails_infinite.json @@ -0,0 +1,12 @@ +{ + "type": "details", + "cardinality": { + "type": "Infinite" + }, + "length": [ + 2, + null + ], + "empty": false, + "total": false +} \ No newline at end of file diff --git a/tests/term_operation_test.py b/tests/term_operation_test.py index 31e066b..1790597 100644 --- a/tests/term_operation_test.py +++ b/tests/term_operation_test.py @@ -26,6 +26,23 @@ def test_get_details(self): str(details) ) + def test_get_details_infinite(self): + with open('tests/assets/response_getDetails_infinite.json') as response: + json_response = json.load(response) + with requests_mock.Mocker() as mock: + mock.post( + "https://api.regexsolver.com/api/analyze/details", + json=json_response, status_code=200 + ) + + term = Term.regex(r"de.*") + details = term.get_details() + + self.assertEqual( + "Details[cardinality=Infinite, length=Length[minimum=2, maximum=None], empty=False, total=False]", + str(details) + ) + def test_generate_strings(self): with open('tests/assets/response_generateStrings.json') as response: json_response = json.load(response)