-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_resources.py
54 lines (45 loc) · 2.28 KB
/
test_resources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import warnings
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
from dsp_tools.commands.excel2json.resources import _check_complete_gui_order
class TestCheckCompleteGuiOrder:
def test_column_does_not_exist(self) -> None:
df = pd.DataFrame({"prop": [1, 2, 3]})
expected_df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, 3]})
res = _check_complete_gui_order("class_name", df)
assert_frame_equal(res, expected_df)
def test_na_in_row(self) -> None:
df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, pd.NA]})
expected_msg = (
"In the sheet 'class_name' of the file 'resources.xlsx', "
"some rows in the column 'gui_order' are empty.\n"
"Values have been filled in automatically, "
"so that the gui-order reflects the order of the properties in the file."
)
expected_df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, 3]})
with pytest.warns(Warning, match=expected_msg):
res = _check_complete_gui_order("class_name", df)
assert_frame_equal(res, expected_df)
def test_error(self) -> None:
df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, "a"]})
expected_msg = (
"In the sheet 'class_name' of the file 'resources.xlsx', "
"some rows in the column 'gui_order' contain invalid characters "
"that could not be converted to an integer.\n"
"Values have been filled in automatically, "
"so that the gui-order reflects the order of the properties in the file."
)
expected_df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, 3]})
with pytest.warns(Warning, match=expected_msg):
res = _check_complete_gui_order("class_name", df)
assert_frame_equal(res, expected_df)
def test_good(self) -> None:
df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": ["1", "2", "3"]})
expected_df = pd.DataFrame({"prop": [1, 2, 3], "gui_order": [1, 2, 3]})
with warnings.catch_warnings():
warnings.simplefilter("error")
res = _check_complete_gui_order("class_name", df)
assert_frame_equal(res, expected_df)
if __name__ == "__main__":
pytest.main([__file__])