diff --git a/flexmeasures/utils/tests/test_time_utils.py b/flexmeasures/utils/tests/test_time_utils.py index f14d0a20f..0c15d68fd 100644 --- a/flexmeasures/utils/tests/test_time_utils.py +++ b/flexmeasures/utils/tests/test_time_utils.py @@ -12,11 +12,25 @@ @pytest.mark.parametrize( "dt_tz,now,server_tz,delta_in_h,exp_result", + # there can be two results depending of today's date, due to humanize. + # Monekypatching was too hard. [ (None, datetime.utcnow(), "UTC", 3, "3 hours ago"), - (None, datetime(2021, 5, 17, 3), "Europe/Amsterdam", 48, "May 15"), + ( + None, + datetime(2021, 5, 17, 3), + "Europe/Amsterdam", + 48, + ("May 15", "May 15 2021"), + ), ("Asia/Seoul", "server_now", "Europe/Amsterdam", 1, "an hour ago"), - ("UTC", datetime(2021, 5, 17, 3), "Asia/Seoul", 24 * 7, "May 10"), + ( + "UTC", + datetime(2021, 5, 17, 3), + "Asia/Seoul", + 24 * 7, + ("May 10", "May 10 2021"), + ), ("UTC", datetime(2021, 5, 17, 3), "Asia/Seoul", None, "never"), ], ) @@ -31,17 +45,19 @@ def test_naturalized_datetime_str( ): monkeypatch.setitem(app.config, "FLEXMEASURES_TIMEZONE", server_tz) if now == "server_now": - now = server_now() # done this way as it needs app context + now = server_now() # done this way as it needs (patched) app context if now.tzinfo is None: - now.replace(tzinfo=pytz.utc) # assuming UTC + now = now.replace(tzinfo=pytz.utc) # assuming UTC if delta_in_h is not None: h_ago = now - timedelta(hours=delta_in_h) if dt_tz is not None: h_ago = h_ago.astimezone(pytz.timezone(dt_tz)) else: h_ago = None - print(h_ago) - assert naturalized_datetime_str(h_ago, now=now) == exp_result + if isinstance(exp_result, tuple): + assert naturalized_datetime_str(h_ago, now=now) in exp_result + else: + assert naturalized_datetime_str(h_ago, now=now) == exp_result @pytest.mark.parametrize(