Пример #1
0
def test_constant_constructor():
    value = Constant('bool', 'FOO', '1')
    assert value

    with assert_raises(TypeError):
        Constant('pkg/Foo', 'FOO', '')

    with assert_raises(NameError):
        Constant('bool', 'FOO BAR', '')

    with assert_raises(ValueError):
        Constant('bool', 'FOO', None)
Пример #2
0
def test_message_specification_constructor():
    msg_spec = MessageSpecification('pkg', 'Foo', [], [])
    assert msg_spec.base_type.pkg_name == 'pkg'
    assert msg_spec.base_type.type == 'Foo'
    assert len(msg_spec.fields) == 0
    assert len(msg_spec.constants) == 0

    with assert_raises(TypeError):
        MessageSpecification('pkg', 'Foo', None, [])
    with assert_raises(TypeError):
        MessageSpecification('pkg', 'Foo', [], None)
    with assert_raises(TypeError):
        MessageSpecification('pkg', 'Foo', ['field'], [])
    with assert_raises(TypeError):
        MessageSpecification('pkg', 'Foo', [], ['constant'])

    field = Field(Type('bool'), 'foo', '1')
    constant = Constant('bool', 'BAR', '1')
    msg_spec = MessageSpecification('pkg', 'Foo', [field], [constant])
    assert len(msg_spec.fields) == 1
    assert msg_spec.fields[0] == field
    assert len(msg_spec.constants) == 1
    assert msg_spec.constants[0] == constant

    with assert_raises(ValueError):
        MessageSpecification('pkg', 'Foo', [field, field], [])
    with assert_raises(ValueError):
        MessageSpecification('pkg', 'Foo', [], [constant, constant])
Пример #3
0
def test_message_specification_methods():
    field = Field(Type('bool'), 'foo', '1')
    constant = Constant('bool', 'BAR', '1')
    msg_spec = MessageSpecification('pkg', 'Foo', [field], [constant])

    assert msg_spec != 'spec'
    assert msg_spec == MessageSpecification('pkg', 'Foo', [field], [constant])
    assert msg_spec != MessageSpecification('pkg', 'Bar', [], [])
    assert msg_spec != MessageSpecification('pkg', 'Foo', [field], [])
    assert msg_spec != MessageSpecification('pkg', 'Foo', [], [constant])
Пример #4
0
def test_constant_methods():
    assert Constant('bool', 'FOO', '1') != 23

    assert Constant('bool', 'FOO', '1') == Constant('bool', 'FOO', '1')
    assert Constant('bool', 'FOO', '1') != Constant('bool', 'FOO', '0')
    assert Constant('bool', 'FOO', '1') != Constant('bool', 'BAR', '1')
    assert Constant('bool', 'FOO', '1') != Constant('byte', 'FOO', '1')

    assert str(Constant('bool', 'FOO', '1')) == 'bool FOO=True'

    assert str(Constant('string', 'FOO', 'foo')) == "string FOO='foo'"