Skip to content

Commit 691b1a2

Browse files
committed
BUG: Separate multiple tests (39701)
1 parent a4f8cc4 commit 691b1a2

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

pandas/tests/util/test_show_versions.py

+52-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import pytest
66

7-
from pandas.util._print_versions import _get_dependency_info, _get_sys_info
7+
from pandas.util._print_versions import (
8+
_get_dependency_info,
9+
_get_sys_info,
10+
)
811

912
import pandas as pd
1013

@@ -30,56 +33,67 @@
3033
"ignore:Distutils:UserWarning"
3134
)
3235
@pytest.mark.filterwarnings("ignore:Setuptools is replacing distutils:UserWarning")
33-
@pytest.mark.parametrize("as_json", [True, False, "test_output.json"])
34-
def test_show_versions(capsys, as_json, tmpdir):
35-
# gh-32041
36-
if isinstance(as_json, str):
37-
as_json = os.path.join(tmpdir, as_json)
36+
def test_show_versions(tmpdir):
37+
as_json = os.path.join(tmpdir, "test_output.json")
3838

3939
pd.show_versions(as_json=as_json)
40+
41+
# make sure that the file was created
42+
assert os.path.exists(as_json)
43+
44+
with open(as_json) as fd:
45+
contents = fd.readlines()
46+
str_contents = "".join(contents)
47+
48+
# make sure that there was output to the file
49+
assert str_contents
50+
51+
# check if file output is valid JSON, will raise an exception if not
52+
dict_check = json.loads(str_contents)
53+
54+
# Basic check that each version element is found in output
55+
version_elements = {
56+
"system": _get_sys_info(),
57+
"dependencies": _get_dependency_info(),
58+
}
59+
60+
assert version_elements == dict_check
61+
62+
63+
def test_show_versions_console_json(capsys):
64+
pd.show_versions(as_json=True)
4065
captured = capsys.readouterr()
4166
result = captured.out
4267

43-
# check header for non-JSON console output
44-
if as_json is False:
45-
assert "INSTALLED VERSIONS" in result
46-
47-
# check full commit hash
48-
assert re.search(r"commit\s*:\s[0-9a-f]{40}\n", result)
68+
# check valid json is printed to the console if as_json is True
69+
dict_check = json.loads(result)
4970

50-
# check required dependency
51-
# 2020-12-09 npdev has "dirty" in the tag
52-
assert re.search(r"numpy\s*:\s([0-9\.\+a-g\_]|dev)+(dirty)?\n", result)
71+
# Basic check that each version element is found in output
72+
version_elements = {
73+
"system": _get_sys_info(),
74+
"dependencies": _get_dependency_info(),
75+
}
5376

54-
# check optional dependency
55-
assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result)
77+
assert version_elements == dict_check
5678

57-
# Dictionary-based asserts
58-
else:
59-
# check valid json is printed to the console if as_json is True
60-
if as_json is True:
61-
dict_check = json.loads(result)
62-
elif isinstance(as_json, str):
63-
# make sure that the file was created
64-
assert os.path.exists(as_json)
6579

66-
with open(as_json) as fd:
67-
contents = fd.readlines()
68-
str_contents = "".join(contents)
80+
def test_show_versions_console(capsys):
81+
# gh-32041
82+
pd.show_versions(as_json=False)
83+
captured = capsys.readouterr()
84+
result = captured.out
6985

70-
# make sure that there was output to the file
71-
assert str_contents
86+
assert "INSTALLED VERSIONS" in result
7287

73-
# check if file output is valid JSON
74-
dict_check = json.loads(str_contents)
88+
# check full commit hash
89+
assert re.search(r"commit\s*:\s[0-9a-f]{40}\n", result)
7590

76-
# Basic check that each version element is found in output
77-
version_elements = {
78-
"system": _get_sys_info(),
79-
"dependencies": _get_dependency_info(),
80-
}
91+
# check required dependency
92+
# 2020-12-09 npdev has "dirty" in the tag
93+
assert re.search(r"numpy\s*:\s([0-9\.\+a-g\_]|dev)+(dirty)?\n", result)
8194

82-
assert version_elements == dict_check
95+
# check optional dependency
96+
assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result)
8397

8498

8599
def test_json_output_match(capsys, tmpdir):

0 commit comments

Comments
 (0)