Skip to content
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

Refactor: Set a default value to options parameter #16

Merged
merged 6 commits into from
Jul 31, 2024
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
2 changes: 1 addition & 1 deletion src/frformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .geo.pays import Pays as Pays
from .geo.region import Region as Region
from .nomenclature_acte_format import NomenclatureActe as NomenclatureActe
from .options import Options
from .options import Options as Options
from .siren import Siren as Siren
from .siret import Siret as Siret

Expand Down
4 changes: 3 additions & 1 deletion src/frformat/enum_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class EnumFormat(CustomStrFormat):

May preprocess the input and valid values according to given "options"."""

def __init__(self, options: Options):
def __init__(self, options: Options = Options()):
self._options = options

_normalized_extra_values = {
normalize_value(e, self._options)
for e in self._options.extra_valid_values
}

self._normalized_enum = {
normalize_value(e, self._options) for e in enum
}.union(_normalized_extra_values)
Expand Down
5 changes: 2 additions & 3 deletions src/tests/test_geo_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Region,
)
from frformat.common import NBSP, NNBSP
from frformat.options import Options
from tests.testing import strict_lenient_test_helper_factory


Expand All @@ -29,7 +28,7 @@ def test_code_fantoir():

def test_code_commune_insee():
value = "01015"
code_commune_insee = CodeCommuneInsee(Options())
code_commune_insee = CodeCommuneInsee()
assert code_commune_insee.is_valid(value)
assert code_commune_insee.format(value) == value

Expand All @@ -39,7 +38,7 @@ def test_code_commune_insee():

def test_code_postal():
value = "05560"
code_postal = CodePostal(Options())
code_postal = CodePostal()
assert code_postal.is_valid(value)
assert code_postal.format(value) == value

Expand Down