Skip to content

Commit

Permalink
- f revert commandlineinterface.py and test for build imports
Browse files Browse the repository at this point in the history
excluding venv

Co-Authored-By: 4dsherwood <[email protected]>
Co-Authored-By: jmasonlee <[email protected]>
Co-Authored-By: Jay Bazuzi <[email protected]>
Co-Authored-By: Nitsan Avni <[email protected]>
Co-Authored-By: Michael R Wolf <[email protected]>
Co-Authored-By: Matt Anderson <[email protected]>
  • Loading branch information
7 people committed Sep 22, 2024
1 parent 7d9a0ed commit d570c41
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 16 additions & 22 deletions approvaltests/commandline_interface.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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()
42 changes: 23 additions & 19 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

0 comments on commit d570c41

Please sign in to comment.