|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 |
|
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 | +) |
8 | 11 |
|
9 | 12 | import pandas as pd
|
10 | 13 |
|
|
30 | 33 | "ignore:Distutils:UserWarning"
|
31 | 34 | )
|
32 | 35 | @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") |
38 | 38 |
|
39 | 39 | 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) |
40 | 65 | captured = capsys.readouterr()
|
41 | 66 | result = captured.out
|
42 | 67 |
|
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) |
49 | 70 |
|
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 | + } |
53 | 76 |
|
54 |
| - # check optional dependency |
55 |
| - assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result) |
| 77 | + assert version_elements == dict_check |
56 | 78 |
|
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) |
65 | 79 |
|
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 |
69 | 85 |
|
70 |
| - # make sure that there was output to the file |
71 |
| - assert str_contents |
| 86 | + assert "INSTALLED VERSIONS" in result |
72 | 87 |
|
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) |
75 | 90 |
|
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) |
81 | 94 |
|
82 |
| - assert version_elements == dict_check |
| 95 | + # check optional dependency |
| 96 | + assert re.search(r"pyarrow\s*:\s([0-9\.]+|None)\n", result) |
83 | 97 |
|
84 | 98 |
|
85 | 99 | def test_json_output_match(capsys, tmpdir):
|
|
0 commit comments