def test_list_programs(): result = iter(list_programs(Path("examples/mini/programs/"))) program = next(result) assert program.path == "assignment.py" assert program.source == "a = b" program = next(result) assert program.path == "collatz.py" assert program.source.startswith("def print_collatz(n):") program = next(result) assert program.path == "fizzbuzz.py" assert program.source.startswith("import collatz") program = next(result) assert program.path == "is_even.py" assert program.source.__contains__( "def is_even(n):\n return n % 2 == 0")
def test_list_programs(): result = iter(list_programs(Path("tests/data/simple"))) program = next(result) assert program.name == "assignment.py" assert program.source == "a = b" program = next(result) assert program.name == "collatz_print.py" assert program.source.startswith("def print_collatz(n):") program = next(result) assert program.name == "fizzbuzz.py" assert program.source.startswith("import collatz_print") program = next(result) assert program.name == "is_even.py" assert program.source.__contains__( "def is_even(n):\n return n % 2 == 0")
def test_label_presence(capsys): all_names = set() present_names = set() result = [] for program in list_programs(Path("tests/data/simple/")): labels = parse( Program(source=program.source, labels=[], taxons=[], addition={}, deletion={}), yield_failed_matches=True, ) for (name, spans) in labels: all_names.add(name) if spans: present_names.add(name) result.append(name + f" / {program.name} / " + ", ".join(map(couple_to_string, spans))) present = "\n- ".join(sorted(result)) absent = "\n- ".join(sorted(all_names - present_names)) text = f"# Present labels\n\n- {present}\n\n# Absent labels\n\n- {absent}\n" make_snapshot(Path("tests/snapshots/simple_labels.md"), text, capsys)