From 9ed04a6a9a5fc4a04c28c7eebf0f850c1064c848 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 20 Mar 2024 14:25:25 -0400 Subject: [PATCH] [SCHEMA] Very minor tune ups to the test_rule_objects test while trying to grasp its function (#1728) * 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] * 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. * Update tools/schemacode/bidsschematools/data/tests/test_rules.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Chris Markiewicz Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tools/schemacode/bidsschematools/data/tests/test_rules.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/schemacode/bidsschematools/data/tests/test_rules.py b/tools/schemacode/bidsschematools/data/tests/test_rules.py index e8da90ee93..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 = [ - 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 @@ -100,7 +99,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