import time
import unittest

import freezegun
import nose.tools


from statscache.schedule import Schedule


class TestSchedule(unittest.TestCase):

    @freezegun.freeze_time('2012-01-14 00:00:00')
    def test_basic(self):
        s = Schedule(minute=[15], hour=[5])
        self.assertEquals(float(s), 5 * 60 * 60 + 15 * 60 + 1)

    @freezegun.freeze_time('2012-01-14 00:00:00')
    def test_one_second(self):
        s = Schedule()
        self.assertEquals(float(s), 1)

    @freezegun.freeze_time('2012-01-14 00:00:01')
    def test_one_second_ahead(self):
        s = Schedule()
        self.assertEquals(float(s), 1)

    @freezegun.freeze_time('2012-01-14 00:00:00')
    def test_two_seconds(self):
        s = Schedule(second=[2])
        self.assertEquals(float(s), 2)

    @freezegun.freeze_time('2012-01-14 12:00:00')
    def test_wrap_day(self):
        s = Schedule(minute=[15], hour=[5])
        self.assertEquals(float(s), 17 * 60 * 60 + 15 * 60 + 1)

    @freezegun.freeze_time('2012-01-14 12:15:00')
    def test_wrap_day_match_minute(self):
        s = Schedule(minute=[15], hour=[5])
        self.assertEquals(float(s), 17 * 60 * 60 + 1)

    @freezegun.freeze_time('2012-01-14 12:16:00')
    def test_wrap_day_wrap_minute(self):
        s = Schedule(minute=[15], hour=[5])
        self.assertEquals(float(s), 16 * 60 * 60 + 59 * 60 + 1)

    @freezegun.freeze_time('2012-01-14 00:00:00')
    def test_working_with_time_sleep(self):
        s = Schedule(second=[1])
        time.sleep(s)  # Let's just make sure this doesn't crash

    @nose.tools.raises(ValueError)
    def test_wrap_invalid_item(self):
        Schedule(minute=['lol'])

    @nose.tools.raises(TypeError)
    def test_wrap_invalid_item_int(self):
        Schedule(minute=1)

if __name__ == '__main__':
    unittest.main()

@@ -1346,32 +1346,535 @@
 + 59 * 60 + 1)%0A%0A
+    @freezegun.freeze_time('2012-01-14 12:15:01')%0A    def test_denomination_precedence_default(self):%0A        # https://github.com/fedora-infra/statscache/issues/10%0A        s = Schedule(minute=%5B15, 16%5D)%0A        self.assertEquals(float(s), 59)%0A%0A    @freezegun.freeze_time('2012-01-14 12:15:01')%0A    def test_denomination_precedence_specified(self):%0A        # https://github.com/fedora-infra/statscache/issues/10%0A        s = Schedule(second=range(60), minute=%5B15%5D)%0A        self.assertEquals(float(s), 1)%0A%0A
     @freezegun.f

Add failing tests for #10.