DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (1aeaa33a64f9)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import absolute_import, unicode_literals

import datetime
import unittest

from mozunit import main

from taskgraph.cron.util import (
    match_utc,
)


class TestMatchUtc(unittest.TestCase):

    def test_hour_minute(self):
        params = {'time': datetime.datetime(2017, 1, 26, 16, 30, 0)}
        self.assertFalse(match_utc(params, {'hour': 4, 'minute': 30}))
        self.assertTrue(match_utc(params, {'hour': 16, 'minute': 30}))
        self.assertFalse(match_utc(params, {'hour': 16, 'minute': 0}))

    def test_hour_only(self):
        params = {'time': datetime.datetime(2017, 1, 26, 16, 0, 0)}
        self.assertFalse(match_utc(params, {'hour': 0}))
        self.assertFalse(match_utc(params, {'hour': 4}))
        self.assertTrue(match_utc(params, {'hour': 16}))
        params = {'time': datetime.datetime(2017, 1, 26, 16, 15, 0)}
        self.assertFalse(match_utc(params, {'hour': 0}))
        self.assertFalse(match_utc(params, {'hour': 4}))
        self.assertTrue(match_utc(params, {'hour': 16}))
        params = {'time': datetime.datetime(2017, 1, 26, 16, 30, 0)}
        self.assertFalse(match_utc(params, {'hour': 0}))
        self.assertFalse(match_utc(params, {'hour': 4}))
        self.assertTrue(match_utc(params, {'hour': 16}))
        params = {'time': datetime.datetime(2017, 1, 26, 16, 45, 0)}
        self.assertFalse(match_utc(params, {'hour': 0}))
        self.assertFalse(match_utc(params, {'hour': 4}))
        self.assertTrue(match_utc(params, {'hour': 16}))

    def test_minute_only(self):
        params = {'time': datetime.datetime(2017, 1, 26, 13, 0, 0)}
        self.assertTrue(match_utc(params, {'minute': 0}))
        self.assertFalse(match_utc(params, {'minute': 15}))
        self.assertFalse(match_utc(params, {'minute': 30}))
        self.assertFalse(match_utc(params, {'minute': 45}))

    def test_zeroes(self):
        params = {'time': datetime.datetime(2017, 1, 26, 0, 0, 0)}
        self.assertTrue(match_utc(params, {'minute': 0}))
        self.assertTrue(match_utc(params, {'hour': 0}))
        self.assertFalse(match_utc(params, {'hour': 1}))
        self.assertFalse(match_utc(params, {'minute': 15}))
        self.assertFalse(match_utc(params, {'minute': 30}))
        self.assertFalse(match_utc(params, {'minute': 45}))

    def test_invalid_minute(self):
        params = {'time': datetime.datetime(2017, 1, 26, 13, 0, 0)}
        self.assertRaises(Exception, lambda:
                          match_utc(params, {'minute': 1}))

    def test_day_hour_minute(self):
        params = {'time': datetime.datetime(2017, 1, 26, 16, 30, 0)}
        self.assertFalse(match_utc(params, {'day': 25, 'hour': 16, 'minute': 30}))
        self.assertTrue(match_utc(params, {'day': 26, 'hour': 16, 'minute': 30}))
        self.assertFalse(match_utc(params, {'day': 26, 'hour': 16, 'minute': 0}))

    def test_weekday_hour_minute(self):
        params = {'time': datetime.datetime(2017, 1, 26, 16, 30, 0)}
        self.assertFalse(match_utc(params, {'weekday': 'Wednesday', 'hour': 16, 'minute': 30}))
        self.assertTrue(match_utc(params, {'weekday': 'Thursday', 'hour': 16, 'minute': 30}))
        self.assertFalse(match_utc(params, {'weekday': 'Thursday', 'hour': 16, 'minute': 0}))


if __name__ == '__main__':
    main()