ratchets

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

commit b161c6a9e8d0fabc3ce8baeda571ee1ead6c861e
parent 3b6b7264373646d426224436d87e57673d600bbe
Author: Andrew D. Laack <andrew@laack.co>
Date:   Wed, 18 Jun 2025 19:44:48 -0500

Merge pull request #1 from andrewlaack/toml-naming-change

Toml naming change
Diffstat:
MREADME.md | 8++++----
Msrc/ratchets/abstracted_tests.py | 9++++++---
Asrc/ratchets/bad.py | 5+++++
Msrc/ratchets/run_tests.py | 4++--
Msrc/ratchets/validate.py | 2+-
Mtests.toml | 8++++----
Mtests/toml_files/default.toml | 8++++----
Mtests/toml_files/different/default_minus_1.toml | 6+++---
Mtests/toml_files/different/default_plus_1.toml | 10+++++-----
Mtests/toml_files/different/entirely_different.toml | 8++++----
Mtests/toml_files/invalid.toml | 8++++----
Mtests/toml_files/only-commands.toml | 2+-
Mtests/toml_files/only-python.toml | 2+-
Mtests/toml_files/regexp/invalid/default.toml | 8++++----
Mtests/toml_files/regexp/invalid/only-python.toml | 2+-
Mtests/toml_files/regexp/valid/default.toml | 8++++----
Mtests/toml_files/regexp/valid/only-commands.toml | 2+-
Mtests/toml_files/regexp/valid/only-python.toml | 2+-
18 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/README.md b/README.md @@ -16,14 +16,14 @@ pip install ratchets You first need to create a tests.toml file at the root of your repository. See [tests.toml](tests.toml) for an example of how this should look. There are two primary rule types that can be defined in the tests.toml file. -## python-tests +## ratchet.regex These are tests that check regular expressions on the basis of each line of each file being examined. **Example:** ```toml -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -52,7 +52,7 @@ except: The valid and invalid entries are not necessary, but we provide a CLI utility, ran with ```python3 -m ratchets.validate```, to verify the regular expressions don't exist in the valid string and do exist in the invalid string. If you are testing the tests.toml file in the current git repository or ```python3 -m ratchets.validate -f FILENAME``` if you need to test a specific toml file. -## custom-tests +## ratchet.shell These are tests that run against each file where each evaluation is of the form: @@ -66,7 +66,7 @@ It is assumed the standard output of the command describes each of the issues wh ```toml -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" ``` diff --git a/src/ratchets/abstracted_tests.py b/src/ratchets/abstracted_tests.py @@ -32,13 +32,16 @@ def get_config() -> Dict[str, Any]: def get_python_tests() -> Dict[str, Any]: """Extract and return the 'python-tests' section from config.""" config = get_config() - return config.get("python-tests", {}) or {} + python_tests = config.get("ratchet", {}).get("regex") + return python_tests or {} def get_command_tests() -> Dict[str, Any]: - """Extract and return the 'custom-tests' section from config.""" + """Extract and return the 'ratchet.shell' section from config.""" config = get_config() - return config.get("custom-tests", {}) or {} + shell_tests = config.get("ratchet", {}).get("shell") + return shell_tests or {} + def load_baseline_counts() -> Dict[str, int]: diff --git a/src/ratchets/bad.py b/src/ratchets/bad.py @@ -0,0 +1,5 @@ +except: +except: +except: +except: +except: diff --git a/src/ratchets/run_tests.py b/src/ratchets/run_tests.py @@ -82,8 +82,8 @@ def evaluate_tests(path: str, cmd_only: bool, regex_only: bool) -> Tuple[Dict[st config = toml.load(path) - python_tests = config.get("python-tests") - custom_tests = config.get("custom-tests") + python_tests = config.get("ratchet", {}).get("regex") + custom_tests = config.get("ratchet", {}).get("shell") root = find_project_root() files = get_python_files(root) EXCLUDED_PATH = "ratchet_excluded.txt" diff --git a/src/ratchets/validate.py b/src/ratchets/validate.py @@ -33,7 +33,7 @@ def check_invalid(python_tests: Dict[str, Dict[str, Any]]) -> int: def validate(filename : Optional[str]) -> Optional[bool]: test_path: str = get_file_path(filename) config: Dict[str, Any] = toml.load(test_path) - python_tests: Optional[Dict[str, Dict[str, Any]]] = config.get("python-tests") + python_tests: Optional[Dict[str, Dict[str, Any]]] = config.get("ratchet", {}).get("regex") if python_tests is None: print("No python tests found, there is nothing to validate.") diff --git a/tests.toml b/tests.toml @@ -1,7 +1,7 @@ # these will be ran in *parallel # (gthreads) -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -25,12 +25,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -48,5 +48,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/default.toml b/tests/toml_files/default.toml @@ -1,7 +1,7 @@ # these will be ran in *parallel # (gthreads) -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -25,12 +25,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -48,5 +48,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/different/default_minus_1.toml b/tests/toml_files/different/default_minus_1.toml @@ -1,12 +1,12 @@ # these will be ran in *parallel # (gthreads) -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -24,5 +24,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/different/default_plus_1.toml b/tests/toml_files/different/default_plus_1.toml @@ -3,7 +3,7 @@ -[python-tests.typos] +[ratchet.regex.typos] regex = "rachet|ratchet|rathet|rachet|ratchett" valid = [ """ @@ -18,7 +18,7 @@ invalid = [ -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -42,12 +42,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -65,5 +65,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/different/entirely_different.toml b/tests/toml_files/different/entirely_different.toml @@ -1,7 +1,7 @@ # these will be ran in *parallel # (gthreads) -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -25,12 +25,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -48,5 +48,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/invalid.toml b/tests/toml_files/invalid.toml @@ -3,7 +3,7 @@ # see missing ] (invalid) -[python-tests.exceptions +[ratchet.regex.exceptions regex = "except:" valid = [ """try: @@ -27,12 +27,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -50,5 +50,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/only-commands.toml b/tests/toml_files/only-commands.toml @@ -1,2 +1,2 @@ -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/only-python.toml b/tests/toml_files/only-python.toml @@ -1,4 +1,4 @@ -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: diff --git a/tests/toml_files/regexp/invalid/default.toml b/tests/toml_files/regexp/invalid/default.toml @@ -1,7 +1,7 @@ # these will be ran in *parallel # (gthreads) -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" invalid = [ """try: @@ -25,12 +25,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -48,5 +48,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/regexp/invalid/only-python.toml b/tests/toml_files/regexp/invalid/only-python.toml @@ -1,4 +1,4 @@ -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" invalid = [ """try: diff --git a/tests/toml_files/regexp/valid/default.toml b/tests/toml_files/regexp/valid/default.toml @@ -1,7 +1,7 @@ # these will be ran in *parallel # (gthreads) -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: @@ -25,12 +25,12 @@ except: recover()""" ] -[python-tests.lightning] +[ratchet.regex.lightning] regex = "import pytorch_lightning|from pytorch_lightning" valid = ["import torch", "from my_project import Trainer"] invalid = ["import pytorch_lightning", "from pytorch_lightning import LightningModule"] -[python-tests.tabs] +[ratchet.regex.tabs] regex = "\\t" valid = [ """def foo(): @@ -48,5 +48,5 @@ invalid = [ # these can be tested by running echo FILEPATH | COMMAND # these will be ran in parallel -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/regexp/valid/only-commands.toml b/tests/toml_files/regexp/valid/only-commands.toml @@ -1,2 +1,2 @@ -[custom-tests.line_too_long] +[ratchet.shell.line_too_long] command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/regexp/valid/only-python.toml b/tests/toml_files/regexp/valid/only-python.toml @@ -1,4 +1,4 @@ -[python-tests.exceptions] +[ratchet.regex.exceptions] regex = "except:" valid = [ """try: