From 17c7fb7c8689ae036bd6a20fc18a376678084048 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 15 Mar 2024 19:19:30 -0400 Subject: [PATCH 1/4] RF: minor simplification of Python code If the point is to go through values, just go through .values() without iterating through keys() and then dereferencing via [key] --- tools/schemacode/bidsschematools/data/tests/test_rules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/schemacode/bidsschematools/data/tests/test_rules.py b/tools/schemacode/bidsschematools/data/tests/test_rules.py index e8da90ee93..3cceeb750a 100644 --- a/tools/schemacode/bidsschematools/data/tests/test_rules.py +++ b/tools/schemacode/bidsschematools/data/tests/test_rules.py @@ -83,8 +83,8 @@ def test_rule_objects(schema_obj): if object_type in ["extensions", "suffixes"]: # Some object types are referenced via their "value" fields in the rules object_values = [ - schema_obj["objects"][object_type][k]["value"] - for k in schema_obj["objects"][object_type].keys() + value["value"] + for value in schema_obj["objects"][object_type].values() ] else: # But other object types are referenced via their keys From e1952c4e8e9c21f81724027268fa228649e8c14a Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 15 Mar 2024 19:23:39 -0400 Subject: [PATCH 2/4] Raise AssertionError in the test, not ValueError Since then also it is not clear if that is indeed some ValueError from within code. I also added a string which summarizes the problem. --- tools/schemacode/bidsschematools/data/tests/test_rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/schemacode/bidsschematools/data/tests/test_rules.py b/tools/schemacode/bidsschematools/data/tests/test_rules.py index 3cceeb750a..8309a56469 100644 --- a/tools/schemacode/bidsschematools/data/tests/test_rules.py +++ b/tools/schemacode/bidsschematools/data/tests/test_rules.py @@ -100,7 +100,7 @@ def test_rule_objects(schema_obj): if not_found: not_found_string = "\n".join([f"{'.'.join(path)} == {val}" for path, val in not_found]) - raise ValueError(not_found_string) + raise AssertionError(f"Undefined objects found in rules: {not_found_string}" @pytest.mark.validate_schema From d6408f9111f168c8cae26598d4b089520926239e Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Fri, 15 Mar 2024 19:33:06 -0400 Subject: [PATCH 3/4] Update tools/schemacode/bidsschematools/data/tests/test_rules.py --- tools/schemacode/bidsschematools/data/tests/test_rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/schemacode/bidsschematools/data/tests/test_rules.py b/tools/schemacode/bidsschematools/data/tests/test_rules.py index 8309a56469..b642650c4b 100644 --- a/tools/schemacode/bidsschematools/data/tests/test_rules.py +++ b/tools/schemacode/bidsschematools/data/tests/test_rules.py @@ -100,7 +100,7 @@ def test_rule_objects(schema_obj): if not_found: not_found_string = "\n".join([f"{'.'.join(path)} == {val}" for path, val in not_found]) - raise AssertionError(f"Undefined objects found in rules: {not_found_string}" + raise AssertionError(f"Undefined objects found in rules: {not_found_string}") @pytest.mark.validate_schema From 12dcfb2e8d96da917d190f865c66e9de03639819 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:33:26 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tools/schemacode/bidsschematools/data/tests/test_rules.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/schemacode/bidsschematools/data/tests/test_rules.py b/tools/schemacode/bidsschematools/data/tests/test_rules.py index b642650c4b..3eb11a6ed0 100644 --- a/tools/schemacode/bidsschematools/data/tests/test_rules.py +++ b/tools/schemacode/bidsschematools/data/tests/test_rules.py @@ -83,8 +83,7 @@ def test_rule_objects(schema_obj): if object_type in ["extensions", "suffixes"]: # Some object types are referenced via their "value" fields in the rules object_values = [ - value["value"] - for value in schema_obj["objects"][object_type].values() + value["value"] for value in schema_obj["objects"][object_type].values() ] else: # But other object types are referenced via their keys