def test_exclude_programs(): # The program collatz_print.py is imported by fizzbuzz.py, and indirectly by is_even.py. # Excluding the former excludes the two latter too. dbf = ProgramFilter(db) dbf.exclude_programs({"collatz_print.py"}) print(set(dbf.selected_programs.keys())) assert set(dbf.selected_programs.keys()) == {"assignment.py"} # The program fizzbuzz.py is imported by is_even.py. Excluding the former excludes both. dbf = ProgramFilter(db) dbf.exclude_programs({"fizzbuzz.py"}) print(set(dbf.selected_programs.keys())) assert set( dbf.selected_programs.keys()) == {"assignment.py", "collatz_print.py"} # The program is_even.py is not imported. Excluding it has no other effect on the selection. dbf = ProgramFilter(db) dbf.exclude_programs({"is_even.py"}) print(set(dbf.selected_programs.keys())) assert set(dbf.selected_programs.keys()) == { "assignment.py", "collatz_print.py", "fizzbuzz.py", }
def test_exclude_taxa(): # The taxon "var/assignment/explicit/single" is featured by assignment.py and collatz.py. It # is indirectly featured by fizzbuzz.py (which imports collatz.py) and by is_even.py # (which imports fizzbuzz.py). Therefore, excluding this taxon excludes all four programs. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa( {"var/assignment/explicit/single"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == set() # "operator/arithmetic/addition" is featured by collatz.py, and indirectly by fizzbuzz.py # and is_even.py. Therefore, excluding this taxon keeps only assignment.py. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa( {"call/subroutine/builtin/print"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py"} # "flow/conditional" is featured by collatz.py, fizzbuzz.py, and indirectly by # is_even.py. Therefore, excluding this taxon keeps only assignment.py. dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa({"flow/conditional"}), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py"} # "type/sequence/string/literal" is featured by fizzbuzz.py, and indirectly by is_even.py. # Therefore, excluding this taxon keeps only assignment.py and collatz.py dbf = ProgramFilter(db) dbf.exclude_programs(dbf.programs_of_taxa({"type/sequence/string/literal" }), follow=True) print(dbf.selected_programs) assert dbf.selected_programs == {"assignment.py", "collatz.py"}
def test_exclude_programs(): dbf = ProgramFilter(db) programs = {"prg1.py", "prg2.py", "non_existing_program"} dbf.exclude_programs(programs) print(sorted(dbf.selected_programs)) assert dbf.selected_programs.keys() == set(db["programs"]) - set(programs)