diff --git a/futurist/periodics.py b/futurist/periodics.py index 5ad61f1..6b8980b 100644 --- a/futurist/periodics.py +++ b/futurist/periodics.py @@ -164,7 +164,7 @@ def periodic(spacing, run_immediately=False, enabled=True): :type enabled: boolean """ - if spacing <= 0: + if spacing <= 0 and enabled: raise ValueError("Periodicity/spacing must be greater than" " zero instead of %s" % spacing) diff --git a/futurist/tests/test_periodics.py b/futurist/tests/test_periodics.py index 0c003e8..a5e09bc 100644 --- a/futurist/tests/test_periodics.py +++ b/futurist/tests/test_periodics.py @@ -323,6 +323,19 @@ class TestPeriodics(testscenarios.TestWithScenarios, base.TestCase): self.assertIsNotNone(w.add(add_me)) self.assertEqual(1, len(w)) + def test_interval_checking(self): + + @periodics.periodic(-0.5, enabled=False) + def no_add_me(): + pass + + w = periodics.PeriodicWorker([], **self.worker_kwargs) + self.assertEqual(0, len(w)) + self.assertIsNone(w.add(no_add_me)) + self.assertEqual(0, len(w)) + + self.assertRaises(ValueError, periodics.periodic, -0.5) + def test_is_periodic(self): @periodics.periodic(0.5, enabled=False)