MCPcopy
hub / github.com/pandas-dev/pandas / test_submodule

Function test_submodule

pandas/tests/test_optional_dependency.py:68–90  ·  view source on GitHub ↗
(monkeypatch)

Source from the content-addressed store, hash-verified

66
67
68def test_submodule(monkeypatch):
69 # Create a fake module with a submodule
70 name = "fakemodule"
71 module = types.ModuleType(name)
72 module.__version__ = "0.9.0"
73 sys.modules[name] = module
74 sub_name = "submodule"
75 submodule = types.ModuleType(sub_name)
76 setattr(module, sub_name, submodule)
77 sys.modules[f"{name}.{sub_name}"] = submodule
78 monkeypatch.setitem(VERSIONS, name, "1.0.0")
79
80 match = "Pandas requires .*1.0.0.* of .fakemodule.*'0.9.0'"
81 with pytest.raises(ImportError, match=match):
82 import_optional_dependency("fakemodule.submodule")
83
84 with tm.assert_produces_warning(UserWarning, match=match):
85 result = import_optional_dependency("fakemodule.submodule", errors="warn")
86 assert result is None
87
88 module.__version__ = "1.0.0" # exact match is OK
89 result = import_optional_dependency("fakemodule.submodule")
90 assert result is submodule
91
92
93def test_no_version_raises(monkeypatch):

Callers

nothing calls this directly

Calls 3

setitemMethod · 0.45
raisesMethod · 0.45

Tested by

no test coverage detected