コード例 #1
0
    def test_nested(self):
        assert fiscalyear.START_YEAR == "previous"
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1

        with fiscalyear.fiscal_calendar(start_year="same"):
            assert fiscalyear.START_YEAR == "same"
            assert fiscalyear.START_MONTH == 10
            assert fiscalyear.START_DAY == 1

            with fiscalyear.fiscal_calendar(start_month=4):
                assert fiscalyear.START_YEAR == "same"
                assert fiscalyear.START_MONTH == 4
                assert fiscalyear.START_DAY == 1

                with fiscalyear.fiscal_calendar(start_day=6):
                    assert fiscalyear.START_YEAR == "same"
                    assert fiscalyear.START_MONTH == 4
                    assert fiscalyear.START_DAY == 6

                assert fiscalyear.START_YEAR == "same"
                assert fiscalyear.START_MONTH == 4
                assert fiscalyear.START_DAY == 1

            assert fiscalyear.START_YEAR == "same"
            assert fiscalyear.START_MONTH == 10
            assert fiscalyear.START_DAY == 1

        assert fiscalyear.START_YEAR == "previous"
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1
コード例 #2
0
    def test_end(self, c: FiscalDay) -> None:
        assert c.end == FiscalYear(c.fiscal_year).end

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert c.end == datetime.datetime(2016, 9, 30, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert c.end == datetime.datetime(2017, 4, 5, 23, 59, 59)
コード例 #3
0
    def test_out_of_range(self):
        with pytest.raises(ValueError):
            with fiscalyear.fiscal_calendar(start_month=0):
                pass

        with pytest.raises(ValueError):
            with fiscalyear.fiscal_calendar(start_month=2, start_day=29):
                pass
コード例 #4
0
    def test_end(self, e):
        assert e.end == fiscalyear.FiscalYear(e.fiscal_year).end

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert e.end == datetime.datetime(2016, 9, 30, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert e.end == datetime.datetime(2017, 4, 5, 23, 59, 59)
コード例 #5
0
    def test_fiscal_year(self, a, c):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.fiscal_year == 2017
            assert c.fiscal_year == 2018

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.fiscal_year == 2016
            assert c.fiscal_year == 2017
コード例 #6
0
ファイル: test_fiscalyear.py プロジェクト: Ethrain/fiscalyear
    def test_wrong_type(self):
        with pytest.raises(TypeError):
            with fiscalyear.fiscal_calendar(start_month=6.5):
                pass

        with pytest.raises(TypeError):
            with fiscalyear.fiscal_calendar(start_day='hello world'):
                pass
コード例 #7
0
    def test_end(self, a):
        assert a.end == a.q4.end

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.end == datetime.datetime(2016, 9, 30, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.end == datetime.datetime(2017, 4, 5, 23, 59, 59)
コード例 #8
0
    def test_start(self, a):
        assert a.start == a.q1.start

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.start == datetime.datetime(2015, 10, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.start == datetime.datetime(2016, 4, 6, 0, 0, 0)
コード例 #9
0
    def test_start(self, a, e):
        assert a.start == fiscalyear.FiscalYear(a.fiscal_year).start
        assert e.start == fiscalyear.FiscalDateTime(2016, 9, 30, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.start == datetime.datetime(2015, 10, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.start == datetime.datetime(2016, 4, 6, 0, 0, 0)
コード例 #10
0
    def test_start(self, a: FiscalMonth, c: FiscalMonth) -> None:
        assert a.start == FiscalYear(a.fiscal_year).start
        assert c.start == FiscalDateTime(2016, 9, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.start == datetime.datetime(2015, 10, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.start == datetime.datetime(2016, 4, 6, 0, 0, 0)
            assert FiscalMonth(2016, 12).start == datetime.datetime(
                2017, 3, 6, 0, 0, 0)
コード例 #11
0
    def test_fiscal_periods(self, a, c):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.fiscal_year == 2017
            assert a.fiscal_month == 4
            assert c.fiscal_year == 2018
            assert c.fiscal_month == 2

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.fiscal_year == 2016
            assert a.fiscal_month == 10
            assert c.fiscal_year == 2017
            assert c.fiscal_month == 8
コード例 #12
0
    def test_fiscal_periods(self, a: FiscalDate, b: FiscalDate) -> None:
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert a.fiscal_year == 2017
            assert a.fiscal_month == 4
            assert b.fiscal_year == 2018
            assert b.fiscal_month == 2

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert a.fiscal_year == 2016
            assert a.fiscal_month == 9
            assert b.fiscal_year == 2017
            assert b.fiscal_month == 8
コード例 #13
0
    def test_start_year(self):
        assert fiscalyear.START_YEAR == "previous"

        with fiscalyear.fiscal_calendar(start_year="same"):
            assert fiscalyear.START_YEAR == "same"

        assert fiscalyear.START_YEAR == "previous"
コード例 #14
0
    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
コード例 #15
0
    def test_start_year(self):
        assert fiscalyear.START_YEAR == 'previous'

        with fiscalyear.fiscal_calendar(start_year='same'):
            assert fiscalyear.START_YEAR == 'same'

        assert fiscalyear.START_YEAR == 'previous'
コード例 #16
0
    def test_start_month(self):
        assert fiscalyear.START_MONTH == 10

        with fiscalyear.fiscal_calendar(start_month=4):
            assert fiscalyear.START_MONTH == 4

        assert fiscalyear.START_MONTH == 10
コード例 #17
0
    def test_is_leap(self, a, b, g):
        # default US start_year='previous', start_month=10
        assert isinstance(a.isleap, bool)
        assert isinstance(g.isleap, bool)

        with fiscalyear.fiscal_calendar(start_year="previous", start_month=1):
            assert not a.isleap
            assert b.isleap

        with fiscalyear.fiscal_calendar(start_year="same", start_month=3):
            assert not a.isleap
            assert g.isleap

        with fiscalyear.fiscal_calendar(start_year="same", start_month=1):
            assert a.isleap
            assert not g.isleap
コード例 #18
0
    def test_start_day(self):
        assert fiscalyear.START_DAY == 1

        with fiscalyear.fiscal_calendar(start_day=6):
            assert fiscalyear.START_DAY == 6

        assert fiscalyear.START_DAY == 1
コード例 #19
0
    def test_is_leap(self, a: FiscalYear, b: FiscalYear,
                     e: FiscalYear) -> None:
        # default US start_year='previous', start_month=10
        assert isinstance(a.isleap, bool)
        assert isinstance(e.isleap, bool)

        with fiscalyear.fiscal_calendar(start_year="previous", start_month=1):
            assert not a.isleap
            assert b.isleap

        with fiscalyear.fiscal_calendar(start_year="same", start_month=3):
            assert not a.isleap
            assert e.isleap

        with fiscalyear.fiscal_calendar(start_year="same", start_month=1):
            assert a.isleap
            assert not e.isleap
コード例 #20
0
    def test_complex(self):
        assert fiscalyear.START_YEAR == "previous"
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1

        with fiscalyear.fiscal_calendar("same", 4, 6):
            assert fiscalyear.START_YEAR == "same"
            assert fiscalyear.START_MONTH == 4
            assert fiscalyear.START_DAY == 6

        assert fiscalyear.START_YEAR == "previous"
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1
コード例 #21
0
    def test_complex(self):
        assert fiscalyear.START_YEAR == 'previous'
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1

        with fiscalyear.fiscal_calendar('same', 4, 6):
            assert fiscalyear.START_YEAR == 'same'
            assert fiscalyear.START_MONTH == 4
            assert fiscalyear.START_DAY == 6

        assert fiscalyear.START_YEAR == 'previous'
        assert fiscalyear.START_MONTH == 10
        assert fiscalyear.START_DAY == 1
コード例 #22
0
 def test_end(self, a):
     with fiscalyear.fiscal_calendar(start_month=1, start_year="same"):
         assert a.end == datetime.datetime(2016, 12, 31, 23, 59, 59)
コード例 #23
0
    def test_q2_start(self, c: FiscalQuarter) -> None:
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert c.start == datetime.datetime(2017, 1, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert c.start == datetime.datetime(2017, 7, 6, 0, 0, 0)
コード例 #24
0
    def test_q4_end(self, e):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert e.end == datetime.datetime(2017, 9, 30, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert e.end == datetime.datetime(2018, 4, 5, 23, 59, 59)
コード例 #25
0
    def test_q4_start(self, e):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert e.start == datetime.datetime(2017, 7, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert e.start == datetime.datetime(2018, 1, 6, 0, 0, 0)
コード例 #26
0
    def test_q3_end(self, d):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert d.end == datetime.datetime(2017, 6, 30, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert d.end == datetime.datetime(2018, 1, 5, 23, 59, 59)
コード例 #27
0
    def test_q3_start(self, d):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert d.start == datetime.datetime(2017, 4, 1, 0, 0, 0)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert d.start == datetime.datetime(2017, 10, 6, 0, 0, 0)
コード例 #28
0
    def test_q2_end(self, c):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert c.end == datetime.datetime(2017, 3, 31, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert c.end == datetime.datetime(2017, 10, 5, 23, 59, 59)
コード例 #29
0
    def test_q1_end(self, b):
        with fiscalyear.fiscal_calendar(*US_FEDERAL):
            assert b.end == datetime.datetime(2016, 12, 31, 23, 59, 59)

        with fiscalyear.fiscal_calendar(*UK_PERSONAL):
            assert b.end == datetime.datetime(2017, 7, 5, 23, 59, 59)
コード例 #30
0
 def test_start(self, a):
     with fiscalyear.fiscal_calendar(start_month=3):
         assert a.start == datetime.datetime(2015, 12, 1, 0, 0)