Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…834)
- Loading branch information
1 parent
7f98945
commit b55224a
Showing
3 changed files
with
127 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...sts/commands/excel2json/test_resources.py → ...s/excel2json/test_resources_high_level.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
"""unit tests for excel to resource""" | ||
|
||
import re | ||
import unittest | ||
|
||
|
61 changes: 61 additions & 0 deletions
61
test/unittests/commands/excel2json/test_resources_low_level.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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_msg = ( | ||
"In the sheet 'class_name' of the file 'resources.xlsx', " | ||
"the column 'gui_order' does not exist.\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_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__]) |