Skip to content

Commit

Permalink
Merge pull request #372 from Deltares/fix/315-spyder-freezes-upon-pri…
Browse files Browse the repository at this point in the history
…nt-of-forcingmodel

fix: Fix freeze when printing a ForcingModel with multiple [forcing] blocks by omitting the datablocks.
  • Loading branch information
tim-vd-aardweg authored Oct 14, 2022
2 parents 01537e1 + b4d98f2 commit 426c7cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hydrolib/core/io/bc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def _to_section(self) -> Section:
class Config:
extra = Extra.ignore

def __repr__(self) -> str:
data = dict(self)
data["datablock"] = "<omitted>"
representable = BaseModel.construct(**data)
return str(representable)


class TimeSeries(ForcingBase):
"""Subclass for a .bc file [Forcing] block with timeseries data."""
Expand Down
17 changes: 17 additions & 0 deletions tests/io/test_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ def test_astronomic_values_with_strings_in_datablock_are_parsed_correctly(
f"No validation error should be raised when creating an {cls.__name__}"
)

def test_representation_is_correct(self):
forcing = ForcingBase(
name="some_name",
function="some_function",
quantityunitpair=[QuantityUnitPair(quantity="some_quantity", unit="some_unit")],
datablock=[[1.2, 2.3]]
)

str_representation_as_single = str(forcing)
str_representation_in_list = str([forcing])

# datablock should be omitted when a `ForcingBase` is represented from within a list
expected_result = "comments=Comments() datablock={0} name='some_name' function='some_function' quantityunitpair=[QuantityUnitPair(quantity='some_quantity', unit='some_unit', vertpositionindex=None)]"
assert str_representation_as_single == expected_result.format("[[1.2, 2.3]]")
assert str_representation_in_list == "[{0}]".format(expected_result.format("'<omitted>'"))



class TestT3D:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 426c7cd

Please sign in to comment.