def test_ranking_parser_whitespace_partial_token_matches():
    expected_result = ("The_orange_cat", "The_grey_cat")
    rp = RankingParser()
    result = rp.parse_statements([
        "The orange cat before The grey cat",
    ])
    assert (result == expected_result)
def test_ranking_parser_whitespace_partial_token_matches_missed_capital():
    expected_result = ("The_orange_cat", "Grey_cat")
    rp = RankingParser()
    result = rp.parse_statements([
        "The orange cat is before the Grey cat",
    ])
    assert (result == expected_result)
def test_ranking_parser_parse_whitespace_in_brackets():
    expected_result = ("Captain_Blackbeard", "Long_John_Silver")
    rp = RankingParser()
    result = rp.parse_statements([
        "[Captain Blackbeard] is not last", "[Long John Silver] is not first"
    ])
    assert (result == expected_result)
Exemple #4
0
def solve_challenge():
    rl = RankingLexer()
    hl = HighLighter(rl, STYLE_MAP)

    print()

    for s in programmer_riddle:
        print(hl.highlight(s))

    print()
    print("Solving by specifying rules")
    print(Fore.CYAN + ("=" * 30) + Fore.RESET)
    r = RankingProblem()

    r.set_items(["Jessie", "Evan", "John", "Sarah", "Matt"]).\
        not_first("Jessie").not_last("Evan").\
        not_first("John").not_last("John").\
        is_before("Sarah", "Evan").\
        not_directly_before_or_after("Matt", "John").\
        not_directly_before_or_after("John", "Evan")

    solutions = r.solve()

    for s in solutions:
        typewrite_print(", ".join(s))

    print()

    print("Solving by parsing")
    print(Fore.CYAN + ("=" * 30) + Fore.RESET)

    rp = RankingParser()
    typewrite_print(", ".join(rp.parse_statements(programmer_riddle)))
def test_ranking_parser_parse_statements():
    expected_result = (
        "Sarah",
        "John",
        "Jessie",
        "Evan",
        "Matt",
    )

    rp = RankingParser()
    result = rp.parse_statements(programmer_riddle)
    print(result)
    assert (result == expected_result)
def test_ranking_parser_parse_add_entity_statements():
    rp = RankingParser()
    expected_result = [
        "George_Harrison",
        "John_Lennon",
        "Paul_McCartney",
        "Ringo_Starr",
    ]

    result = rp.parse_statements([
        "+[Ringo Starr]",
        "John Lennon",
        "[Paul McCartney]",
        "+George Harrison",
    ])

    assert (sorted(result) == expected_result)
Exemple #7
0
def test_export_csv():
    test = RankingParser()
    lines = None

    filename = str(uuid.uuid1())
    filename = f"{filename}.csv"

    solutions = test.parse_statements(tea_steps, return_last_parsed=False)

    try:
        export_csv(solutions, filename)

        with open(filename, "r") as txt_file:
            lines = txt_file.readlines()
    finally:
        os.remove(filename)

    assert ("".join(lines) == tea_steps_result_csv)
def test_ranking_parser_parse_statements_no_statements():
    rp = RankingParser()
    with pytest.raises(IncompleteResultsError):
        rp.parse_statements([])
def test_ranking_parser_parse_statements_no_statements():
    rp = RankingParser()
    result = rp.parse_statements([])

    assert (result is None)