summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2016-04-03 17:55:09 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2016-04-03 17:55:09 +0300
commitba5e8dd68e46da90fafac2e5638f9168c03737b1 (patch)
tree5f2ac72c89bd9de7dc7541dae7c3ff16dd1523fd /tests
parent1f324b840223b174912ca307110655d4babf765c (diff)
downloadapscheduler-ba5e8dd68e46da90fafac2e5638f9168c03737b1.tar.gz
Added pickling tests for triggers
Diffstat (limited to 'tests')
-rw-r--r--tests/test_triggers.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/test_triggers.py b/tests/test_triggers.py
index 62fe559..8e81116 100644
--- a/tests/test_triggers.py
+++ b/tests/test_triggers.py
@@ -1,4 +1,5 @@
-from datetime import datetime, timedelta
+import pickle
+from datetime import datetime, timedelta, date
import pytest
import pytz
@@ -213,6 +214,17 @@ class TestCronTrigger(object):
correct_next_date = est.localize(datetime(2009, 9, 26, 11, 20))
assert str(trigger.get_next_fire_time(None, start_date)) == str(correct_next_date)
+ def test_pickle(self, timezone):
+ """Test that the trigger is pickleable."""
+
+ trigger = CronTrigger(year=2016, month='5-6', day='20-28', hour=7, minute=25, second='*',
+ timezone=timezone)
+ data = pickle.dumps(trigger, 2)
+ trigger2 = pickle.loads(data)
+
+ for attr in CronTrigger.__slots__:
+ assert getattr(trigger2, attr) == getattr(trigger, attr)
+
class TestDateTrigger(object):
@pytest.mark.parametrize('run_date,alter_tz,previous,now,expected', [
@@ -254,6 +266,14 @@ class TestDateTrigger(object):
trigger = DateTrigger(datetime(2009, 7, 6), timezone)
assert str(trigger) == "date[2009-07-06 00:00:00 CEST]"
+ def test_pickle(self, timezone):
+ """Test that the trigger is pickleable."""
+
+ trigger = DateTrigger(date(2016, 4, 3), timezone=timezone)
+ data = pickle.dumps(trigger, 2)
+ trigger2 = pickle.loads(data)
+ assert trigger2.run_date == trigger.run_date
+
class TestIntervalTrigger(object):
@pytest.fixture()
@@ -324,3 +344,14 @@ class TestIntervalTrigger(object):
def test_str(self, trigger):
assert str(trigger) == "interval[0:00:01]"
+
+ def test_pickle(self, timezone):
+ """Test that the trigger is pickleable."""
+
+ trigger = IntervalTrigger(weeks=2, days=6, minutes=13, seconds=2,
+ start_date=date(2016, 4, 3), timezone=timezone)
+ data = pickle.dumps(trigger, 2)
+ trigger2 = pickle.loads(data)
+
+ for attr in IntervalTrigger.__slots__:
+ assert getattr(trigger2, attr) == getattr(trigger, attr)