forked from ahawker/crython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_field.py
170 lines (152 loc) · 4.99 KB
/
test_field.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
__author__ = 'Andrew Hawker <andrew.r.hawker@gmail.com>'
from crython.crython import sec, min, hr, dom, mon, dow, yr
import unittest
class CronField(object):
def test_wildcard(self):
"""
Test field created from a wildcard (*) character.
"""
midpt = (self.min + self.max) / 2
field = self.field('*')
assert midpt in field
assert self.min in field
assert self.max in field
assert not (self.min - 1) in field
assert not (self.max + 1) in field
def test_integer(self):
"""
Test field created from an integer object.
"""
val = (self.max + self.min) / 2
field = self.field(val)
assert not (val - 1) in field
assert not (val + 1) in field
assert val in field
def test_csv(self):
"""
Test field created from a comma separated list.
"""
min = self.min + 1
midpt = (self.max + self.min) / 2
max = self.max - 1
field = self.field(','.join(map(str, (min, midpt, max))))
assert min in field
assert midpt in field
assert max in field
assert not (midpt - 1) in field
assert not (max + 10) in field
def test_integer_string(self):
"""
Test field created from a string which can be converted to an integer.
"""
val = (self.max + self.min) / 2
field = self.field(str(val))
assert val in field
assert not (val - 1) in field
assert not (val + 1) in field
def test_range(self):
"""
Test field created from string representation of a range.
"""
start = self.min + 10
stop = start + 10
midpt = (start + stop) / 2
field = self.field('{0}-{1}'.format(start, stop))
assert start in field
assert midpt in field
assert stop in field
assert not (start - 1) in field
assert not (stop + 1) in field
def test_range_with_step(self):
"""
Test field created from string representation of a range with a step.
"""
start = self.min + 10
stop = start + 10
step = 2
field = self.field('{0}-{1}/{2}'.format(start, stop, step))
assert start in field
assert stop in field
assert (start + step) in field
assert not (stop + step) in field
assert not (start + (step - 1)) in field
assert not (start + (step + 1)) in field
def test_wildcard_with_step(self):
"""
Test field created from a wildcard with a step.
"""
step = 2
field = self.field('*/{0}'.format(step))
assert self.min in field
assert (self.min + step) in field
assert not (self.min + 1) in field
def test_range_obj(self):
"""
Test field created from an iterable. Ex: range(x,y)
"""
start = self.min
stop = start + 20
midpt = (start + stop) / 2
field = self.field(range(start, stop))
assert start in field
assert midpt in field
assert not stop in field
assert not (stop + 1) in field
def test_range_obj_with_step(self):
"""
Test field created from an interable with step. Ex: range(x,y,z)
"""
start = self.min
stop = start + 20
step = 2
field = self.field(range(start,stop, step))
assert start in field
assert not stop in field
assert (start + step) in field
assert not (stop + step) in field
assert not (start + (step - 1)) in field
assert not (start + (step + 1)) in field
class TestCronSecond(unittest.TestCase, CronField):
def setUp(self):
self.field = sec
self.min = 0
self.max = 59
self.specials = set(['*', '/', ',', '-'])
class TestCronMinute(unittest.TestCase, CronField):
def setUp(self):
self.field = min
self.min = 0
self.max = 59
self.specials = set(['*', '/', ',', '-'])
class TestCronHour(unittest.TestCase, CronField):
def setUp(self):
self.field = hr
self.min = 0
self.max = 23
self.specials = set(['*', '/', ',', '-'])
class TestCronDay(unittest.TestCase, CronField):
def setUp(self):
self.field = dom
self.min = 1
self.max = 31
self.specials = set(['*', '/', ',', '-', '?', 'L', 'W'])
class TestCronMonth(unittest.TestCase, CronField):
def setUp(self):
self.field = mon
self.min = 1
self.max = 12
self.specials = set(['*', '/', ',', '-'])
class TestCronDayOfWeek(unittest.TestCase, CronField):
def setUp(self):
self.field = dow
self.min = 0
self.max = 6
self.specials = set(['*', '/', '-', '?', 'L', '#'])
class TestCronYear(unittest.TestCase, CronField):
def setUp(self):
self.field = yr
self.min = 1970
self.max = 2099
self.specials = set(['*', '/', ',', '-'])
if __name__ == '__main__':
unittest.main()