Пример #1
0
def test_mixed_step():
    step = Step('a{foo}b')
    assert step.s == 'a{foo}b'
    assert step.generalized == 'a{}b'
    assert step.parts == ('a', 'b')
    assert step.names == ['foo']
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == 'a{}b'

    variables = {}
    assert step.match('abarb', variables)
    assert variables == {'foo': 'bar'}

    variables = {}
    assert not step.match('ab', variables)
    assert not variables

    variables = {}
    assert not step.match('xbary', variables)
    assert not variables

    variables = {}
    assert not step.match('yabarbx', variables)
    assert not variables

    variables = {}
    assert not step.match('afoo', variables)
    assert not variables
Пример #2
0
def test_mixed_step():
    step = Step('a{foo}b')
    assert step.s == 'a{foo}b'
    assert step.generalized == 'a{}b'
    assert step.parts == ('a', 'b')
    assert step.names == ['foo']
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == 'a{}b'

    variables = {}
    assert step.match('abarb', variables)
    assert variables == {'foo': 'bar'}

    variables = {}
    assert not step.match('ab', variables)
    assert not variables

    variables = {}
    assert not step.match('xbary', variables)
    assert not variables

    variables = {}
    assert not step.match('yabarbx', variables)
    assert not variables

    variables = {}
    assert not step.match('afoo', variables)
    assert not variables
