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 -class Assert:
42
43 @classmethod
44 - def equal(self, first, second, msg=None):
45 """
46 Asserts that 2 elements are the same
47
48 :Args:
49 - First object to be tested
50 - Second object to be tested
51 - Message that will be printed if it fails
52 """
53 assert first == second, msg
54
55 @classmethod
56 - def not_equal(self, first, second, msg=None):
57 """
58 Asserts that 2 elements are the same
59
60 :Args:
61 - First object to be tested
62 - Second object to be tested
63 - Message that will be printed if it fails
64 """
65 assert first != second, msg
66
67 @classmethod
68 - def true(self, first, msg=None):
69 """
70 Asserts that what is given is equal to True
71
72 :Args:
73 - First object to be tested
74 - Message that will be printed if it fails
75 """
76
77 assert first is True, msg
78
79 @classmethod
80 - def false(self, first, msg=None):
81 """
82 Asserts that what is given is equal to False
83
84 :Args:
85 - First object to be tested
86 - Message that will be printed if it fails
87 """
88
89 assert first is False, msg
90
91 @classmethod
92 - def none(self, first, msg=None):
93 """
94 Asserts that what is given is equal to None
95
96 :Args:
97 - First object to be tested
98 - Message that will be printed if it fails
99 """
100
101 assert first is None, msg
102
103 @classmethod
105 """
106 Asserts that what is given is not equal to None
107
108 :Args:
109 - First object to be tested
110 - Message that will be printed if it fails
111 """
112
113 assert first is not None, msg
114
115 @classmethod
116 - def fail(self, msg):
117 """
118 Raises an assertion error with a message passed in
119
120 :Args:
121 - Message that will be printed
122 """
123 raise AssertionError(msg)
124
125 @classmethod
127 """
128 Goes through a list and asserts that items in the list are sorted ascendingly
129
130 :Args:
131 - List that will be asserted against
132 - Message that will be printed if it fails
133 """
134 for i in xrange(len(iterable) - 1):
135 assert iterable[i] <= iterable[i + 1], '. '.join(['%s is not before %s' % (iterable[i + 1], iterable[i]), msg])
136
137 @classmethod
139 """
140 Goes through a list and asserts that items in the list are sorted descendingly
141
142 :Args:
143 - List that will be asserted against
144 - Message that will be printed if it fails
145 """
146
147 for i in xrange(len(iterable) - 1):
148 assert iterable[i] >= iterable[i + 1], '. '.join(['%s is not before %s' % (iterable[i], iterable[i + 1]), msg])
149
150 @classmethod
151 - def raises(self, exception, caller, msg=None, *args, **kwargs):
152 """
153 Asserts that an Error is raised when calling a method
154
155 :Args:
156 - Error class
157 - method to be called
158 - Message that will be printed if it fails
159 - args that will be passed to the caller
160 - kwargs that will be passed to the caller
161 """
162 try:
163 caller(*args, **kwargs)
164 except exception:
165 return
166
167 if hasattr(exception, '__name__'):
168 excName = exception.__name__
169 else:
170 excName = str(exception)
171
172 raise AssertionError("%s was not raised" % excName)
173
174 @classmethod
176 try:
177 assert needle in haystack
178 except AssertionError:
179 raise AssertionError('%s is not found in %s' % (needle, haystack))
180
181 @classmethod
182 - def less(self, first, second, msg=None):
183 """
184 Asserts that first element is < the second element
185
186 :Args:
187 - First object to be tested
188 - Second object to be tested
189 - Message that will be printed if it fails
190 """
191 assert first < second, msg
192
193 @classmethod
194 - def greater(self, first, second, msg=None):
195 """
196 Asserts that first element is greater than the second element
197
198 :Args:
199 - First object to be tested
200 - Second object to be tested
201 - Message that will be printed if it fails
202 """
203
204 assert first > second, msg
205
206 @classmethod
208 """
209 Asserts that the first element is <= to the second element
210
211 :Args:
212 - First object to be tested
213 - Second object to be tested
214 - Message that will be printed if it fails
215 """
216
217 assert first <= second, msg
218
219 @classmethod
221 """
222 Asserts that first element is >= to the send element
223
224 :Args:
225 - First object to be tested
226 - Second object to be tested
227 - Message that will be printed if it fails
228 """
229
230 assert first >= second, msg
231