def __getattr__(name): # Requires Python >= 3.7 """Lazily perform imports and class definitions on first demand.""" if name == '__all__': converted = (util.convert_snake_case_to_upper_case(key) for key in _lazy_name_to_package_map) all_names = sorted(converted) globals()['__all__'] = all_names return all_names elif name.endswith('Transport'): module = __getattr__(util.convert_upper_case_to_snake_case(name)) sub_mod_class = getattr(module, name) klass = type(name, (sub_mod_class, ), {'__doc__': sub_mod_class.__doc__}) globals()[name] = klass return klass elif name.endswith('ServiceClient'): module = __getattr__(util.convert_upper_case_to_snake_case(name)) enums = __getattr__('enums') sub_mod_class = getattr(module, name) klass = type(name, (sub_mod_class, ), { '__doc__': sub_mod_class.__doc__, 'enums': enums }) globals()[name] = klass return klass elif name in _lazy_name_to_package_map: module = importlib.import_module( f'{_lazy_name_to_package_map[name]}.{name}') globals()[name] = module return module else: raise AttributeError(f'unknown sub-module {name!r}.')
def __getattr__(name): # Requires Python >= 3.7 """Lazily perform imports and class definitions on first demand.""" if name == "__all__": converted = (util.convert_snake_case_to_upper_case(key) for key in _lazy_name_to_package_map) all_names = sorted(converted) globals()["__all__"] = all_names return all_names elif name.endswith("Transport"): module = __getattr__(util.convert_upper_case_to_snake_case(name)) sub_mod_class = getattr(module, name) klass = type(name, (sub_mod_class, ), {"__doc__": sub_mod_class.__doc__}) globals()[name] = klass return klass elif name.endswith("ServiceClient"): module = __getattr__(util.convert_upper_case_to_snake_case(name)) enums = __getattr__("enums") sub_mod_class = getattr(module, name) klass = type( name, (sub_mod_class, ), { "__doc__": sub_mod_class.__doc__, "enums": enums }, ) globals()[name] = klass return klass elif name == "enums": path = "google.ads.google_ads.v6.services.enums" module = importlib.import_module(path) globals()[name] = module return module elif name == "types": path = "google.ads.google_ads.v6.types" module = importlib.import_module(path) globals()[name] = module return module elif name in _lazy_name_to_package_map: module = importlib.import_module( f"{_lazy_name_to_package_map[name]}.{name}") globals()[name] = module return module else: raise AttributeError(f"unknown sub-module {name!r}.")
def test_convert_upper_case_to_snake_case(self): string = "GoogleAdsServiceClientTransport" expected = "google_ads_service_client_transport" result = util.convert_upper_case_to_snake_case(string) self.assertEqual(result, expected)