Skip to content

Commit 835c0c0

Browse files
Addressing PR comments and refactoring code
1 parent 10c2d18 commit 835c0c0

File tree

3 files changed

+530
-479
lines changed

3 files changed

+530
-479
lines changed

pages/datasets/investigation_dataset_page.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -713,33 +713,49 @@ def label_matches(idx: int) -> bool:
713713

714714
def check_visibility_of_drug_type(
715715
self, drug_type: str, drug_number: int, visible: bool
716-
) -> bool:
716+
) -> None:
717717
"""
718718
Checks the visibility of the drug type input cell.
719719
Args:
720720
drug_type (str): The drug type to check
721721
drug_number (int): The number of the drug type cell to check.
722722
expected_text (str): The expected text content of the cell.
723-
Returns:
724-
bool: True if the visibility matches the expectation, False otherwise.
723+
Raises:
724+
AssertionError: If the visibility does not match the expectation.
725725
"""
726726
locator = self.get_drug_type_locator(drug_type, drug_number)
727-
return locator.is_visible() == visible
727+
actual_visibility = locator.is_visible()
728+
assert actual_visibility == visible, (
729+
f"The {ordinal(drug_number)} {drug_type} drug type input cell visibility was {actual_visibility}, "
730+
f"expected {visible}"
731+
)
732+
logging.info(
733+
f"The {ordinal(drug_number)} {drug_type} drug type input cell is "
734+
f"{'visible' if actual_visibility else 'not visible'} as expected"
735+
)
728736

729737
def check_visibility_of_drug_dose(
730738
self, drug_type: str, drug_number: int, visible: bool
731-
) -> bool:
739+
) -> None:
732740
"""
733-
Checks the visibility of the drug dose input cell.
741+
Asserts the visibility of the drug dose input cell and logs the result.
734742
Args:
735-
drug_type (str): The drug type to check
743+
drug_type (str): The drug type to check.
736744
drug_number (int): The number of the drug dose cell to check.
737745
visible (bool): True if the field should be visible, False if it should not.
738-
Returns:
739-
bool: True if the visibility matches the expectation, False otherwise.
746+
Raises:
747+
AssertionError: If the visibility does not match the expectation.
740748
"""
741749
locator = self.get_drug_dose_locator(drug_type, drug_number)
742-
return locator.is_visible() == visible
750+
actual_visibility = locator.is_visible()
751+
assert actual_visibility == visible, (
752+
f"The {ordinal(drug_number)} {drug_type} drug dose input cell visibility was {actual_visibility}, "
753+
f"expected {visible}"
754+
)
755+
logging.info(
756+
f"The {ordinal(drug_number)} {drug_type} drug dose input cell is "
757+
f"{'visible' if actual_visibility else 'not visible'} as expected"
758+
)
743759

744760
def assert_drug_type_text(
745761
self, drug_type: str, drug_number: int, expected_text: str
@@ -1444,3 +1460,14 @@ def to_enum_name_or_value(val: Any) -> Union[str, Any]:
14441460

14451461
# Fallback: return unchanged
14461462
return val
1463+
1464+
1465+
def ordinal(n: int) -> str:
1466+
"""
1467+
Converts an integer to its ordinal representation (e.g., 1 -> '1st', 2 -> '2nd').
1468+
"""
1469+
if 10 <= n % 100 <= 20:
1470+
suffix = "th"
1471+
else:
1472+
suffix = {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
1473+
return f"{n}{suffix}"

0 commit comments

Comments
 (0)