コード例 #1
0
def test_exclude_taxons():
    dbf = ProgramFilter(db)
    taxons = ["O/J", "X/S/M/L", "non_existing_taxon"]
    dbf.exclude_taxons(taxons)
    print(sorted(dbf.selected_programs))
    assert dbf.selected_programs.keys() == {"prg2.py", "prg5.py"}
    for taxon in taxons:
        assert taxon not in db["programs"]["prg2.py"]["taxons"]
        assert taxon not in db["programs"]["prg5.py"]["taxons"]
コード例 #2
0
def test_exclude_taxons():

    # The taxon "variable/assignment/single" is featured by assignment.py and collatz_print.py. It
    # is indirectly featured by fizzbuzz.py (which imports collatz_print.py) and by is_even.py
    # (which imports fizzbuzz.py). Therefore, excluding this taxon excludes all four programs.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({"variable/assignment/single"})
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == set()

    # "operator/arithmetic/addition" is featured by collatz_print.py, and indirectly by fizzbuzz.py
    # and is_even.py. Therefore, excluding this taxon keeps only assignment.py.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({"io/standard/print"})
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {"assignment.py"}

    # "flow/conditional" is featured by collatz_print.py, fizzbuzz.py, and indirectly by
    # is_even.py. Therefore, excluding this taxon keeps only assignment.py.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({"flow/conditional"})
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {"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_print.py
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({"type/sequence/string/literal"})
    print(set(dbf.selected_programs.keys()))
    assert set(
        dbf.selected_programs.keys()) == {"assignment.py", "collatz_print.py"}
コード例 #3
0
def test_exclude_taxons():

    # The taxon "variable/assignment/single" is featured by assignment.py and collatz_print.py. In
    # collatz_print.py, it appears after a taxon "io/standard/print". Consequently, it should be excluded
    # from the results, along with the programs which import it: fizzbuzz.py and is_even.py.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({("after", "variable/assignment/single", "io/standard/print")})
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {"assignment.py"}

    # "operator/arithmetic/addition" and "operator/arithmetic/multiplication" are both featured on
    # the same line of collatz_print.py, and indirectly by fizzbuzz.py and is_even.py. Therefore,
    # excluding this taxon keeps only assignment.py.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons(
        {("equals", "operator/arithmetic/addition", "operator/arithmetic/multiplication")}
    )
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {"assignment.py"}

    # "test/equality" is inside "subroutine/function" in is_even.py, which is not imported anywhere.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons({("inside", "test/equality", "subroutine/function")})
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {"collatz_print.py", "assignment.py", "fizzbuzz.py"}

    # "call/function/builtin/range" is not inside "flow/conditional" anywhere.
    dbf = ProgramFilter(db)
    dbf.exclude_taxons([("inside", "call/function/builtin/range", "flow/conditional")])
    print(set(dbf.selected_programs.keys()))
    assert set(dbf.selected_programs.keys()) == {
        "is_even.py",
        "fizzbuzz.py",
        "assignment.py",
        "collatz_print.py",
    }