コード例 #1
0
def test_match():
    """
    Given a regex object and a string that matches the regex pattern, when
    match() is called with the object, then it returns a function that returns
    the string when called with it.
    """
    r = re.compile('^foo.*baz$')
    s = 'foobarbaz'
    validator = mod.match(r)
    assert validator(s) == s
コード例 #2
0
def test_match():
    """
    Given a regex object and a string that matches the regex pattern, when
    match() is called with the object, then it returns a function that returns
    the string when called with it.
    """
    r = re.compile("^foo.*baz$")
    s = "foobarbaz"
    validator = mod.match(r)
    assert validator(s) == s
コード例 #3
0
def test_no_match():
    """
    Given a regex object and a string that does not match the regex pattern,
    when match() is called with the object, then it returns a function that
    raises ValueError exception when called with the sting.
    """
    r = re.compile('^foo.*baz$')
    s = 'foobarbazooka'
    validator = mod.match(r)
    with pytest.raises(ValueError):
        validator(s)
コード例 #4
0
def test_no_match():
    """
    Given a regex object and a string that does not match the regex pattern,
    when match() is called with the object, then it returns a function that
    raises ValueError exception when called with the sting.
    """
    r = re.compile("^foo.*baz$")
    s = "foobarbazooka"
    validator = mod.match(r)
    with pytest.raises(ValueError):
        validator(s)