Exemplo n.º 1
0
def test_variable_node_more_specific_first():
    node = Node()
    xy_node = node.add(Step('x{x}y'))
    xay_node = node.add(Step('xa{x}y'))
    ay_node = node.add(Step('a{x}y'))
    assert node.get('xwhaty') == (xy_node, {'x': 'what'})
    assert node.get('xawhaty') == (xay_node, {'x': 'what'})
    assert node.get('awhaty') == (ay_node, {'x': 'what'})
Exemplo n.º 2
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{}"
Exemplo n.º 3
0
def test_steps_the_same():
    step1 = Step('{foo}')
    step2 = Step('{foo}')
    assert step1 == step2
    assert not step1 != step2
    assert not step1 < step2
    assert not step1 > step2
    assert step1 >= step2
    assert step1 <= step2
Exemplo n.º 4
0
def test_step_different():
    step1 = Step('{foo}')
    step2 = Step('bar')
    assert step1 != step2
    assert not step1 == step2
    assert not step1 < step2
    assert step1 > step2
    assert step1 >= step2
    assert not step1 <= step2
Exemplo n.º 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{}'
Exemplo n.º 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{}'
Exemplo n.º 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{}"
Exemplo n.º 8
0
def test_step_different():
    step1 = Step("{foo}")
    step2 = Step("bar")
    assert step1 != step2
    assert not step1 == step2
    assert not step1 < step2
    assert step1 > step2
    assert step1 >= step2
    assert not step1 <= step2
Exemplo n.º 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() == "{}"
Exemplo n.º 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() == '{}'
Exemplo n.º 11
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() == '{}'
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo n.º 15
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'
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
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'
Exemplo n.º 19
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"
Exemplo n.º 20
0
def test_variable_node_optional_colon():
    node = Node()
    x_node = node.add(Step('{x}'))
    xy_node = node.add(Step('{x}:{y}'))

    variables = {}
    assert node.resolve('a', variables) is x_node
    assert variables == {'x': 'a'}

    variables = {}
    assert node.resolve('a:b', variables) is xy_node
    assert variables == {'x': 'a', 'y': 'b'}
Exemplo n.º 21
0
def test_variable_node_optional_colon():
    node = Node()
    x_node = node.add(Step("{x}"))
    xy_node = node.add(Step("{x}:{y}"))

    variables = {}
    assert node.resolve("a", variables) is x_node
    assert variables == {"x": "a"}

    variables = {}
    assert node.resolve("a:b", variables) is xy_node
    assert variables == {"x": "a", "y": "b"}
Exemplo n.º 22
0
def test_variable_node_specific_first():
    node = Node()
    x_node = node.add(Step("{x}"))

    prefix_node = node.add(Step("prefix{x}"))

    variables = {}
    assert node.resolve("what", variables) is x_node
    assert variables == {"x": "what"}

    variables = {}
    assert node.resolve("prefixwhat", variables) is prefix_node
    assert variables == {"x": "what"}
Exemplo n.º 23
0
def test_variable_node_specific_first():
    node = Node()
    x_node = node.add(Step('{x}'))

    prefix_node = node.add(Step('prefix{x}'))

    variables = {}
    assert node.resolve('what', variables) is x_node
    assert variables == {'x': 'what'}

    variables = {}
    assert node.resolve('prefixwhat', variables) is prefix_node
    assert variables == {'x': 'what'}
Exemplo n.º 24
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"}
Exemplo n.º 25
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
Exemplo n.º 26
0
def test_variable_node_more_specific_first():
    node = Node()
    xy_node = node.add(Step("x{x}y"))
    xay_node = node.add(Step("xa{x}y"))
    ay_node = node.add(Step("a{x}y"))

    variables = {}
    assert node.resolve("xwhaty", variables) is xy_node
    assert variables == {"x": "what"}

    variables = {}
    assert node.resolve("xawhaty", variables) is xay_node
    assert variables == {"x": "what"}

    variables = {}
    assert node.resolve("awhaty", variables) is ay_node
    assert variables == {"x": "what"}
Exemplo n.º 27
0
def test_variable_node_more_specific_first():
    node = Node()
    xy_node = node.add(Step('x{x}y'))
    xay_node = node.add(Step('xa{x}y'))
    ay_node = node.add(Step('a{x}y'))

    variables = {}
    assert node.resolve('xwhaty', variables) is xy_node
    assert variables == {'x': 'what'}

    variables = {}
    assert node.resolve('xawhaty', variables) is xay_node
    assert variables == {'x': 'what'}

    variables = {}
    assert node.resolve('awhaty', variables) is ay_node
    assert variables == {'x': 'what'}
Exemplo n.º 28
0
def test_name_node():
    node = Node()
    step_node = node.add(Step('foo'))
    variables = {}
    assert node.resolve('foo', variables) is step_node
    assert not variables

    assert node.resolve('bar', variables) is None
    assert not variables
Exemplo n.º 29
0
def test_name_node():
    node = Node()
    step_node = node.add(Step("foo"))
    variables = {}
    assert node.resolve("foo", variables) is step_node
    assert not variables

    assert node.resolve("bar", variables) is None
    assert not variables
Exemplo n.º 30
0
def test_variable_node():
    node = Node()

    step_node = node.add(Step("{x}"))
    variables = {}
    assert node.resolve("foo", variables) is step_node
    assert variables == {"x": "foo"}

    variables = {}
    assert node.resolve("bar", variables) is step_node
    assert variables == {"x": "bar"}
Exemplo n.º 31
0
def test_variable_node():
    node = Node()

    step_node = node.add(Step('{x}'))
    variables = {}
    assert node.resolve('foo', variables) is step_node
    assert variables == {'x': 'foo'}

    variables = {}
    assert node.resolve('bar', variables) is step_node
    assert variables == {'x': 'bar'}
Exemplo n.º 32
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'
Exemplo n.º 33
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"
Exemplo n.º 34
0
def test_mixed_node():
    node = Node()
    step_node = node.add(Step("prefix{x}postfix"))

    variables = {}
    assert node.resolve("prefixfoopostfix", variables) is step_node
    assert variables == {"x": "foo"}

    variables = {}
    assert node.resolve("prefixbarpostfix", variables) is step_node
    assert variables == {"x": "bar"}

    variables = {}
    assert node.resolve("prefixwhat", variables) is None
    assert variables == {}
Exemplo n.º 35
0
def test_mixed_node():
    node = Node()
    step_node = node.add(Step('prefix{x}postfix'))

    variables = {}
    assert node.resolve('prefixfoopostfix', variables) is step_node
    assert variables == {'x': 'foo'}

    variables = {}
    assert node.resolve('prefixbarpostfix', variables) is step_node
    assert variables == {'x': 'bar'}

    variables = {}
    assert node.resolve('prefixwhat', variables) is None
    assert variables == {}
Exemplo n.º 36
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 == {}
Exemplo n.º 37
0
def test_illegal_consecutive_variables():
    with pytest.raises(TrajectError):
        Step('{a}{b}')
Exemplo n.º 38
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}'
Exemplo n.º 39
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() == "{}"
Exemplo n.º 40
0
def test_illegal_identifier():
    with pytest.raises(TrajectError):
        Step('{1}')
Exemplo n.º 41
0
def test_unknown_converter():
    with pytest.raises(TrajectError):
        Step('{foo:blurb}')
Exemplo n.º 42
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() == '{}'
Exemplo n.º 43
0
def test_illegal_variable():
    with pytest.raises(TrajectError):
        Step('{a:int:int}')