Esempio n. 1
0
def test_msg2dict(app):
    app.name = 'v-name'
    app.msg = 'v-msg'
    ret = msg2dict(app, ['name', 'msg', 'tz'])
    assert ret == {'name': 'v-name', 'msg': 'v-msg', 'tz': 'Asia/Shanghai'}

    request = helloworld_pb2.HelloRequest(name="value")
    ret = msg2dict(request)
    assert ret == {"name": "value"}
Esempio n. 2
0
def test_msg2dict(app):
    request = helloworld_pb2.HelloRequest(name="value")
    ret = msg2dict(request)
    assert ret == {"name": "value"}

    pb = sample_pb2.MessageOfTypes()
    pb.i32 = 666
    pb.flot = 3.14
    pb.bol = True
    pb.nested.req = "hahahaa"
    pb.str_repeated.append("dhueife")
    pb.str_repeated.append("fhrvrjvnj")

    pb.simpleMap['s1'] = 3.1415
    pb.simpleMap['s2'] = 4.1235
    res = msg2dict(pb)
    assert res['bol'] is True
    assert round(res['flot'], 2) == 3.14
    assert res['nested'] == {"req": "hahahaa"}
    assert res["str_repeated"] == ["dhueife", "fhrvrjvnj"]
    assert round(res["simpleMap"]['s1'], 4) == 3.1415

    # test including_default_value_fields
    res = msg2dict(pb, including_default_value_fields=True)
    assert res['i64'] == 0
    assert res['strng'] == ""

    # test user_enum_label
    pb.enm = 2
    res = msg2dict(pb)
    assert res['enm'] == 2
    res = msg2dict(pb, use_enum_labels=True)
    assert res['enm'] == "C"

    # test keys
    res = msg2dict(pb, keys=['bol', 'i32'])
    assert res == {"bol": True, "i32": 666}
Esempio n. 3
0
 def stream_generator():
     for i in range(5):
         yield helloworld_pb2.HelloRequest(name=str(i))