Пример #3
0
def test_mixed_step():
    step = Step("a{foo}b")
    assert step.s == "a{foo}b"
    assert step.generalized == "a{}b"
    assert step.parts == ("a", "b")
    assert step.names == ["foo"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == "a{}b"

    variables = {}
    assert step.match("abarb", variables)
    assert variables == {"foo": "bar"}

    variables = {}
    assert not step.match("ab", variables)
    assert not variables

    variables = {}
    assert not step.match("xbary", variables)
    assert not variables

    variables = {}
    assert not step.match("yabarbx", variables)
    assert not variables

    variables = {}
    assert not step.match("afoo", variables)
    assert not variables
Пример #4
0
def test_multi_mixed_step():
    step = Step("{foo}a{bar}")
    assert step.s == "{foo}a{bar}"
    assert step.generalized == "{}a{}"
    assert step.parts == ("", "a", "")
    assert step.names == ["foo", "bar"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == "{}a{}"
Пример #5
0
def test_multi_mixed_step():
    step = Step("{foo}a{bar}")
    assert step.s == "{foo}a{bar}"
    assert step.generalized == "{}a{}"
    assert step.parts == ("", "a", "")
    assert step.names == ["foo", "bar"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == "{}a{}"
Пример #6
0
def test_multi_mixed_step():
    step = Step('{foo}a{bar}')
    assert step.s == '{foo}a{bar}'
    assert step.generalized == '{}a{}'
    assert step.parts == ('', 'a', '')
    assert step.names == ['foo', 'bar']
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == '{}a{}'
Пример #7
0
def test_multi_mixed_step():
    step = Step('{foo}a{bar}')
    assert step.s == '{foo}a{bar}'
    assert step.generalized == '{}a{}'
    assert step.parts == ('', 'a', '')
    assert step.names == ['foo', 'bar']
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == '{}a{}'
Пример #8
0
def test_variable_step():
    step = Step('{foo}')
    assert step.s == '{foo}'
    assert step.generalized == '{}'
    assert step.parts == ('', '')
    assert step.names == ['foo']
    assert step.converters == {}
    assert step.has_variables()
    assert step.match('bar') == (True, {'foo': 'bar'})
    assert step.discriminator_info() == '{}'
Пример #9
0
def test_variable_step():
    step = Step('{foo}')
    assert step.s == '{foo}'
    assert step.generalized == '{}'
    assert step.parts == ('', '')
    assert step.names == ['foo']
    assert step.converters == {}
    assert step.has_variables()
    assert step.match('bar') == (True, {'foo': 'bar'})
    assert step.discriminator_info() == '{}'
Пример #10
0
def test_variable_step():
    step = Step("{foo}")
    assert step.s == "{foo}"
    assert step.generalized == "{}"
    assert step.parts == ("", "")
    assert step.names == ["foo"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.match("bar") == (True, {"foo": "bar"})
    assert step.discriminator_info() == "{}"
Пример #11
0
def test_name_step():
    step = Step("foo")
    assert step.s == "foo"
    assert step.generalized == "foo"
    assert step.parts == ("foo",)
    assert step.names == []
    assert step.converters == {}
    assert not step.has_variables()
    assert step.match("foo") == (True, {})
    assert step.match("bar") == (False, {})
    assert step.discriminator_info() == "foo"
Пример #12
0
def test_converter():
    step = Step('{foo}', converters=dict(foo=Converter(int)))
    assert step.discriminator_info() == '{}'

    variables = {}
    assert step.match('1', variables)
    assert variables == {'foo': 1}

    variables = {}
    assert not step.match('x', variables)
    assert not variables
Пример #13
0
def test_converter():
    step = Step("{foo}", converters=dict(foo=Converter(int)))
    assert step.discriminator_info() == "{}"

    variables = {}
    assert step.match("1", variables)
    assert variables == {"foo": 1}

    variables = {}
    assert not step.match("x", variables)
    assert not variables
Пример #14
0
def test_name_step():
    step = Step('foo')
    assert step.s == 'foo'
    assert step.generalized == 'foo'
    assert step.parts == ('foo',)
    assert step.names == []
    assert step.converters == {}
    assert not step.has_variables()
    assert step.match('foo') == (True, {})
    assert step.match('bar') == (False, {})
    assert step.discriminator_info() == 'foo'
Пример #15
0
def test_converter():
    step = Step('{foo}', converters=dict(foo=Converter(int)))
    assert step.discriminator_info() == '{}'

    variables = {}
    assert step.match('1', variables)
    assert variables == {'foo': 1}

    variables = {}
    assert not step.match('x', variables)
    assert not variables
Пример #16
0
def test_name_step():
    step = Step('foo')
    assert step.s == 'foo'
    assert step.generalized == 'foo'
    assert step.parts == ('foo',)
    assert step.names == []
    assert step.converters == {}
    assert not step.has_variables()
    assert step.match('foo') == (True, {})
    assert step.match('bar') == (False, {})
    assert step.discriminator_info() == 'foo'
Пример #17
0
def test_variable_step():
    step = Step("{foo}")
    assert step.s == "{foo}"
    assert step.generalized == "{}"
    assert step.parts == ("", "")
    assert step.names == ["foo"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.discriminator_info() == "{}"

    variables = {}
    assert step.match("bar", variables)
    assert variables == {"foo": "bar"}
Пример #18
0
def test_mixed_step():
    step = Step('a{foo}b')
    assert step.s == 'a{foo}b'
    assert step.generalized == 'a{}b'
    assert step.parts == ('a', 'b')
    assert step.names == ['foo']
    assert step.converters == [str]
    assert step.has_variables()
    assert step.match('abarb') == (True, {'foo': 'bar'})
    assert step.match('ab') == (False, {})
    assert step.match('xbary') == (False, {})
    assert step.match('yabarbx') == (False, {})
    assert step.match('afoo') == (False, {})
    assert step.discriminator_info() == 'a{str}b'
Пример #19
0
def test_mixed_step():
    step = Step("a{foo}b")
    assert step.s == "a{foo}b"
    assert step.generalized == "a{}b"
    assert step.parts == ("a", "b")
    assert step.names == ["foo"]
    assert step.converters == {}
    assert step.has_variables()
    assert step.match("abarb") == (True, {"foo": "bar"})
    assert step.match("ab") == (False, {})
    assert step.match("xbary") == (False, {})
    assert step.match("yabarbx") == (False, {})
    assert step.match("afoo") == (False, {})
    assert step.discriminator_info() == "a{}b"
Пример #20
0
def test_name_step():
    step = Step("foo")
    assert step.s == "foo"
    assert step.generalized == "foo"
    assert step.parts == ("foo", )
    assert step.names == []
    assert step.converters == {}
    assert step.discriminator_info() == "foo"

    assert not step.has_variables()
    variables = {}
    assert step.match("foo", variables)
    assert variables == {}
    assert not step.match("bar", variables)
    assert variables == {}
Пример #21
0
def test_converter():
    step = Step('{foo}', converters=dict(foo=Converter(int)))
    assert step.match('1') == (True, {'foo': 1})
    assert step.match('x') == (False, {})
    assert step.discriminator_info() == '{}'
Пример #22
0
def test_converter():
    step = Step('{foo}', converters=dict(foo=Converter(int)))
    assert step.match('1') == (True, {'foo': 1})
    assert step.match('x') == (False, {})
    assert step.discriminator_info() == '{}'
Пример #23
0
def test_converter():
    step = Step('{foo:int}')
    assert step.match('1') == (True, {'foo': 1})
    assert step.match('x') == (False, {})
    assert step.discriminator_info() == '{int}'
Пример #24
0
def test_converter():
    step = Step("{foo}", converters=dict(foo=Converter(int)))
    assert step.match("1") == (True, {"foo": 1})
    assert step.match("x") == (False, {})
    assert step.discriminator_info() == "{}"