Skip to content

Commit 3dfc16e

Browse files
committed
BUG: Fix broken tests. (39701)
1 parent 1123326 commit 3dfc16e

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

pandas/tests/util/test_show_versions.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import re
4+
from itertools import chain
45

56
import pytest
67

@@ -39,14 +40,9 @@ def test_show_versions(capsys, as_json, tmpdir):
3940
pd.show_versions(as_json=as_json)
4041
captured = capsys.readouterr()
4142
result = captured.out
42-
string_check = result
43-
44-
# check valid json is printed to the console if as_json is True
45-
if as_json is True:
46-
json.loads(result)
4743

4844
# check header for non-JSON console output
49-
elif as_json is False:
45+
if as_json is False:
5046
assert "INSTALLED VERSIONS" in result
5147

5248
# check full commit hash
@@ -59,26 +55,29 @@ def test_show_versions(capsys, as_json, tmpdir):
5955
# check optional dependency
6056
assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result)
6157

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

66-
with open(as_json) as fd:
67-
contents = fd.readlines()
68-
str_contents = "".join(contents)
67+
with open(as_json) as fd:
68+
contents = fd.readlines()
69+
str_contents = "".join(contents)
6970

70-
# make sure that there was output to the file
71-
assert str_contents
71+
# make sure that there was output to the file
72+
assert str_contents
7273

73-
# check if file output is valid JSON
74-
json.loads(str_contents)
74+
# check if file output is valid JSON
75+
dict_check = json.loads(str_contents)
7576

76-
# prepare string for checking for specific keys
77-
string_check = str_contents
77+
# Basic check that each version element is found in output
78+
version_elements = dict(system = _get_sys_info(), dependencies = _get_dependency_info())
7879

79-
# Basic check that each version element is found in output
80-
version_elements = {**_get_sys_info, **_get_dependency_info}
81-
assert all(v in string_check and k in string_check for k, v in version_elements)
80+
assert version_elements == dict_check
8281

8382

8483
def test_json_output_match(capsys, tmpdir):

0 commit comments

Comments
 (0)