Ejemplo n.º 1
0
    def test_get_next_date_monthly_multiple_days_next_month(self):
        schedule_lines = [
            '2013/06/27 lightning energy',
            '    ;; schedule ; monthly ; 7th, 27th ; ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/07/07')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 2
0
    def test_get_next_date_monthly_interval3(self):
        schedule_lines = [
            '2013/06/15 lightning energy',
            '    ;; schedule ; monthly ; 15th ; 3 ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/09/15')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 3
0
    def test_get_next_date_monthly_next_month_first(self):
        schedule_lines = [
            '2013/06/28 lightning energy',
            '    ;; schedule ; monthly ; 1st',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/07/01')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 4
0
    def test_get_next_date_monthly_multiple_days_this_month_again(self):
        schedule_lines = [
            '2013/06/08 lightning energy',
            '    ;; schedule ; monthly ; 7th, 12th'
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/06/12')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 5
0
    def test_get_next_date_monthly_next_month_again(self):
        schedule_lines = [
            '2013/06/12 lightning energy',
            '    ;; schedule ; monthly ; 12th ; ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/07/12')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 6
0
    def test_one_entry_count(self):
        testdate = util.get_date_string(date.today())
        schedule_lines = [
            '{date} lightning energy'.format(date=testdate),
            '    ;; schedule ; monthly',
            '    blah blah blah',
        ]
        schedule_thing = ScheduleThing(schedule_lines)

        expected = 1
        actual = len(schedule_thing.get_scheduled_entries())

        self.assertEqual(expected, actual)
Ejemplo n.º 7
0
    def test_get_next_date_monthly_next_month_eom30(self):
        schedule_lines = [
            '2013/07/30 lightning energy',
            '    ;; schedule ; monthly ; eom30 ; ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/08/30')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 8
0
    def test_get_next_date_monthly_too_many70(self):

        schedule_lines = [
            '2013/07/15 lightning energy',
            '    ;; schedule ; monthly ; 70th ; 1 ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/07/31')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 9
0
    def test_one_entry_next_date(self):
        testdate = util.get_date_string(date.today())
        schedule_lines = [
            '{date} lightning energy'.format(date=testdate),
            '    ;; schedule ; monthly',
            '    blah blah blah',
        ]
        schedule_thing = ScheduleThing(schedule_lines)
        schedule_thing.get_scheduled_entries()

        expected = date.today() + relativedelta(months=1)
        actual = schedule_thing.thing_date

        self.assertEqual(expected, actual)
Ejemplo n.º 10
0
    def test_get_next_date_monthly_interval12eom_leap_two(self):

        schedule_lines = [
            '2012/02/29 lightning energy',
            '    ;; schedule ; monthly ; eom ; 12 ; auto',
        ]

        schedule_thing = ScheduleThing(schedule_lines)
        expected_next_date = util.get_date('2013/02/28')

        self.assertEqual(
            expected_next_date,
            schedule_thing._get_next_date(schedule_thing.thing_date)
        )
Ejemplo n.º 11
0
    def setUp(self):
        schedule_lines_test = [
            '2013/06/29 lightning energy',
            '    ;; schedule ; monthly ; 12th ; ; auto'
        ]

        ScheduleThing.do_file_config = False
        self.schedule_thing = ScheduleThing(schedule_lines_test)
Ejemplo n.º 12
0
    def test_basic_entry(self):
        schedule_lines = [
            '2013/06/13 lightning energy',
            '    ;; schedule ; monthly',
            '    blah blah blah',
        ]
        schedule_thing = ScheduleThing(schedule_lines)
        schedule_thing.thing_date = date(2013, 7, 1)

        expected = [
            '2013/07/01 lightning energy',
            '    blah blah blah',
        ]

        actual = schedule_thing._get_entry_thing().get_lines()

        self.assertEqual(expected, actual)
Ejemplo n.º 13
0
class GetWeekDay(TestCase):

    def setUp(self):
        schedule_lines_test = [
            '2013/06/29 lightning energy',
            '    ;; schedule ; monthly ; 12th ; ; auto'
        ]

        ScheduleThing.do_file_config = False
        self.schedule_thing = ScheduleThing(schedule_lines_test)

    def test_get_week_day(self):
        self.assertEqual(-1, self.schedule_thing._get_week_day())
Ejemplo n.º 14
0
class GetSafeDate(Redirector):

    def setUp(self):
        super(GetSafeDate, self).setUp()
        schedule_lines_test = [
            '2013/06/29 lightning energy',
            '    ;; schedule ; monthly ; 12th ; ; auto'
        ]
        ScheduleThing.do_file_config = False
        self.schedule_thing = ScheduleThing(schedule_lines_test)

    def test_date_is_fine(self):
        expected = date(2013, 8, 31)
        actual = self.schedule_thing._get_safe_date(expected, 31)
        self.assertEqual(expected, actual)

    def test_day_is_too_many(self):
        expected = date(2013, 8, 31)
        actual = self.schedule_thing._get_safe_date(
            date(2013, 8, 31),
            99
        )
        self.assertEqual(expected, actual)
Ejemplo n.º 15
0
class GetMonthDay(Redirector):

    def setUp(self):
        super(GetMonthDay, self).setUp()
        schedule_lines_test = [
            '2013/06/29 lightning energy',
            '    ;; schedule ; monthly ; 12th ; ; auto'
        ]

        ScheduleThing.do_file_config = False
        self.schedule_thing = ScheduleThing(schedule_lines_test)

    def test_get_month_day_normal(self):
        """normal day is returned as the same day number"""
        testdate = datetime(2013, 6, 16)
        self.assertEqual(
            5,
            self.schedule_thing._get_month_day('5', testdate)
        )

    def test_get_month_day_february_30(self):
        testdate = datetime(2016, 2, 16)
        self.assertEqual(
            29,
            self.schedule_thing._get_month_day('30', testdate)
        )

    def test_get_month_day_june_eom(self):
        """eom for a 30-day month is 30"""
        testdate = datetime(2013, 6, 16)
        self.assertEqual(
            30,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM,
                testdate
            )
        )

    def test_get_month_day_july_eom(self):
        """eom for a 31-day month is 31"""
        testdate = datetime(2013, 7, 1)
        self.assertEqual(
            31,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM,
                testdate
            )
        )

    def test_get_month_day_february_eom(self):
        """eom for a non-leap year february is 28"""
        testdate = datetime(2013, 2, 5)
        self.assertEqual(
            28,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM,
                testdate
            )
        )

    def test_get_month_day_leap_february_eom(self):
        """eom for a leap year february is 29"""
        testdate = datetime(2012, 2, 5)
        self.assertEqual(
            29,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM,
                testdate
            )
        )

    def test_get_month_day_june_eom30(self):
        """eom30 for a 30-day month is 30"""
        testdate = datetime(2013, 6, 16)
        self.assertEqual(
            30,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM30,
                testdate
            )
        )

    def test_get_month_day_july_eom30(self):
        """eom30 for a 31-day month is 30"""
        testdate = datetime(2013, 7, 1)
        self.assertEqual(
            30,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM30,
                testdate
            )
        )

    def test_get_month_day_february_eom30(self):
        """eom30 for a non-leap year february is 28"""
        testdate = datetime(2013, 2, 5)
        self.assertEqual(
            28,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM30,
                testdate
            )
        )

    def test_get_month_day_leap_february_eom30(self):
        """eom for a leap year february is 29"""
        testdate = datetime(2012, 2, 5)
        self.assertEqual(
            29,
            self.schedule_thing._get_month_day(
                ScheduleThing.EOM30,
                testdate
            )
        )