-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Get all valid values set (#42)
# Goal As outlined in issue #26, the purpose of this PR is to introduce a new feature to the `fr-format` project: Retrieving all valid values set associated to a specific French format. This feature is only possible for Set formats, which is defined a set of all valid values. Fixes #26 --------- Co-authored-by: Pierre Camilleri <[email protected]>
- Loading branch information
1 parent
3da1419
commit 8548fc2
Showing
4 changed files
with
109 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import pytest | ||
|
||
from frformat import set_format | ||
from frformat.set_format import Millesime, new | ||
from frformat.versioned_set import VersionedSet | ||
|
||
|
||
def test_format_validation(): | ||
versioned_data = VersionedSet[Millesime]() | ||
versioned_data.add_version( | ||
Millesime.M2023, | ||
frozenset({"Ambléon", "Ambronay"}), | ||
) | ||
|
||
versioned_data.add_version(Millesime.M2024, frozenset({"Arandas"})) | ||
|
||
FormatTest = new( | ||
"Versionned format", "Versionned format", "Versionned format", versioned_data | ||
) | ||
|
||
test_cases = [ | ||
{ | ||
"version": Millesime.M2023, | ||
"value_to_test": "Ambléon", | ||
"expected_valid": True, | ||
}, | ||
{ | ||
"version": Millesime.M2023, | ||
"value_to_test": "Anglefort", | ||
"expected_valid": False, | ||
}, | ||
{ | ||
"version": Millesime.M2024, | ||
"value_to_test": "Arandas", | ||
"expected_valid": True, | ||
}, | ||
{ | ||
"version": Millesime.LATEST, | ||
"value_to_test": "Arandas", | ||
"expected_valid": True, | ||
}, | ||
{ | ||
"version": Millesime.LATEST, | ||
"value_to_test": "Ambléon", | ||
"expected_valid": False, | ||
}, | ||
{"version": "2025", "expected_error": ValueError}, | ||
] | ||
|
||
for tc in test_cases: | ||
if "expected_error" in tc: | ||
with pytest.raises(tc["expected_error"]): | ||
FormatTest(tc["version"]) | ||
else: | ||
test_format = FormatTest(tc["version"]) | ||
assert ( | ||
test_format.is_valid(tc["value_to_test"]) == tc["expected_valid"] | ||
), f'Error on data format definition with version { tc["version"] } and value { tc["value_to_test"] }' | ||
|
||
|
||
def test_formats_valid_values(): | ||
versioned_data = VersionedSet[Millesime]() | ||
versioned_data.add_version(Millesime.M2024, frozenset({"Paris", "Lyon"})) | ||
test_cases = [ | ||
{ | ||
"name": "VersionedSetFormat", | ||
"valid_data": versioned_data, | ||
"version": "2024", | ||
"expected_result": frozenset({"Paris", "Lyon"}), | ||
}, | ||
{ | ||
"name": "SingleSetFormat", | ||
"valid_data": frozenset({"Nomandie", "Nice"}), | ||
"version": None, | ||
"expected_result": frozenset({"Nomandie", "Nice"}), | ||
}, | ||
] | ||
|
||
name = "Validator name" | ||
description = "Validator description" | ||
|
||
for tc in test_cases: | ||
validator = set_format.new("Validator", name, description, tc["valid_data"]) | ||
if tc["version"]: | ||
assert ( | ||
validator(tc["version"]).get_valid_values_set() == tc["expected_result"] | ||
), f"While we test {tc['name']}, the returned data is not equal to {tc['expected_result']} when the valid_data is {tc['valid_data']} and the version is equal to {tc['version']}" | ||
else: | ||
assert ( | ||
validator().get_valid_values_set() == tc["expected_result"] | ||
), f"While we test {tc['name']}, the returned data is not equal to {tc['expected_result']} when the valid_data is {tc['valid_data']} and the version is equal to {tc['version']}" |