def test_data(request): test_case_name = request.param # Reset the internal symbol database so we can import the `Test` message # multiple times. Ugh. sym = symbol_database.Default() sym.pool = DescriptorPool() reference_module_root = os.path.join( *reference_output_package.split("."), test_case_name ) sys.path.append(reference_module_root) yield ( TestData( plugin_module=importlib.import_module( f"{plugin_output_package}.{test_case_name}.{test_case_name}" ), reference_module=lambda: importlib.import_module( f"{reference_output_package}.{test_case_name}.{test_case_name}_pb2" ), json_data=get_test_case_json_data(test_case_name), ) ) sys.path.remove(reference_module_root)
def __init__(self, path, services: Set[str], xfail: Set[str]): _all = set(get_directories(path)) _services = services _messages = _all - services _messages_with_json = { test for test in _messages if get_test_case_json_data(test) } self.all = self.apply_xfail_marks(_all, xfail) self.services = self.apply_xfail_marks(_services, xfail) self.messages = self.apply_xfail_marks(_messages, xfail) self.messages_with_json = self.apply_xfail_marks(_messages_with_json, xfail)
def __init__(self, path, services: Set[str], xfail: Set[str]): _all = set(get_directories(path)) - {"__pycache__"} _services = services _messages = (_all - services) - {"__pycache__"} _messages_with_json = { test for test in _messages if get_test_case_json_data(test) } unknown_xfail_tests = xfail - _all if unknown_xfail_tests: raise Exception( f"Unknown test(s) in config.py: {unknown_xfail_tests}") self.all = self.apply_xfail_marks(_all, xfail) self.services = self.apply_xfail_marks(_services, xfail) self.messages = self.apply_xfail_marks(_messages, xfail) self.messages_with_json = self.apply_xfail_marks( _messages_with_json, xfail)
def test_which_count(): message = Test() message.from_json(get_test_case_json_data("oneof")) assert betterproto.which_one_of(message, "foo") == ("count", 100)
def test_which_name(): message = Test() message.from_json(get_test_case_json_data("oneof", "oneof-name.json")) assert betterproto.which_one_of(message, "foo") == ("name", "foobar")