def test_describe_type(): roots = [ pkg_resources.resource_filename(__name__, './resources') ] test_proto = pkg_resources.resource_filename( __name__, './resources/deeply_nested_def.proto', ) parser = DefParser(roots) parser.parse(test_proto) raw = { 'a': 'foo', 'b': 'bar', 'j': 1234567, 'k': True, 'd': { 'a': { 'a': 2, 'b': 'spam', 'c': 'egg', 'd': False, }, 'b': { 'a': 0, 'b': 'ham-bar', 'c': 'bar-ham', 'd': True, }, 'c': False, }, 'e': { 'b': 1, 'c': { 'a': 'foo-spam', 'b': 'spam-foo', }, }, 'f': { 'd': 1, }, 'g': { 'b': 0, 'c': { 'a': -123456, }, }, } values = {} for k, v in parser.describe_type('TopLevel').items(): print('k: {}, v: {}'.format(k, v)) values[k] = v(raw.get(k, None)) ptype = parser.find_definition('TopLevel') result = ptype(**values) print(result)
def test_rpc(): roots = [pkg_resources.resource_filename(__name__, './resources')] test_proto = pkg_resources.resource_filename( __name__, './resources/test_rpc.proto', ) parser = DefParser(roots) parser.parse(test_proto)
def test_nested_otpions(): roots = [pkg_resources.resource_filename(__name__, './resources')] test_proto = pkg_resources.resource_filename( __name__, './resources/test_nested_options.proto', ) parser = DefParser(roots) parser.parse(test_proto)
def test_double_line_comment(): roots = [pkg_resources.resource_filename(__name__, './resources')] test_proto = pkg_resources.resource_filename( __name__, './resources/test_double_line_comment.proto', ) parser = DefParser(roots) parser.parse(test_proto)
def test_imported_oneof(): roots = [ pkg_resources.resource_filename(__name__, './'), pkg_resources.resource_filename(__name__, './resources') ] test_proto = pkg_resources.resource_filename( __name__, './resources/test_imported_oneof.proto', ) parser = DefParser(roots) parser.parse(test_proto) found = False for f, p in parser.files(): if b'test_imported_oneof.proto' in f: found = True assert found
def test_deep_nesting(): roots = [pkg_resources.resource_filename(__name__, './resources')] test_proto = pkg_resources.resource_filename( __name__, './resources/deeply_nested_def.proto', ) parser = DefParser(roots) parser.parse(test_proto) # 10 messages + 7 enums defcount = 10 + 7 actual_defcount = 0 for k, v in parser.definitions(): print('def: {} => {}'.format(k, v)) actual_defcount += 1 assert defcount == actual_defcount
def test_iterate_defs(): roots = [ pkg_resources.resource_filename(__name__, './resources'), pkg_resources.resource_filename(__name__, '.') ] test_proto = pkg_resources.resource_filename( __name__, './resources/test_imported_oneof.proto', ) parser = DefParser(roots) parser.parse(test_proto) passed = False for k, v in parser.definitions(): if k == b'resources.Test.EmbeddedMessage': passed = True assert passed
def test_imported_oneof(): roots = [ pkg_resources.resource_filename(__name__, './'), pkg_resources.resource_filename(__name__, './resources') ] test_proto = pkg_resources.resource_filename( __name__, './resources/test_imported_oneof.proto', ) parser = DefParser(roots) parser.parse(test_proto) fields = [] for f, p in parser.files.items(): if b'test_imported_oneof.proto' in f: for r in p: if p[0] == 0: # message fields += p[2:] assert all( field[1].startswith(b'resources.') for field in fields if not type(field[1]) is list )