MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / module_patch

Function module_patch

web/regression/python_test_utils/test_utils.py:1878–1906  ·  view source on GitHub ↗

This is a helper function responsible to import a function inside a module with the same name e.g. user_info module has user_info function in it. :param args: :return:

(*args)

Source from the content-addressed store, hash-verified

1876
1877
1878def module_patch(*args):
1879 """
1880 This is a helper function responsible to import a function inside
1881 a module with the same name
1882
1883 e.g. user_info module has user_info function in it.
1884
1885 :param args:
1886 :return:
1887 """
1888
1889 target = args[0]
1890 components = target.split('.')
1891 from unittest import mock
1892 for i in range(len(components), 0, -1):
1893 try:
1894 # attempt to import the module
1895 imported = importlib.import_module('.'.join(components[:i]))
1896
1897 # module was imported, let's use it in the patch
1898 patch = mock.patch(*args)
1899 patch.getter = lambda imported_module=imported:imported_module
1900 patch.attribute = '.'.join(components[i:])
1901 return patch
1902 except Exception:
1903 pass
1904
1905 # did not find a module, just return the default mock
1906 return mock.patch(*args)
1907
1908
1909def check_extension_exists(cursor, extension_name):

Callers 1

runTestMethod · 0.90

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected