Exemple #1
0
    def test_vixie_word_annually(self):
        """Test built-in @annually (no hash)

        @annually is the same as @yearly
        """
        obj_annually = croniter_hash("@annually", self.epoch, hash_id=None)
        obj_yearly = croniter_hash("@yearly", self.epoch, hash_id=None)
        self.assertEqual(obj_annually.get_next(datetime),
                         obj_yearly.get_next(datetime))
        self.assertEqual(obj_annually.get_next(datetime),
                         obj_yearly.get_next(datetime))
Exemple #2
0
 def test_random_float(self):
     """Test random definition, float result"""
     obj = croniter_hash("R R * * *", self.epoch)
     result_1 = obj.get_next(float)
     self.assertGreaterEqual(result_1, 1577836800.0)
     self.assertLessEqual(result_1, 1577836800.0 + (60 * 60 * 24))
     result_2 = obj.get_next(float)
     self.assertGreaterEqual(result_2, 1577923200.0)
     self.assertLessEqual(result_2, 1577923200.0 + (60 * 60 * 24))
Exemple #3
0
 def test_random_range(self):
     """Test random definition within a range"""
     obj = croniter_hash("R R R(10-20) * *", self.epoch)
     result_1 = obj.get_next(datetime)
     self.assertGreaterEqual(result_1, datetime(2020, 1, 10, 0, 0))
     self.assertLessEqual(result_1,
                          datetime(2020, 1, 10, 0, 0) + timedelta(days=11))
     result_2 = obj.get_next(datetime)
     self.assertGreaterEqual(result_2, datetime(2020, 2, 10, 0, 0))
     self.assertLessEqual(result_2,
                          datetime(2020, 2, 10, 0, 0) + timedelta(days=11))
Exemple #4
0
 def test_random(self):
     """Test random definition"""
     obj = croniter_hash("R R * * *", self.epoch)
     result_1 = obj.get_next(datetime)
     self.assertGreaterEqual(result_1, datetime(2020, 1, 1, 0, 0))
     self.assertLessEqual(result_1,
                          datetime(2020, 1, 1, 0, 0) + timedelta(days=1))
     result_2 = obj.get_next(datetime)
     self.assertGreaterEqual(result_2, datetime(2020, 1, 2, 0, 0))
     self.assertLessEqual(result_2,
                          datetime(2020, 1, 2, 0, 0) + timedelta(days=1))
Exemple #5
0
 def _test_iter(self,
                definition,
                expectations,
                delta,
                epoch=None,
                hash_id=-1,
                next_type=None):
     if epoch is None:
         epoch = self.epoch
     if hash_id == -1:
         hash_id = self.hash_id
     if next_type is None:
         next_type = datetime
     if not isinstance(expectations, (list, tuple)):
         expectations = (expectations, )
     obj = croniter_hash(definition, epoch, hash_id=hash_id)
     testval = obj.get_next(next_type)
     self.assertIn(testval, expectations)
     if delta is not None:
         self.assertEqual(obj.get_next(next_type), testval + delta)
Exemple #6
0
 def test_invalid_hash_id_type(self):
     """Test an invalid hash_id type raises TypeError"""
     with self.assertRaises(TypeError):
         croniter_hash("H H * * *", self.epoch, hash_id={1: 2})
Exemple #7
0
 def test_invalid_get_next_type(self):
     """Test an invalid get_next type raises TypeError"""
     obj = croniter_hash("H H * * *", self.epoch, hash_id=self.hash_id)
     with self.assertRaises(TypeError):
         obj.get_next(str)
Exemple #8
0
 def test_invalid_no_hash(self):
     """Test a definition with "H" but no hash_id raises CroniterBadCronError"""
     with self.assertRaises(croniter.CroniterBadCronError):
         croniter_hash("H H * * *", self.epoch, hash_id=None)
Exemple #9
0
 def test_invalid_definition(self):
     """Test an invalid defition raises CroniterNotAlphaError"""
     with self.assertRaises(croniter.CroniterNotAlphaError):
         croniter_hash("X X * * *", self.epoch, hash_id=self.hash_id)