ratchets

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 484f06d9ad5610096eda916ed1ef086e70e7317e
parent 5d8782dbe6f26e4df51a06918673bcad3d7ec9be
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 18 Jun 2025 16:38:36 -0500

Updated example to fix issue with length

Diffstat:
MREADME.md | 5+++--
Mexamples/example_test_ratchet.py | 49+++++++++++++++++++++++++------------------------
2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/README.md b/README.md @@ -75,7 +75,7 @@ This is an example of an `awk` command being used to print each line that has mo ## Updating Ratchets -Once your rules are defined, you need to count the infractions. This is done by running ```bash python3 -m ratchets -u```. This creates a ratchet_values.json file in the root of your project. This will be checked into git and how the previous number of infractions is tracked to ensure it the never increase. +Once your rules are defined, you need to count the infractions. This is done by running ```python3 -m ratchets -u```. This creates a ratchet_values.json file in the root of your project. This will be checked into git and how the previous number of infractions is tracked to ensure it the never increase. ## Excluding Files @@ -104,7 +104,7 @@ python -m ratchets --help Where you will see the following help message describing CLI usage for ratchets: ``` -usage: __main__.py [-h] [-f FILE] [-c] [-r] [-v] [-b] [-m MAX_COUNT] [--compare-counts] [-u] [--validate] +usage: __main__.py [-h] [-f FILE] [-c] [-r] [-v] [-b] [-m MAX_COUNT] [--compare-counts] [-u] Python ratchet testing @@ -119,6 +119,7 @@ options: maximum infractions to display per test (only applies with --blame; default is 10) --compare-counts show only the differences in infraction counts between the current and last saved tests -u, --update-ratchets + update ratchets_values.json ``` Of these, the -b option is particularly useful. When PyTests fail due to infringement counts increasing, it is necessary to identify where the new infringement occurred. By using the -b option you will, by default, see the 10 most recent changes that caused infringements for each rule. diff --git a/examples/example_test_ratchet.py b/examples/example_test_ratchet.py @@ -1,5 +1,6 @@ import pytest -from ratchets.abstracted_tests import get_python_tests, get_command_tests, check_python_rule, check_command_rule +from ratchets.abstracted_tests import get_python_tests, get_command_tests, \ + check_python_rule, check_command_rule @pytest.mark.parametrize("test_name,rule", get_python_tests().items()) def test_python_regex_rule(test_name: str, rule: dict) -> None: @@ -9,26 +10,26 @@ def test_python_regex_rule(test_name: str, rule: dict) -> None: def test_custom_command_rule(test_name: str, test_dict: dict) -> None: check_command_rule(test_name, test_dict) - # def test_all_python_regex_rules(): - # errors = [] - # for test_name, rule in get_python_tests().items(): - # try: - # check_python_rule(test_name, rule) - # except AssertionError as e: - # errors.append(f"{test_name}: {e}") - # except Exception as e: - # errors.append(f"{test_name}: unexpected error: {e!r}") - # if errors: - # pytest.fail("Some python regex rules failed:\n" + "\n".join(errors)) - # - # def test_all_command_rules(): - # errors = [] - # for test_name, test_dict in get_command_tests().items(): - # try: - # check_command_rule(test_name, test_dict) - # except AssertionError as e: - # errors.append(f"{test_name}: {e}") - # except Exception as e: - # errors.append(f"{test_name}: unexpected error: {e!r}") - # if errors: - # pytest.fail("Some command rules failed:\n" + "\n".join(errors)) +# def test_all_python_regex_rules(): +# errors = [] +# for test_name, rule in get_python_tests().items(): +# try: +# check_python_rule(test_name, rule) +# except AssertionError as e: +# errors.append(f"{test_name}: {e}") +# except Exception as e: +# errors.append(f"{test_name}: unexpected error: {e!r}") +# if errors: +# pytest.fail("Some python regex rules failed:\n" + "\n".join(errors)) +# +# def test_all_command_rules(): +# errors = [] +# for test_name, test_dict in get_command_tests().items(): +# try: +# check_command_rule(test_name, test_dict) +# except AssertionError as e: +# errors.append(f"{test_name}: {e}") +# except Exception as e: +# errors.append(f"{test_name}: unexpected error: {e!r}") +# if errors: +# pytest.fail("Some command rules failed:\n" + "\n".join(errors))