diff --git a/pandas/tests/test_optional_dependency.py b/pandas/tests/test_optional_dependency.py index ce527214e55e7..e5ed69b7703b1 100644 --- a/pandas/tests/test_optional_dependency.py +++ b/pandas/tests/test_optional_dependency.py @@ -22,12 +22,12 @@ def test_xlrd_version_fallback(): import_optional_dependency("xlrd") -def test_bad_version(): +def test_bad_version(monkeypatch): name = "fakemodule" module = types.ModuleType(name) module.__version__ = "0.9.0" sys.modules[name] = module - VERSIONS[name] = "1.0.0" + monkeypatch.setitem(VERSIONS, name, "1.0.0") match = "Pandas requires .*1.0.0.* of .fakemodule.*'0.9.0'" with pytest.raises(ImportError, match=match): @@ -42,11 +42,11 @@ def test_bad_version(): assert result is module -def test_no_version_raises(): +def test_no_version_raises(monkeypatch): name = "fakemodule" module = types.ModuleType(name) sys.modules[name] = module - VERSIONS[name] = "1.0.0" + monkeypatch.setitem(VERSIONS, name, "1.0.0") with pytest.raises(ImportError, match="Can't determine .* fakemodule"): import_optional_dependency(name) diff --git a/pandas/tests/util/test_show_versions.py b/pandas/tests/util/test_show_versions.py new file mode 100644 index 0000000000000..0d2c81c4ea6c7 --- /dev/null +++ b/pandas/tests/util/test_show_versions.py @@ -0,0 +1,22 @@ +import re + +import pandas as pd + + +def test_show_versions(capsys): + # gh-32041 + pd.show_versions() + captured = capsys.readouterr() + result = captured.out + + # check header + assert "INSTALLED VERSIONS" in result + + # check full commit hash + assert re.search(r"commit\s*:\s[0-9a-f]{40}\n", result) + + # check required dependency + assert re.search(r"numpy\s*:\s([0-9\.\+a-f]|dev)+\n", result) + + # check optional dependency + assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result) diff --git a/pandas/util/_print_versions.py b/pandas/util/_print_versions.py index fdfa436ce6536..99b2b9e9f5f6e 100644 --- a/pandas/util/_print_versions.py +++ b/pandas/util/_print_versions.py @@ -118,10 +118,10 @@ def show_versions(as_json=False): print("\nINSTALLED VERSIONS") print("------------------") for k, stat in sys_info: - print(f"{{k:<{maxlen}}}: {{stat}}") + print(f"{k:<{maxlen}}: {stat}") print("") for k, stat in deps_blob: - print(f"{{k:<{maxlen}}}: {{stat}}") + print(f"{k:<{maxlen}}: {stat}") def main() -> int: