def test_out_of_range(self): with pytest.raises(ValueError): fiscalyear.FiscalQuarter(2017, 0) with pytest.raises(ValueError): fiscalyear.FiscalQuarter(2017, 5) with pytest.raises(ValueError): fiscalyear.FiscalQuarter(0, 2)
def test_contains(self, a, b, c, f): assert b in c assert a not in f assert fiscalyear.FiscalDateTime(2015, 10, 1, 0, 0, 0) in a assert datetime.datetime(2015, 10, 1, 0, 0, 0) in a assert fiscalyear.FiscalDate(2015, 10, 1) in a assert datetime.date(2015, 10, 1) in a assert b in fiscalyear.FiscalMonth(2016, 1) assert b in fiscalyear.FiscalQuarter(2016, 1) assert b in fiscalyear.FiscalYear(2016) with pytest.raises(TypeError): "hello world" in a
def d(self): return fiscalyear.FiscalQuarter(2016, 1)
def test_wrong_type(self): with pytest.raises(TypeError): fiscalyear.FiscalQuarter(2017.5, 1.2) with pytest.raises(TypeError): fiscalyear.FiscalQuarter("hello", "world")
def test_current(self, mocker): mock_today = mocker.patch.object(fiscalyear.FiscalDate, "today") mock_today.return_value = fiscalyear.FiscalDate(2016, 10, 1) current = fiscalyear.FiscalQuarter.current() assert current == fiscalyear.FiscalQuarter(2017, 1)
def g(self): return fiscalyear.FiscalQuarter("2018", "1")
def e(self): return fiscalyear.FiscalQuarter(2017, 4)
def test_prev_fiscal_quarter(self, a, c): assert a.prev_fiscal_quarter == fiscalyear.FiscalQuarter(2017, 1) assert c.prev_fiscal_quarter == fiscalyear.FiscalQuarter(2017, 4)
def a(self): return fiscalyear.FiscalQuarter(2016, 4)
def test_q4(self, a): assert a.q4 == fiscalyear.FiscalQuarter(2016, 4)
def test_q3(self, a): assert a.q3 == fiscalyear.FiscalQuarter(2016, 3)
def test_q2(self, a): assert a.q2 == fiscalyear.FiscalQuarter(2016, 2)
def test_q1(self, a): assert a.q1 == fiscalyear.FiscalQuarter(2016, 1)
def test_corner_cases(self): # start_day does not exist in all months with fiscalyear.fiscal_calendar(start_month=5, start_day=31): # Non-leap year assert fiscalyear.FiscalQuarter(2019, 1).start.day == 31 assert fiscalyear.FiscalQuarter(2019, 1).end.day == 30 assert fiscalyear.FiscalQuarter(2019, 2).start.day == 31 assert fiscalyear.FiscalQuarter(2019, 2).end.day == 29 assert fiscalyear.FiscalQuarter(2019, 3).start.day == 30 assert fiscalyear.FiscalQuarter(2019, 3).end.day == 27 assert fiscalyear.FiscalQuarter(2019, 4).start.day == 28 assert fiscalyear.FiscalQuarter(2019, 4).end.day == 30 # Leap year assert fiscalyear.FiscalQuarter(2020, 1).start.day == 31 assert fiscalyear.FiscalQuarter(2020, 1).end.day == 30 assert fiscalyear.FiscalQuarter(2020, 2).start.day == 31 assert fiscalyear.FiscalQuarter(2020, 2).end.day == 29 assert fiscalyear.FiscalQuarter(2020, 3).start.day == 30 assert fiscalyear.FiscalQuarter(2020, 3).end.day == 28 assert fiscalyear.FiscalQuarter(2020, 4).start.day == 29 assert fiscalyear.FiscalQuarter(2020, 4).end.day == 30
def test_next_fiscal_quarter(self, a, c): assert a.next_fiscal_quarter == fiscalyear.FiscalQuarter(2017, 3) assert c.next_fiscal_quarter == fiscalyear.FiscalQuarter(2018, 2)
def f(self): return fiscalyear.FiscalQuarter(2017, 1)
def c(self): return fiscalyear.FiscalQuarter(2017, 2)
def g(self): return fiscalyear.FiscalQuarter('2018', '1')