Add Forecast.__repr__()
This commit is contained in:
parent
47ef1f8759
commit
1d63623dfc
2 changed files with 19 additions and 0 deletions
|
@ -123,3 +123,13 @@ class Forecast(meta.Base):
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
pixel = orm.relationship('Pixel', back_populates='forecasts')
|
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,
|
||||||
|
)
|
||||||
|
|
|
@ -34,6 +34,15 @@ class TestSpecialMethods:
|
||||||
"""Test instantiation of a new `Forecast` object."""
|
"""Test instantiation of a new `Forecast` object."""
|
||||||
assert forecast is not None
|
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.db
|
||||||
@pytest.mark.no_cover
|
@pytest.mark.no_cover
|
||||||
|
|
Loading…
Reference in a new issue