commit 7fdea131bd3a5bfeff0a9bef5c4d34747b3dfc89
parent 300607df051bcb3c90a51892b3524792fca02603
Author: Andrew D. Laack <andrew@laack.co>
Date: Sat, 21 Jun 2025 05:26:46 -0500
Updated test directory structure. (#7)
* Updated tests to specify outputs and toml files to decouple the tests from the repo config
* Made tests self-contained so I can use ratchets with ratchets
* Fixed ratchet issues based on current .toml.
* Fixed OS dependent path issue
* Added a few more regex and shell tests
* Revised no TODO regex
* Added current ratchet_values
* Removed reference to top level db.
* Updated test locations
Diffstat:
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -118,7 +118,7 @@ Once the update command has been executed, the `ratchet_excluded.txt` file is cr
## Running as part of PyTest
-To set up tests, we provide an example file at [examples/example_test_ratchet.py](https://github.com/andrewlaack/ratchets/blob/main/examples/test_ratchet.py), which defines tests to be ran with PyTest. In this file there are two uncommented methods that runs one test per rule in both sections (regex and shell).
+To set up tests, we provide an example file at [test_ratchet.py](https://github.com/andrewlaack/ratchets/blob/main/tests/test_files/test_ratchet.py), which defines tests to be ran with PyTest. In this file there are two uncommented methods that runs one test per rule in both sections (regex and shell).
The commented methods aggregate these tests together into two total tests (regex and shell).
diff --git a/tests/test_files/test_ratchet.py b/tests/test_files/test_ratchet.py
@@ -0,0 +1,51 @@
+import pytest
+from ratchets.abstracted_tests import (
+ get_regex_tests,
+ get_shell_tests,
+ check_regex_rule,
+ check_shell_rule,
+)
+
+
+@pytest.mark.parametrize("test_name,rule", get_regex_tests().items())
+def test_regex_rule(test_name: str, rule: dict) -> None:
+ """Runs a test for a single regex rule."""
+ check_regex_rule(test_name, rule)
+
+
+@pytest.mark.parametrize("test_name,test_dict", get_shell_tests().items())
+def test_shell_rule(test_name: str, test_dict: dict) -> None:
+ """Runs a test for a single shell rule."""
+ check_shell_rule(test_name, test_dict)
+
+
+# def test_all_regex_rules():
+# """Runs a test for all regex rules."""
+# errors = []
+# descriptions = []
+# for test_name, rule in get_regex_tests().items():
+# try:
+# check_regex_rule(test_name, rule)
+# except Exception as e:
+# desc = rule['description']
+# if desc is not None:
+# descriptions.append(test_name + " - " + desc)
+# errors.append(f"{test_name}")
+# if errors:
+# pytest.fail(" - ".join(errors) + "\n\n" + "\n\n".join(descriptions))
+#
+# def test_all_shell_rules():
+# """Runs a test for all shell rules."""
+# errors = []
+# descriptions = []
+# for test_name, test_dict in get_shell_tests().items():
+# try:
+# check_shell_rule(test_name, test_dict)
+# except Exception as e:
+# desc = test_dict['description']
+# if not desc is None:
+# desc = "(" + desc + ")"
+# descriptions.append(test_name + " - " + desc)
+# errors.append(test_name)
+# if errors:
+# pytest.fail(" - ".join(errors) + "\n\n" + "\n\n".join(descriptions))