ratchets

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

commit 0ee96767e2914b09fa776969cdafbefb734508aa
parent 844a0da541b0b20102e1e865159180e09331336b
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 18 Jun 2025 14:06:56 -0500

Added a bunch of tests, refactored code, added directory to show example usage

Diffstat:
M.gitignore | 1-
Aexamples/example_test_ratchet.py | 34++++++++++++++++++++++++++++++++++
Apyproject.toml | 23+++++++++++++++++++++++
Msrc/ratchets/abstracted_tests.py | 10++++++++--
Asrc/ratchets/example_test_ratchet.py | 34++++++++++++++++++++++++++++++++++
Msrc/ratchets/run_tests.py | 10++++++++++
Dsrc/ratchets/test_ratchet.py | 34----------------------------------
Msrc/ratchets/validate.py | 28++++++++++++++--------------
Atests.toml | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/excluded_files/default_excluded.txt | 1+
Atests/excluded_files/no_1.txt | 1+
Atests/excluded_files/no_1_or_dir.txt | 2++
Atests/python_files/ex_dir/ex_example1.py | 1+
Atests/python_files/ex_dir/ex_example2.py | 1+
Atests/python_files/example1.py | 1+
Atests/python_files/example2.py | 1+
Atests/python_files/example3.py | 1+
Atests/python_files/example4.py | 1+
Atests/test_files/test_exclusion.py | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/test_files/test_toml_configs.py | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/test_files/test_validation.py | 26++++++++++++++++++++++++++
Atests/toml_files/blank.toml | 0
Atests/toml_files/default.toml | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/different/default_minus_1.toml | 28++++++++++++++++++++++++++++
Atests/toml_files/different/default_plus_1.toml | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/different/entirely_different.toml | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/invalid.toml | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/only-commands.toml | 2++
Atests/toml_files/only-python.toml | 23+++++++++++++++++++++++
Atests/toml_files/regexp/invalid/default.toml | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/regexp/invalid/only-python.toml | 23+++++++++++++++++++++++
Atests/toml_files/regexp/valid/default.toml | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/toml_files/regexp/valid/only-commands.toml | 2++
Atests/toml_files/regexp/valid/only-python.toml | 23+++++++++++++++++++++++
34 files changed, 819 insertions(+), 51 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -194,6 +194,5 @@ cython_debug/ .cursorindexingignore ratchet_values.json ratchet_excluded.txt -*.toml notes/ data/ diff --git a/examples/example_test_ratchet.py b/examples/example_test_ratchet.py @@ -0,0 +1,34 @@ +import pytest +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: + check_python_rule(test_name, rule) + +@pytest.mark.parametrize("test_name,test_dict", get_command_tests().items()) +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)) diff --git a/pyproject.toml b/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "ratchets" +version = "0.1.0" +description = "Ratcheted testing in Python." +authors = [ + { name = "Andrew Laack", email = "andrew@laack.co" } +] +readme = "README.md" +license = { text = "GPL-3.0-only" } +requires-python = ">=3.7" +dependencies = [ + "pathspec==0.12.1", + "pytest==8.4.0", + "toml==0.10.2" +] + +[project.urls] +Homepage = "https://github.com/andrewlaack/ratchets" +Repository = "https://github.com/andrewlaack/ratchets" diff --git a/src/ratchets/abstracted_tests.py b/src/ratchets/abstracted_tests.py @@ -87,7 +87,10 @@ def get_command_test_matches(test_name: str, test_dict: Dict[str, Any]) -> List[ def check_python_rule(test_name: str, rule: Dict[str, Any]) -> None: - """Assert that current regex violations do not exceed baseline.""" + + assert (test_name is not None) + assert (rule is not None) + matches = get_python_test_matches(test_name, rule) current_count = len(matches) baseline_counts = get_baseline_counts() @@ -102,7 +105,10 @@ def check_python_rule(test_name: str, rule: Dict[str, Any]) -> None: def check_command_rule(test_name: str, test_dict: Dict[str, Any]) -> None: - """Assert that current command violations do not exceed baseline.""" + + assert (test_name is not None) + assert (test_dict is not None) + matches = get_command_test_matches(test_name, test_dict) current_count = len(matches) baseline_counts = get_baseline_counts() diff --git a/src/ratchets/example_test_ratchet.py b/src/ratchets/example_test_ratchet.py @@ -0,0 +1,34 @@ +import pytest +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: + check_python_rule(test_name, rule) + +@pytest.mark.parametrize("test_name,test_dict", get_command_tests().items()) +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)) diff --git a/src/ratchets/run_tests.py b/src/ratchets/run_tests.py @@ -77,8 +77,11 @@ def filter_excluded_files(files: List[Path], excluded_path: str, ignore_path: st def evaluate_tests(path: str, cmd_only: bool, regex_only: bool) -> Tuple[Dict[str, List[Dict[str, Any]]], Dict[str, List[Dict[str, Any]]]]: + assert os.path.isfile(path) + config = toml.load(path) + python_tests = config.get("python-tests") custom_tests = config.get("custom-tests") root = find_project_root() @@ -388,6 +391,12 @@ def cli(): action="store_true", help="update ratchets_values.json" ) + + parser.add_argument( + "--validate", + action="store_true", + help="validate toml regex patterns" + ) args = parser.parse_args() file: Optional[str] = args.file @@ -397,6 +406,7 @@ def cli(): compare_counts: bool = args.compare_counts blame: bool = args.blame verbose: bool = args.verbose + validate: bool = args.validate max_count: Optional[int] = args.max_count if not max_count: diff --git a/src/ratchets/test_ratchet.py b/src/ratchets/test_ratchet.py @@ -1,34 +0,0 @@ -import pytest -from 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: - check_python_rule(test_name, rule) - -@pytest.mark.parametrize("test_name,test_dict", get_command_tests().items()) -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)) diff --git a/src/ratchets/validate.py b/src/ratchets/validate.py @@ -1,8 +1,10 @@ -import run_tests import re import toml import argparse from typing import Dict, Any, Optional +from .run_tests import ( + get_file_path, +) def evaluate_single_regex(regex: str, custom_str: str) -> Optional[re.Match[str]]: pattern = re.compile(regex) @@ -28,28 +30,26 @@ def check_invalid(python_tests: Dict[str, Dict[str, Any]]) -> int: raise AssertionError(f"Regex: {regex} not matched in {validation}") return 0 -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Python ratchet testing") - parser.add_argument("-f", "--file") - args = parser.parse_args() - file: Optional[str] = args.file - test_path: str = run_tests.get_file_path(file) +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") if python_tests is None: print("No python tests found, there is nothing to validate.") - exit() + return True check_valid(python_tests) check_invalid(python_tests) - - print(f"All expected regex invalid/valid samples are correct for:\n{test_path}") - - - - + return True + print(f"All expected regex invalid/valid samples are correct for:\n{test_path}") +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Python ratchet testing") + parser.add_argument("-f", "--file") + args = parser.parse_args() + file: Optional[str] = args.file + validate(file) diff --git a/tests.toml b/tests.toml @@ -0,0 +1,52 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.line_too_long] +command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/excluded_files/default_excluded.txt b/tests/excluded_files/default_excluded.txt @@ -0,0 +1 @@ +myenv/ diff --git a/tests/excluded_files/no_1.txt b/tests/excluded_files/no_1.txt @@ -0,0 +1 @@ +*1* diff --git a/tests/excluded_files/no_1_or_dir.txt b/tests/excluded_files/no_1_or_dir.txt @@ -0,0 +1,2 @@ +*1* +ex_dir/ diff --git a/tests/python_files/ex_dir/ex_example1.py b/tests/python_files/ex_dir/ex_example1.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/python_files/ex_dir/ex_example2.py b/tests/python_files/ex_dir/ex_example2.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/python_files/example1.py b/tests/python_files/example1.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/python_files/example2.py b/tests/python_files/example2.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/python_files/example3.py b/tests/python_files/example3.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/python_files/example4.py b/tests/python_files/example4.py @@ -0,0 +1 @@ +# This is an example file, let's see if it is indexed! diff --git a/tests/test_files/test_exclusion.py b/tests/test_files/test_exclusion.py @@ -0,0 +1,67 @@ + +from ratchets import run_tests +from ratchets import abstracted_tests +import os +import toml +from typing import Dict, Any +import json +import shutil + + +def test_config(): + test_path = run_tests.get_file_path(None) + + assert os.path.isfile(test_path), "tests.toml not found" + + try: + issues = run_tests.evaluate_tests(test_path, True, True) + run_tests.update_ratchets(test_path, True, True) + except Exception as e: + assert False, f"Unable to update ratchets using 'tests.toml': {e}" + + +# TODO: +# add gitignore checks. +# gitignore is handled the same way as +# the excluded file, but should be checked too + +def test_exclusion(): + + current_file_directory = os.path.dirname(os.path.abspath(__file__)) + excluded_directory = os.path.abspath(os.path.join(current_file_directory, "..", "excluded_files")) + test_py_dir= os.path.abspath(os.path.join(current_file_directory, "..", "python_files")) + exclusion_path = run_tests.get_excludes_path() + root = run_tests.find_project_root() + ignore_path = os.path.join(root, ".gitignore") + + python_files_no_exclusion = run_tests.get_python_files(test_py_dir) + + # ensure no side effects in the method + # since we don't change the path values, + # ensuring the count reamins the same should suffice + + length_starting = len(python_files_no_exclusion) + + + expected_results = { + "default_excluded.txt" : 6, + "no_1.txt" : 4, + "no_1_or_dir.txt" : 3 + } + + count = 0 + for filename in os.listdir(excluded_directory): + count += 1 + full_path = os.path.abspath(os.path.join(excluded_directory, filename)) + shutil.copy(full_path, exclusion_path) + filtered = run_tests.filter_excluded_files(python_files_no_exclusion, exclusion_path, ignore_path) + assert len(python_files_no_exclusion) == length_starting, "There is a side effect in filter_excluded_files" + + assert filename in expected_results, "An additional excluded.txt file was added, but the corresponding expected count was not add to the dict" + assert expected_results[filename] == len(filtered), "Filter count differs from expected value" + + assert count == len(expected_results), "There is an entry in the expected_results dictionary that does not correspond with a file tested" + +if __name__ == "__main__": + test_config() + test_exclusion() diff --git a/tests/test_files/test_toml_configs.py b/tests/test_files/test_toml_configs.py @@ -0,0 +1,109 @@ +from ratchets import run_tests +from ratchets import abstracted_tests +import os +import toml +from typing import Dict, Any +import json + +# verify code still runs as expected even +# if only cmd or only python sections are defined + +# also, ensure sufficiently informative message is shown when +# invalid toml is used. + +# ensure environment is configured correctly for other tests to run. +# this creates a ratchet_excluded.txt file, +# creates the output json, and verifies there is a default tests.toml file + +def test_config(): + test_path = run_tests.get_file_path(None) + + assert os.path.isfile(test_path), "tests.toml not found" + + try: + issues = run_tests.evaluate_tests(test_path, True, True) + run_tests.update_ratchets(test_path, True, True) + except Exception as e: + assert False, f"Unable to update ratchets using 'tests.toml': {e}" + + +def test_formatting(): + current_file_directory = os.path.dirname(os.path.abspath(__file__)) + toml_file_directory = os.path.abspath(os.path.join(current_file_directory, "..", "toml_files")) + + for filename in os.listdir(toml_file_directory): + if filename == "invalid.toml": + try: + full_path = os.path.abspath(os.path.join(toml_file_directory, filename)) + run_tests.evaluate_tests(full_path, True, True) + except Exception as e: + assert isinstance(e, toml.TomlDecodeError), f"Expected TomlDecodeError, got {type(e)}: {e}" + else: + assert False, f"Expected error to be thrown for invalid toml file." + + else: + full_path = os.path.abspath(os.path.join(toml_file_directory, filename)) + + # there is a directory in there + if os.path.isfile(full_path): + run_tests.evaluate_tests(full_path, True, True) + + full_path = os.path.abspath(os.path.join(toml_file_directory, filename)) + + +# ensure updated values match subsequent runs. +def verify_updating(): + test_path = run_tests.get_file_path(None) + run_tests.update_ratchets(test_path, True, True) + + # if one is false then the results are guaranteed + # to be either the same or lower. + + issues = run_tests.evaluate_tests(test_path, True, True) + current_json : Dict [str, Any] = json.loads(run_tests.results_to_json(issues)) + previous_json : Dict[str, Any] = run_tests.load_ratchet_results() + + assert current_json == previous_json + +# test how things behave when ratchet_values.json does not exist +def test_ratchet_excluded_missing(): + + ratchet_path = abstracted_tests.get_ratchet_path() + + if os.path.isfile(ratchet_path): + try: + os.remove(ratchet_path) + except Exception as e: + assert False, "Unable to delete ratchet_values.json" + + test_path = run_tests.get_file_path(None) + issues = run_tests.evaluate_tests(test_path, True, True) + + # writes back json file + run_tests.update_ratchets(test_path, True, True) + + return + +# test when there are additional values, +# less values, no values (in current). + +def test_ratchet_values_differ(): + + # ensure clean start + test_config() + + current_file_directory = os.path.dirname(os.path.abspath(__file__)) + toml_file_directory = os.path.abspath(os.path.join(current_file_directory, "..", "toml_files/different")) + + for filename in os.listdir(toml_file_directory): + full_path = os.path.abspath(os.path.join(toml_file_directory, filename)) + run_tests.evaluate_tests(full_path, True, True) + full_path = os.path.abspath(os.path.join(toml_file_directory, filename)) + + return + +if __name__ == "__main__": + test_config() + test_formatting() + test_ratchet_excluded_missing() + test_ratchet_values_differ() diff --git a/tests/test_files/test_validation.py b/tests/test_files/test_validation.py @@ -0,0 +1,26 @@ +from ratchets import validate +import os + +def test_validate_regex(): + current_file_directory = os.path.dirname(os.path.abspath(__file__)) + toml_file_directory_valid = os.path.abspath(os.path.join(current_file_directory, "..", "toml_files/regexp/valid")) + toml_file_directory_invalid = os.path.abspath(os.path.join(current_file_directory, "..", "toml_files/regexp/invalid")) + + for filename in os.listdir(toml_file_directory_valid): + full_path = os.path.abspath(os.path.join(toml_file_directory_valid, filename)) + if os.path.isfile(full_path): + assert validate.validate(full_path), f"{full_path}, was deemed to be invalid" + + for filename in os.listdir(toml_file_directory_invalid): + full_path = os.path.abspath(os.path.join(toml_file_directory_invalid, filename)) + + if os.path.isfile(full_path): + try: + validate.validate(full_path) + except Exception: + pass + else: + assert False, f"Expected validation to fail for {full_path}, but it passed" + +if __name__ == "__main__": + test_validate_regex() diff --git a/tests/toml_files/blank.toml b/tests/toml_files/blank.toml diff --git a/tests/toml_files/default.toml b/tests/toml_files/default.toml @@ -0,0 +1,52 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,28 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,69 @@ +# these will be ran in *parallel +# (gthreads) + + + +[python-tests.typos] +regex = "rachet|ratchet|rathet|rachet|ratchett" +valid = [ + """ + ratchet + """ +] +invalid = [ + """ + rachet + """ +] + + + +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,52 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.line_too_long] +command = "xargs -n1 awk 'length($0) > 80'" diff --git a/tests/toml_files/invalid.toml b/tests/toml_files/invalid.toml @@ -0,0 +1,54 @@ +# these will be ran in *parallel +# (gthreads) + + +# see missing ] (invalid) +[python-tests.exceptions +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,2 @@ +[custom-tests.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 @@ -0,0 +1,23 @@ +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] diff --git a/tests/toml_files/regexp/invalid/default.toml b/tests/toml_files/regexp/invalid/default.toml @@ -0,0 +1,52 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.exceptions] +regex = "except:" +invalid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +valid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,23 @@ +[python-tests.exceptions] +regex = "except:" +invalid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +valid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] diff --git a/tests/toml_files/regexp/valid/default.toml b/tests/toml_files/regexp/valid/default.toml @@ -0,0 +1,52 @@ +# these will be ran in *parallel +# (gthreads) + +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +] + +[python-tests.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] +regex = "\\t" +valid = [ + """def foo(): + return 42""", + "print('no tab here')" +] +invalid = [ + """\tprint('starts with tab')""", + """def bar(): +\treturn True""" +] + +# printed text is assumed to be failures +# each evaluation **must** accept a file path as input +# these can be tested by running echo FILEPATH | COMMAND +# these will be ran in parallel + +[custom-tests.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 @@ -0,0 +1,2 @@ +[custom-tests.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 @@ -0,0 +1,23 @@ +[python-tests.exceptions] +regex = "except:" +valid = [ + """try: + x = 1 +except ValueError: + pass""", + """try: + do_something() +except (IOError, ValueError): + handle()""" +] +invalid = [ + """ +try: + pass +except: + pass""", + """try: + dangerous() +except: + recover()""" +]