diff --git a/TODO.md b/TODO.md index 48df20e..ca18442 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,13 @@ - [ ] docs: point to new architecture docs from python repo +# 9/22/24 +todo: +failure we saw was from a task from a few weeks ago +the failure we see is: +problem of how do we kknow if a .approved file was used in a run +so we can remove the STALE (abandonded) approved files + # Roles From https://github.com/willemlarsen/mobprogrammingrpg/blob/master/rpg_roles_plain_text.md diff --git a/approvaltests/commandline_interface.py b/approvaltests/commandline_interface.py index 5e0aa40..3727c73 100644 --- a/approvaltests/commandline_interface.py +++ b/approvaltests/commandline_interface.py @@ -1,24 +1,22 @@ -from pathlib import Path - +import argparse +from sys import stdin from approvaltests import verify -from build.lib.approvaltests.commandline_interface import parse_arguments -from namer.cli_namer import CliNamer - - -# simplify the following lines of code from commandline_interface.py -# 1. Modify so our future-selves would recognize it -# >>> 2. Make a test -# 3. Refactor parse_arguments to be part of a class (suggested by Jay) +# pylint: disable = no-name-in-module +from approvaltests.namer.cli_namer import CliNamer -# NEw code... -# received = args.received or stdin.read() -# Old code... -# received = args.received -# if args.received is None: -# received = stdin.read() -# return (args.id, received) +def parse_arguments(): + parser = argparse.ArgumentParser(description="verify") + parser.add_argument( + "--test-id", "-t", dest="id", required=True, type=str, help="test id" + ) + parser.add_argument("--received", "-r", type=str, required=False, help="received") + args = parser.parse_args() + received = args.received + if args.received is None: + received = stdin.read() + return (args.id, received) def verify_using_commandline_arguments(): @@ -32,8 +30,4 @@ def verify_with_id(received, test_id): if __name__ == "__main__": - verify_using_commandline_arguments() - - -def list_approved_files_in_test_directory(test_dir: Path): - return [file.name for file in test_dir.iterdir() if file.name.endswith(".approved.txt")] + verify_using_commandline_arguments() \ No newline at end of file diff --git a/tests/test_build.py b/tests/test_build.py index 6ec3052..25748ad 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -5,23 +5,27 @@ def test_no_imports_from_build_directory(): # Make sure no file imports from build root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) for dirpath, dirnames, filenames in os.walk(root_dir): - # Skip the 'build' directory and its subdirectories - if 'build' in dirnames: - dirnames.remove('build') + # Exclude directories that start with '.' + dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != 'build'] + # also exclude venv + dirnames[:] = [d for d in dirnames if not d.startswith('venv' + )] for filename in filenames: - if filename.endswith('.py'): - file_path = os.path.join(dirpath, filename) - with open(file_path, 'r', encoding='utf-8') as file: - source = file.read() - try: - tree = ast.parse(source, filename=file_path) - except SyntaxError: - continue # Skip files with syntax errors - for node in ast.walk(tree): - if isinstance(node, ast.Import): - for alias in node.names: - if alias.name == 'build' or alias.name.startswith('build.'): - assert False, f"{file_path} imports 'build'" - elif isinstance(node, ast.ImportFrom): - if node.module == 'build' or (node.module and node.module.startswith('build.')): - assert False, f"{file_path} imports from 'build'" + # Skip files that start with '.' and non-Python files + if filename.startswith('.') or not filename.endswith('.py'): + continue + file_path = os.path.join(dirpath, filename) + with open(file_path, 'r', encoding='utf-8') as file: + source = file.read() + try: + tree = ast.parse(source, filename=file_path) + except SyntaxError: + continue # Skip files with syntax errors + for node in ast.walk(tree): + if isinstance(node, ast.Import): + for alias in node.names: + if alias.name == 'build' or alias.name.startswith('build.'): + assert False, f"{file_path} imports 'build'" + elif isinstance(node, ast.ImportFrom): + if node.module == 'build' or (node.module and node.module.startswith('build.')): + assert False, f"{file_path} imports from 'build'"