Skip to content

Commit

Permalink
fix: no-op test that doesn't test anything (DEV-2655) (#517)
Browse files Browse the repository at this point in the history
* Fix

* Update test_properties.py

* Refomatted error message
  • Loading branch information
Nora-Olivia-Ammann committed Sep 14, 2023
1 parent 03a59ee commit 76f1db2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/dsp_tools/utils/excel2json/properties.py
Expand Up @@ -260,7 +260,7 @@ def _check_compliance_gui_attributes(df: pd.DataFrame) -> dict[str, pd.Series] |
else:
final_series = no_attribute_check
# The boolean series is returned
return {"wrong gui_attributes": final_series}
return {"gui_attributes": final_series}


def _check_missing_values_in_row_raise_error(df: pd.DataFrame, excelfile: str) -> None:
Expand Down Expand Up @@ -293,7 +293,7 @@ def _check_missing_values_in_row_raise_error(df: pd.DataFrame, excelfile: str) -
if missing_dict:
# Get the row numbers from the boolean series
missing_dict = utl.get_wrong_row_numbers(wrong_row_dict=missing_dict, true_remains=True)
error_str = "\n".join([f" - Column Name: {k} Row Number: {v}" for k, v in missing_dict.items()])
error_str = "\n".join([f"- Column '{k}' Row Number(s): {v}" for k, v in missing_dict.items()])
raise UserError(f"The file '{excelfile}' is missing values in the following rows:\n" f"{error_str}")


Expand Down
59 changes: 32 additions & 27 deletions test/unittests/test_excel2json/test_properties.py
Expand Up @@ -13,7 +13,7 @@
import pytest
from pandas.testing import assert_frame_equal

from dsp_tools.models.exceptions import BaseError, UserError
from dsp_tools.models.exceptions import UserError
from dsp_tools.utils.excel2json import properties as e2j


Expand Down Expand Up @@ -440,13 +440,17 @@ def test__do_property_excel_compliance(self) -> None:
"gui_attributes": ["size: 32, maxlength: 128", pd.NA, pd.NA, pd.NA, pd.NA, pd.NA, pd.NA, pd.NA],
}
)
with self.assertRaises(BaseError) as context:
with self.assertRaisesRegex(
UserError,
r"The file 'Test' is missing values in the following rows\:\n"
r"\- Column 'name' Row Number\(s\)\: \[9\]\n"
r"\- Column 'super' Row Number\(s\)\: \[2, 4, 9\]\n"
r"\- Column 'object' Row Number\(s\)\: \[5, 9\]\n"
r"\- Column 'gui_element' Row Number\(s\)\: \[6, 8, 9\]\n"
r"\- Column 'label' Row Number\(s\)\: \[3, 8\]\n"
r"\- Column 'gui_attributes' Row Number\(s\)\: \[7\]",
):
e2j._do_property_excel_compliance(df=original_df, excelfile="Test")
self.assertEqual(
context,
"The file '{excel_filename}' is missing values in some rows. See below for more information:\n"
"{error_str}",
)

@pytest.mark.filterwarnings("ignore::UserWarning")
def test__rename_deprecated_hlist(self) -> None:
Expand Down Expand Up @@ -480,27 +484,28 @@ def test__get_gui_attribute(self) -> None:
{"gui_attributes": [pd.NA, "max:1.4 / min:1.2", "hlist:", "234345", "hlist: languages,"]}
)
self.assertIsNone(e2j._get_gui_attribute(df_row=original_df.loc[0, :], row_num=2, excelfile="Test"))
with self.assertRaises(UserError) as context:

with self.assertRaisesRegex(
UserError,
r"Row 3 of Excel file Test contains invalid data in column 'gui_attributes'\.\n"
r"The expected format is '\[attribute\: value, attribute\: value\]'\.",
):
e2j._get_gui_attribute(df_row=original_df.loc[1, :], row_num=3, excelfile="Test")
self.assertEqual(
"Row {row_num} of Excel file {excel_filename} contains invalid data in column 'gui_attributes'. "
"The expected format is '[attribute: value, attribute: value]'.",
context,
)
with self.assertRaises(UserError) as context:

with self.assertRaisesRegex(
UserError,
r"Row 4 of Excel file Test contains invalid data in column 'gui_attributes'\.\n"
r"The expected format is '\[attribute\: value, attribute\: value\]'\.",
):
e2j._get_gui_attribute(df_row=original_df.loc[2, :], row_num=4, excelfile="Test")
self.assertEqual(
"Row {row_num} of Excel file {excel_filename} contains invalid data in column 'gui_attributes'. "
"The expected format is '[attribute: value, attribute: value]'.",
context,
)
with self.assertRaises(UserError) as context:

with self.assertRaisesRegex(
UserError,
r"Row 5 of Excel file Test contains invalid data in column 'gui_attributes'\.\n"
r"The expected format is '\[attribute\: value, attribute\: value\]'\.",
):
e2j._get_gui_attribute(df_row=original_df.loc[3, :], row_num=5, excelfile="Test")
self.assertEqual(
"Row {row_num} of Excel file {excel_filename} contains invalid data in column 'gui_attributes'. "
"The expected format is '[attribute: value, attribute: value]'.",
context,
)

expected_dict = {"hlist": "languages"}
returned_dict = e2j._get_gui_attribute(df_row=original_df.loc[4, :], row_num=6, excelfile="Test")
self.assertDictEqual(expected_dict, cast(dict[str, str], returned_dict))
Expand All @@ -520,10 +525,10 @@ def test__check_compliance_gui_attributes(self) -> None:
"gui_attributes": ["Spinbox_attr", pd.NA, pd.NA, pd.NA, pd.NA, pd.NA, "TimeStamp_attr"],
}
)
expected_dict = {"wrong gui_attributes": [False, True, False, False, False, False, True]}
expected_dict = {"gui_attributes": [False, True, False, False, False, False, True]}
returned_dict = e2j._check_compliance_gui_attributes(df=original_df)
returned_dict = cast(dict[str, list[pd.Series]], returned_dict)
casted_dict: dict[str, Any] = {"wrong gui_attributes": list(returned_dict["wrong gui_attributes"])}
casted_dict: dict[str, Any] = {"gui_attributes": list(returned_dict["gui_attributes"])}
self.assertDictEqual(expected_dict, casted_dict)

def test__row2prop(self) -> None:
Expand Down

0 comments on commit 76f1db2

Please sign in to comment.