From 1d63623dfca96e924345cbe6cf477d9b093e1489 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Sun, 31 Jan 2021 21:55:32 +0100 Subject: [PATCH] Add `Forecast.__repr__()` --- src/urban_meal_delivery/db/forecasts.py | 10 ++++++++++ tests/db/test_forecasts.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/urban_meal_delivery/db/forecasts.py b/src/urban_meal_delivery/db/forecasts.py index f9ebc44..352320e 100644 --- a/src/urban_meal_delivery/db/forecasts.py +++ b/src/urban_meal_delivery/db/forecasts.py @@ -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, + ) diff --git a/tests/db/test_forecasts.py b/tests/db/test_forecasts.py index d6780df..8cf9703 100644 --- a/tests/db/test_forecasts.py +++ b/tests/db/test_forecasts.py @@ -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'' # noqa:E501 + ) + @pytest.mark.db @pytest.mark.no_cover