Skip to content

Commit

Permalink
add test for initializing the TimModel with filepath and `quantit…
Browse files Browse the repository at this point in the history
…ies_names`
  • Loading branch information
MAfarrag committed Jan 17, 2025
1 parent 996661f commit bc9ae67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hydrolib/core/dflowfm/tim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ class TimModel(ParsableFileModel):

quantities_names: Optional[List[str]] = Field(default=None)

def __init__(self, *args, quantities_names: Optional[List[str]] = None, **kwargs):
"""
Custom initializer to handle extra parameters specific to TimModel.
Args:
quantities_names (Optional[List[str]]): Names for the quantities in the timeseries.
*args, **kwargs: Other arguments for the superclass.
"""
super().__init__(*args, **kwargs)
self.quantities_names = quantities_names

@classmethod
def _ext(cls) -> str:
return ".tim"
Expand Down
6 changes: 6 additions & 0 deletions tests/dflowfm/test_tim.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def test_initialization(self):
assert len(model.timeseries) == 0
assert model.as_dataframe().empty

def test_initialize_with_quantities_names(self, input_files_dir: Path):
path = input_files_dir / "tim/single_data_for_timeseries.tim"
model = TimModel(path, quantities_names=["a"])
assert model.quantities_names == ["a"]
assert len(model.timeseries) == 13

def test_as_dataframe(self):
model = TimModel(
timeseries=self.single_data_for_timeseries_floats,
Expand Down

0 comments on commit bc9ae67

Please sign in to comment.