Exemplo n.º 1
0
def test_enum():
    scheme = '''yamls://
- name: msg
  id: 10
  enums:
    Enum: {type: int32, options.type: enum, enum: {A: 10, B: 20}}
  fields:
    - {name: f0, type: Enum}
    - {name: f1, type: Enum}
'''
    url = Config.load(f'''yamls://
tll.proto: yaml
name: yaml
dump: scheme
config.0:
  name: msg
  data:
    f0: A
    f1: 20
''')
    url['scheme'] = scheme
    c = Accum(url)
    c.open()
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, 0)]
    m = c.unpack(c.result[0])
    assert m.f0 == m.f0.A
    assert m.f1 == m.f1.B
Exemplo n.º 2
0
def test_simple(t, v):
    if isinstance(v, tuple):
        v, s = v
    else:
        s = str(v)
    scheme = f'''yamls://
- name: msg
  id: 10
  fields:
    - {{name: f0, type: {t} }}
'''
    url = Config.load(f'''yamls://
tll.proto: yaml
name: yaml
dump: scheme
config.0:
  name: msg
''')
    url['scheme'] = scheme
    url['config.0.data.f0'] = s
    c = Accum(url)
    c.open()
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, 0)]
    m = c.unpack(c.result[0])
    assert m.as_dict() == {'f0': v}
Exemplo n.º 3
0
def test_union(data, r):
    scheme = '''yamls://
- name: sub
  fields:
    - {name: s0, type: int8}
- name: msg
  id: 10
  fields:
    - {name: f0, type: union, union: [{name: i8, type: int8}, {name: string, type: string}, {name: sub, type: sub}, {name: array, type: 'int8[4]'}]}
'''
    url = Config.load(f'''yamls://
tll.proto: yaml
name: yaml
dump: scheme
config.0:
  name: msg
  data.f0: %s
''' % data)
    url['scheme'] = scheme
    c = Accum(url)
    c.open()
    if r is None:
        with pytest.raises(TLLError):
            c.process()
        assert c.state == c.State.Error
        return
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, 0)]
    m = c.unpack(c.result[0])
    assert m.as_dict() == {'f0': r}
Exemplo n.º 4
0
def test_many():
    scheme = '''yamls://
- name: msg
  id: 10
  fields:
    - {name: f0, type: int8}
'''
    url = Config.load('''yamls://
tll.proto: yaml
name: yaml
dump: scheme
autoclose: no
config:
  - {name: msg, seq: 0, data.f0: 0}
  - {name: msg, seq: 1, data.f0: 1}
  - {name: msg, seq: 2, data.f0: 2}
  - {name: msg, seq: 3, data.f0: 3}
''')
    url['scheme'] = scheme
    c = Accum(url)
    c.open()
    for i in range(4):
        c.process()
        assert [(m.msgid, m.seq) for m in c.result] == [(10, j)
                                                        for j in range(i + 1)]
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, j) for j in range(4)]
    for i in range(4):
        assert c.unpack(c.result[i]).as_dict() == {'f0': i}
Exemplo n.º 5
0
def test_message():
    scheme = '''yamls://
- name: sub
  fields:
    - {name: s0, type: int8}
- name: msg
  id: 10
  fields:
    - {name: f0, type: sub}
'''
    url = Config.load(f'''yamls://
tll.proto: yaml
name: yaml
dump: scheme
config.0:
  name: msg
  data.f0.s0: 123
''')
    url['scheme'] = scheme
    c = Accum(url)
    c.open()
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, 0)]
    m = c.unpack(c.result[0])
    assert m.as_dict() == {'f0': {'s0': 123}}
Exemplo n.º 6
0
def test_list(t, v):
    scheme = f'''yamls://
- name: msg
  id: 10
  fields:
    - {{name: f0, type: {t} }}
'''
    url = Config.load(f'''yamls://
tll.proto: yaml
name: yaml
dump: scheme
config.0:
  name: msg
  data.f0: {v}
''')
    url['scheme'] = scheme
    c = Accum(url)
    c.open()
    c.process()
    assert [(m.msgid, m.seq) for m in c.result] == [(10, 0)]
    m = c.unpack(c.result[0])
    assert m.as_dict() == {'f0': v}