- Moved the assignment of `phenology_phase` in assemble.py to ensure it is included only for valid days. - Updated the docstring in disease.py to clarify the rounding behavior of decimal values, enhancing the understanding of the formatting logic. - Removed unnecessary checks in the decimal formatting function to streamline the code.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Unit tests for INCUBAZPRIMARIA model_value rounding and labels."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from decimal import Decimal
|
|
|
|
from pipeline.stages.disease import _format_model_value, _incub_label
|
|
|
|
|
|
class FormatModelValueTests(unittest.TestCase):
|
|
def test_long_float_rounds_to_two_decimals(self) -> None:
|
|
self.assertEqual(_format_model_value(40.123456789), "40.12")
|
|
|
|
def test_long_decimal_rounds_to_two_decimals(self) -> None:
|
|
self.assertEqual(_format_model_value(Decimal("40.123456789")), "40.12")
|
|
|
|
def test_trailing_zeros_stripped(self) -> None:
|
|
self.assertEqual(_format_model_value(40.30), "40.3")
|
|
self.assertEqual(_format_model_value(40.0), "40")
|
|
self.assertEqual(_format_model_value(Decimal("40.10")), "40.1")
|
|
|
|
def test_none_and_empty_return_none(self) -> None:
|
|
self.assertIsNone(_format_model_value(None))
|
|
self.assertIsNone(_format_model_value(" "))
|
|
|
|
def test_non_numeric_passthrough(self) -> None:
|
|
self.assertEqual(_format_model_value("n/a"), "n/a")
|
|
|
|
|
|
class IncubLabelTests(unittest.TestCase):
|
|
def test_picks_max_raw_value_then_rounds_suffix(self) -> None:
|
|
self.assertEqual(
|
|
_incub_label([40.12, 40.129, 39.99]),
|
|
"INCUBAZPRIMARIA_40.13",
|
|
)
|
|
|
|
def test_empty_or_non_numeric_falls_back(self) -> None:
|
|
self.assertEqual(_incub_label([]), "INCUBAZPRIMARIA")
|
|
self.assertEqual(_incub_label([None, "n/a"]), "INCUBAZPRIMARIA")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|