示例#1
0
    def test_working_with_time_sleep(self):
        now = datetime.now()
        f = Schedule(timedelta(seconds=1), midnight_of(now))

        value = float(f)
        # Be careful not to sleep for 20 years if there's a bug
        if value > 2:
            raise ValueError("sleeping too long %r" % value)

        time.sleep(f)  # Let's just make sure this doesn't crash
示例#2
0
 def test_all(self):
     f = Schedule(timedelta(days=1, hours=1, minutes=1, seconds=1),
                  datetime.utcnow())
     self.assertEqual(str(f), '1d1h1m1s')
示例#3
0
 def test_hour(self):
     f = Schedule(timedelta(days=1), datetime.utcnow())
     self.assertEqual(str(f), '1d')
示例#4
0
 def test_minute(self):
     f = Schedule(timedelta(minutes=10), datetime.utcnow())
     self.assertEqual(str(f), '10m')
示例#5
0
 def test_second(self):
     f = Schedule(timedelta(seconds=10), datetime.utcnow())
     self.assertEqual(str(f), '10s')
示例#6
0
 def test_invalid_epoch(self):
     Schedule(timedelta(seconds=15), 'squirrels')
示例#7
0
 def test_invalid_interval(self):
     Schedule('banana', datetime.utcnow())
示例#8
0
 def test_last_on_epoch(self):
     now = datetime.now()
     f = Schedule(timedelta(hours=5, minutes=20, seconds=30),
                  midnight_of(now))
     self.assertEquals(f.last(), datetime(year=2012, month=1, day=14))
示例#9
0
 def test_last_before_epoch(self):
     now = datetime.now()
     f = Schedule(timedelta(minutes=15, hours=5), now)
     self.assertEquals(
         f.last(now=(now - timedelta(seconds=1))),
         datetime(year=2012, month=1, day=13, hour=22, minute=45))
示例#10
0
 def test_two_seconds(self):
     now = datetime.now()
     f = Schedule(timedelta(seconds=2), midnight_of(now))
     self.assertEquals(float(f), 2)
示例#11
0
 def test_one_second_ahead(self):
     now = datetime.now()
     f = Schedule(timedelta(seconds=1), midnight_of(now))
     self.assertEquals(float(f), 1)
示例#12
0
 def test_basic(self):
     now = datetime.now()
     f = Schedule(timedelta(minutes=15, hours=5), midnight_of(now))
     self.assertEquals(float(f), (5 * 60 + 15) * 60)
示例#13
0
 def test_last_on_epoch(self):
     now = datetime.now()
     f = Schedule(timedelta(hours=5, minutes=20, seconds=30), midnight_of(now))
     self.assertEquals(f.last(), datetime(year=2012, month=1, day=14))
示例#14
0
 def test_last_before_epoch(self):
     now = datetime.now()
     f = Schedule(timedelta(minutes=15, hours=5), now)
     self.assertEquals(f.last(now=(now - timedelta(seconds=1))),
         datetime(year=2012, month=1, day=13, hour=22, minute=45))