def test_invalid_init_input(self): with pytest.raises(TypeError): DateRange() with pytest.raises(TypeError): DateRange(1, "") with pytest.raises(ValueError): DateRange(end="alice", start="bob")
def test_bad_period(self): with pytest.raises(ValueError): DateRange(start="2019-01-01", end="2018-12-31") with pytest.raises(ValueError): DateRange(start="2019-01-01", end="2019-12-31").end = "2018-12-31" with pytest.raises(ValueError): DateRange(start="2019-01-01", end="2019-12-31").start = "2020-12-31"
def test_equals(self, year_2019_from_strs, year_2019_from_dates, year_2020, year_2020_other): assert year_2019_from_strs == DateRange(end="2019-12-31", start="2019-01-01") assert year_2019_from_dates == DateRange(end="2019-12-31", start="2019-01-01") assert year_2020 != DateRange(end="2019-12-31", start="2019-01-01") assert year_2020 != year_2019_from_dates assert year_2020 != year_2019_from_strs assert year_2020 == year_2020_other
def test_run_saxony(self, calc, region_saxony): totals, _ = calc.run(region_saxony, DateRange(start='2020-02-10', end='2020-02-10'), TimeAggregation.MONTHLY, Pollutant.NO2) assert 0.04 * 4 <= totals.iloc[-1, 0] <= 0.05 * 4 assert 71 <= totals.iloc[-1, 1] <= 72 assert 71 <= totals.iloc[-1, 2] <= 72 totals, _ = calc.run(region_saxony, DateRange(start='2020-02-29', end='2020-03-01'), TimeAggregation.MONTHLY, Pollutant.NO2) assert 0.09 * 4 <= totals.iloc[-1, 0] <= 0.1 * 4 assert 50 <= totals.iloc[-1, 1] <= 51 assert 50 <= totals.iloc[-1, 2] <= 51
def test_run_germany(self, calc, region_germany): totals, _ = calc.run(region_germany, DateRange(start='2018-08-01', end='2018-08-31'), TimeAggregation.MONTHLY, Pollutant.NO2) assert 22.5 * 4 <= totals.iloc[-1, 0] <= 22.6 * 4 assert 3.49 <= totals.iloc[-1, 1] <= 3.5 assert 3.49 <= totals.iloc[-1, 2] <= 3.5
def period_medium(): return DateRange("2019-01-01", "2020-01-31")
def year_2019_from_strs(): return DateRange("2019-01-01", "2019-12-31")
def period_very_short(): return DateRange("2018-10-15", "2018-10-25")
def period_short(): return DateRange("2020-02-01", "2020-02-29")
def august_2018(): return DateRange("2018-08-01", "2018-08-31")
def year_2020_other(): return DateRange("2020-01-01", "2020-12-31")
def period_too_short(): return DateRange("2100-01-01", "2100-01-31")
def period_not_supported_other(): return DateRange("2000-01-01", "9999-12-31")
def period_not_supported(): return DateRange("0001-01-01", "2019-12-31")
def year_2019_from_dates(): return DateRange(date.fromisoformat("2019-01-01"), date.fromisoformat("2019-12-31"))
def period_medium_other(): return DateRange("2019-11-01", "2020-12-31")
def period_medium_third(): return DateRange("2020-01-01", "2020-11-15")
def one_day(): return DateRange("2018-08-01", "2018-08-01")
def period_short_other(): return DateRange("2020-02-01", "2020-02-20")
def future_short(): return DateRange("2030-01-15", "2030-04-30")
def period_long(): return DateRange("2018-10-15", "2020-02-29")
def future_long(): return DateRange("2030-01-15", "2042-12-31")