diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebffcb5c..bf65b69f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,13 @@ repos: - id: trailing-whitespace args: [ --markdown-linebreak-ext=md ] exclude: '\.svg' + - repo: local + hooks: + - id: check-test-file-name + name: check test file name convention + entry: python tools/check-test-file-name.py + language: python + files: '(tests/.*\.py)$' - repo: https://github.com/kynan/nbstripout rev: 0.7.1 hooks: diff --git a/tools/check-test-file-name.py b/tools/check-test-file-name.py new file mode 100644 index 00000000..b5dce929 --- /dev/null +++ b/tools/check-test-file-name.py @@ -0,0 +1,21 @@ +from pathlib import Path +import sys + +ALLOWED_NAMES = ("conftest.py",) + + +def main(): + errors = False + paths = map(Path, sys.argv[1:]) + for path in paths: + if path.name in ALLOWED_NAMES: + continue + if not path.stem.endswith("_test"): + sys.stderr.write(f"Bad test file name: {path}\n") + errors = True + + sys.exit(int(errors)) + + +if __name__ == "__main__": + main()