示例#1
0
def test_no_match_found():
    with pytest.raises(NoMatchFound):
        Match(
            "Some other super string",
            ("Some string that will never match", 1),
            keep=True,
        )
示例#2
0
def test_simple_match():
    assert (Match(
        "My super string",
        ("A super string", False),
        ("MY super string", ""),
        ("My super string", True),
    ) == True)
示例#3
0
def test_match_on_any():
    assert (Match(
        "My super string",
        ("A super string", False),
        ("MY super string", ""),
        (_, True),
    ) is True)
示例#4
0
def test_raises():
    with pytest.raises(ValueError):
        Match(
            "Some other super string",
            ("A super string", False),
            ("MY super string", ""),
            ("Some other super string",
             ValueError("This string it too super for me")),
        )
示例#5
0
def test_multiple_match():
    my_first_val = "Oggy"
    my_second_val = "McFrites"

    assert (Match(
        (my_first_val, my_second_val),
        (("Albert", "Donovan"), "First!"),
        ((_, _), "Second!"),
    ) == "Second!")

    with pytest.raises(ValueError):
        Match(
            (my_first_val, my_second_val),
            (
                (RegexMatcher(r"^O\w{3}$"), _),
                ValueError("I'm raising an exception."),
            ),
            (("Oggy", "McFrites"), "Second!"),
        )
示例#6
0
def test_regex():
    assert (Match(
        "123-654-897",
        (
            RegexMatcher(r"(?P<first_test_regex>\d{3}(| |-)\d{3}(| |-)\d{3})"),
            "First!",
        ),
        (RegexMatcher(r"(?P<second_test_regex>\d+(| |-)\d+(| |-)\d+)"),
         "Second!"),
        (RegexMatcher(r"^123")),
        "Third!",
    ) == "First!")
示例#7
0
def test_match_floats():
    assert Match(1.0001, (1.0001, "Oh hello there!")) == "Oh hello there!"
示例#8
0
def test_keep():
    match_object = Match("Some other super string",
                         ("Some other super string", 1),
                         keep=True)
    assert type(match_object) is Match
示例#9
0
def test_wrong_pair_given():
    with pytest.raises(ValueError):
        Match("Some other super string", (1, 2, 3), ("yes", "no"))
示例#10
0
def test_one_pair_required():
    with pytest.raises(ValueError):
        Match("Some other super string")