Skip to content

Commit

Permalink
refactor: Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarrabah committed Oct 15, 2024
1 parent c85c073 commit d3c5d61
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
12 changes: 5 additions & 7 deletions src/frformat/geo/code_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
CODE_REGION_SET_COG_2024 = CODE_REGION_SET_COG_2023

name = "Code région"
description = (
"Vérifie qu'il s'agit d'un code région selon le code officiel géographique donné"
)
all_cog_version: Dict[Millesime, Set[str]] = {
Millesime.Y2023: CODE_REGION_SET_COG_2023,
Millesime.Y2024: CODE_REGION_SET_COG_2024,
description = "Vérifie qu'il s'agit d'un code région selon le code officiel géographique (cog) donné"
all_cog_versions: Dict[Millesime, Set[str]] = {
Millesime.A2023: CODE_REGION_SET_COG_2023,
Millesime.A2024: CODE_REGION_SET_COG_2024,
}
CodeRegion = geo_enum_format.new("CodeRegion", name, description, all_cog_version)
CodeRegion = geo_enum_format.new("CodeRegion", name, description, all_cog_versions)
4 changes: 2 additions & 2 deletions src/frformat/geo/commune.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

all_cog_version: Dict[Millesime, Set[str]] = {
Millesime.Y2023: COMMUNE_SET_COG_2023,
Millesime.Y2024: COMMUNE_SET_COG_2024,
Millesime.A2023: COMMUNE_SET_COG_2023,
Millesime.A2024: COMMUNE_SET_COG_2024,
}
Commune = geo_enum_format.new("Commune", name, description, all_cog_version)
4 changes: 2 additions & 2 deletions src/frformat/geo/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
description = "Vérifie les régions françaises valides"

all_cog_version: Dict[Millesime, Set[str]] = {
Millesime.Y2023: REGION_SET_COG_2023,
Millesime.Y2024: REGION_SET_COG_2024,
Millesime.A2023: REGION_SET_COG_2023,
Millesime.A2024: REGION_SET_COG_2024,
}
Region = geo_enum_format.new("Region", name, description, all_cog_version)
24 changes: 13 additions & 11 deletions src/frformat/geo_enum_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class Millesime(Enum):
Y2023 = auto()
Y2024 = auto()
A2023 = auto()
A2024 = auto()


def new(
Expand All @@ -17,10 +17,10 @@ def new(
description: str,
geographical_enums: Dict[Millesime, Set[str]],
) -> Type:
class EnumFormat(CustomStrFormat):
"""Checks if a value is in a given list
class GeoEnumFormat(CustomStrFormat):
"""Checks if a value is in a given geographical referential, with validation for the vintage of choice
May preprocess the input and valid values according to given "options" and the "Official Geographic Code"
Geographical data in France is revised once a year, with new valid values set given by the "Code Officiel Géographique" (cog).
"""

def __init__(self, cog: Millesime, options: Options = Options()):
Expand All @@ -32,12 +32,14 @@ def __init__(self, cog: Millesime, options: Options = Options()):
}

if cog not in geographical_enums.keys():
raise ValueError(f"Invalid given cog: {cog.name}")
raise ValueError(
f"No data available for official geographical code (cog): {cog.name}"
)

_code_set = geographical_enums[cog]
_valid_values = geographical_enums[cog]

self._normalized_geo_enum_value = {
normalize_value(code, self._options) for code in _code_set
normalize_value(val, self._options) for val in _valid_values
}.union(_normalized_extra_values)

metadata = Metadata(name, description)
Expand All @@ -46,7 +48,7 @@ def is_valid(self, value: str) -> bool:
normalized_value = normalize_value(value, self._options)
return normalized_value in self._normalized_geo_enum_value

EnumFormat.__name__ = class_name
EnumFormat.__qualname__ = class_name
GeoEnumFormat.__name__ = class_name
GeoEnumFormat.__qualname__ = class_name

return EnumFormat
return GeoEnumFormat
2 changes: 1 addition & 1 deletion src/tests/new_testing.py → src/tests/geo_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_helper(
replace_non_alphanumeric_with_space=True,
ignore_extra_whitespace=True,
)
all_cogs = [Millesime.Y2023, Millesime.Y2024]
all_cogs = [Millesime.A2023, Millesime.A2024]

for cog in all_cogs:
_test_class(strict_test_cases, expectValid=True, cog=cog, options=Options())
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_new_geo_fr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from frformat import CodeRegion, Commune, Region
from frformat.geo_enum_format import Millesime
from tests.new_testing import strict_lenient_test_helper_factory
from tests.geo_testing import strict_lenient_test_helper_factory


def test_code_region():
Expand All @@ -24,8 +24,8 @@ def test_region():


def test_commune():
commune_2023 = Commune(Millesime.Y2023)
commune_2024 = Commune(Millesime.Y2024)
commune_2023 = Commune(Millesime.A2023)
commune_2024 = Commune(Millesime.A2024)

valid_test_cases_cog_2023 = [
"Bellac",
Expand Down

0 comments on commit d3c5d61

Please sign in to comment.