Add Forecast.__repr__()

This commit is contained in:
Alexander Hess 2021-01-31 21:55:32 +01:00
parent 47ef1f8759
commit 1d63623dfc
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
2 changed files with 19 additions and 0 deletions

View file

@ -123,3 +123,13 @@ class Forecast(meta.Base):
# Relationships
pixel = orm.relationship('Pixel', back_populates='forecasts')
def __repr__(self) -> str:
"""Non-literal text representation."""
return '<{cls}: {prediction} for pixel ({n_x}|{n_y}) at {start_at}>'.format(
cls=self.__class__.__name__,
prediction=self.prediction,
n_x=self.pixel.n_x,
n_y=self.pixel.n_y,
start_at=self.start_at,
)

View file

@ -34,6 +34,15 @@ class TestSpecialMethods:
"""Test instantiation of a new `Forecast` object."""
assert forecast is not None
def test_text_representation(self, forecast):
"""`Forecast` has a non-literal text representation."""
result = repr(forecast)
assert (
result
== f'<Forecast: {forecast.prediction} for pixel ({forecast.pixel.n_x}|{forecast.pixel.n_y}) at {forecast.start_at}>' # noqa:E501
)
@pytest.mark.db
@pytest.mark.no_cover