1
1
import json
2
2
import os
3
3
import re
4
+ from itertools import chain
4
5
5
6
import pytest
6
7
@@ -39,14 +40,9 @@ def test_show_versions(capsys, as_json, tmpdir):
39
40
pd .show_versions (as_json = as_json )
40
41
captured = capsys .readouterr ()
41
42
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 )
47
43
48
44
# check header for non-JSON console output
49
- elif as_json is False :
45
+ if as_json is False :
50
46
assert "INSTALLED VERSIONS" in result
51
47
52
48
# check full commit hash
@@ -59,26 +55,29 @@ def test_show_versions(capsys, as_json, tmpdir):
59
55
# check optional dependency
60
56
assert re .search (r"pyarrow\s*:\s([0-9\.]+|None)\n" , result )
61
57
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 )
65
66
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 )
69
70
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
72
73
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 )
75
76
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 ())
78
79
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
82
81
83
82
84
83
def test_json_output_match (capsys , tmpdir ):
0 commit comments