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

Feature/camelcase fields #32

Merged
merged 13 commits into from
Sep 5, 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).



### Fixes

* *Simple condition:* an error occurs when the field is of type camelcase or pascalcase (e.g., `input.streetNumber`, `input.StreetNumber`).


## [0.8.0] - July, 2024

### Features
Expand Down
3 changes: 3 additions & 0 deletions docs/pages/a_simple_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ rules:
mail_to: [email protected]
mail_content: "Thanks for preparing once a month the following dish:"
meal: input.favorite_meal



actions_source_modules:
- my_folder.actions
Expand Down Expand Up @@ -178,6 +180,7 @@ applicants = [
"favorite_meal": None,
"secret_weakness": "Feel alone",
"weapons": ["Hands", "Batarang"],

},
{
"id": 3,
Expand Down
2 changes: 1 addition & 1 deletion src/arta/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def verify(self, input_data: dict[str, Any], parsing_error_strategy: ParsingErro
bool_var: bool = False
unitary_expr: str = self._condition_id

data_path_patt: str = r"(?:input\.|output\.)(?:[a-z_\.]*)"
data_path_patt: str = r"(?:input\.|output\.)(?:[a-zA-Z_\.]*)"

# Retrieve only the data path
path_matches: list[str] = re.findall(data_path_patt, unitary_expr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ rules:
action_parameters:
value: false


parsing_error_strategy: raise
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ rules:
action_parameters:
list_str:
- OK
camelCase :
RULE_1:
simple_condition: input.streetNumber>0 and input.streetName!="" and input.postalCode >0
action: concatenate_str
action_parameters:
list_str:
- OK
47 changes: 21 additions & 26 deletions tests/unit/test_simple_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
},
"simple_cond_conf/default",
None,
{"admission": {"admission": True}, "course": {"course_id": "senior"}, "email": True},
{
"admission": {"admission": True},
"course": {"course_id": "senior"},
"email": True,
},
),
(
{
Expand All @@ -30,7 +34,11 @@
},
"simple_cond_conf/default",
None,
{"admission": {"admission": True}, "course": {"course_id": "english"}, "email": None},
{
"admission": {"admission": True},
"course": {"course_id": "english"},
"email": None,
},
),
(
{
Expand All @@ -41,26 +49,20 @@
},
"simple_cond_conf/default",
None,
{"admission": {"admission": False}, "course": {"course_id": "senior"}, "email": None},
),
(
{
"dummy": 100,
"language": "french",
"power": "strength",
"favorite_meal": "Spinach",
"admission": {"admission": False},
"course": {"course_id": "senior"},
"email": None,
},
),
(
{"dummy": 100, "language": "french", "power": "strength", "favorite_meal": "Spinach"},
"simple_cond_conf/ignore",
None,
{"admission": {"admission": True}, "course": {"course_id": "senior"}, "email": True},
),
(
{
"age": 100,
"language": "french",
"power": "strength",
"favorite_meal": "Spinach",
},
{"age": 100, "language": "french", "power": "strength", "favorite_meal": "Spinach"},
"simple_cond_conf/wrong/ignore",
None,
{"admission": {"admission": True}, "course": {"course_id": "senior"}, "email": True},
Expand All @@ -74,20 +76,16 @@
{"whitespace": "OK"},
),
(
{
"text": "SUPER HERO",
},
{"text": "SUPER HERO", "streetNumber": 15, "streetName": "rue des Es", "postalCode": 89000},
"simple_cond_conf/uppercase",
None,
{"uppercase": "OK"},
{"uppercase": "OK", "camelCase": "OK"},
),
(
{
"text": "SUPER HERO",
},
{"text": "SUPER HERO", "streetNumber": 0, "streetName": "", "postalCode": 0},
"simple_cond_conf/uppercase",
set(),
{"uppercase": "OK"},
{"uppercase": "OK", "camelCase": None},
),
(
{"age": 100, "power": "strength"},
Expand All @@ -102,7 +100,6 @@ def test_simple_condition(input_data, config_dir, ignored_rules, good_results, b
config_path = os.path.join(base_config_path, config_dir)
eng = RulesEngine(config_path=config_path)
res = eng.apply_rules(input_data=input_data, ignored_rules=ignored_rules)

assert res == good_results


Expand Down Expand Up @@ -180,7 +177,6 @@ def test_simple_condition_verbose(input_data, good_results, base_config_path):
config_path = os.path.join(base_config_path, "simple_cond_conf/default")
eng = RulesEngine(config_path=config_path)
res = eng.apply_rules(input_data=input_data, verbose=True)

assert res == good_results


Expand Down Expand Up @@ -265,5 +261,4 @@ def test_math(input_data, config_dir, good_results, base_config_path):
config_path = os.path.join(base_config_path, config_dir)
eng = RulesEngine(config_path=config_path)
res = eng.apply_rules(input_data=input_data)

assert res == good_results