Debian Codegraph @

test/test_tag_expression.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2
3 from __future__ import absolute_import
4 from behave.tag_expression import TagExpression
5 from nose import tools
6 import unittest
7
8
9 # ----------------------------------------------------------------------------
10 # BASIC TESTS: 0..1 tags, not @tag
11 # ----------------------------------------------------------------------------
12 class TestTagExpressionNoTags(unittest.TestCase):
13 def setUp(self):
14 self.e = TagExpression([])
15
16 def test_should_match_empty_tags(self):
17 assert self.e.check([])
18
19 def test_should_match_foo(self):
20 assert self.e.check(['foo'])
21
22
23 class TestTagExpressionFoo(unittest.TestCase):
24 def setUp(self):
25 self.e = TagExpression(['foo'])
26
27 def test_should_not_match_no_tags(self):
28 assert not self.e.check([])
29
30 def test_should_match_foo(self):
31 assert self.e.check(['foo'])
32
33 def test_should_not_match_bar(self):
34 assert not self.e.check(['bar'])
35
36
37 class TestTagExpressionNotFoo(unittest.TestCase):
38 def setUp(self):
39 self.e = TagExpression(['-foo'])
40
41 def test_should_match_no_tags(self):
42 assert self.e.check([])
43
44 def test_should_not_match_foo(self):
45 assert not self.e.check(['foo'])
46
47 def test_should_match_bar(self):
48 assert self.e.check(['bar'])
49
50
51 # ----------------------------------------------------------------------------
52 # LOGICAL-AND TESTS: With @foo, @bar (2 tags)
53 # ----------------------------------------------------------------------------
54 class TestTagExpressionFooAndBar(unittest.TestCase):
55 # -- LOGIC: @foo and @bar
56
57 def setUp(self):
58 self.e = TagExpression(['foo', 'bar'])
59
60 def test_should_not_match_no_tags(self):
61 assert not self.e.check([])
62
63 def test_should_not_match_foo(self):
64 assert not self.e.check(['foo'])
65
66 def test_should_not_match_bar(self):
67 assert not self.e.check(['bar'])
68
69 def test_should_not_match_other(self):
70 assert not self.e.check(['other'])
71
72 def test_should_match_foo_bar(self):
73 assert self.e.check(['foo', 'bar'])
74 assert self.e.check(['bar', 'foo'])
75
76 def test_should_not_match_foo_other(self):
77 assert not self.e.check(['foo', 'other'])
78 assert not self.e.check(['other', 'foo'])
79
80 def test_should_not_match_bar_other(self):
81 assert not self.e.check(['bar', 'other'])
82 assert not self.e.check(['other', 'bar'])
83
84 def test_should_not_match_zap_other(self):
85 assert not self.e.check(['zap', 'other'])
86 assert not self.e.check(['other', 'zap'])
87
88 def test_should_match_foo_bar_other(self):
89 assert self.e.check(['foo', 'bar', 'other'])
90 assert self.e.check(['bar', 'other', 'foo'])
91 assert self.e.check(['other', 'bar', 'foo'])
92
93 def test_should_not_match_foo_zap_other(self):
94 assert not self.e.check(['foo', 'zap', 'other'])
95 assert not self.e.check(['other', 'zap', 'foo'])
96
97 def test_should_not_match_bar_zap_other(self):
98 assert not self.e.check(['bar', 'zap', 'other'])
99 assert not self.e.check(['other', 'bar', 'zap'])
100
101 def test_should_not_match_zap_baz_other(self):
102 assert not self.e.check(['zap', 'baz', 'other'])
103 assert not self.e.check(['baz', 'other', 'baz'])
104 assert not self.e.check(['other', 'baz', 'zap'])
105
106
107 class TestTagExpressionFooAndNotBar(unittest.TestCase):
108 # -- LOGIC: @foo and not @bar
109
110 def setUp(self):
111 self.e = TagExpression(['foo', '-bar'])
112
113 def test_should_not_match_no_tags(self):
114 assert not self.e.check([])
115
116 def test_should_match_foo(self):
117 assert self.e.check(['foo'])
118
119 def test_should_not_match_bar(self):
120 assert not self.e.check(['bar'])
121
122 def test_should_not_match_other(self):
123 assert not self.e.check(['other'])
124
125 def test_should_not_match_foo_bar(self):
126 assert not self.e.check(['foo', 'bar'])
127 assert not self.e.check(['bar', 'foo'])
128
129 def test_should_match_foo_other(self):
130 assert self.e.check(['foo', 'other'])
131 assert self.e.check(['other', 'foo'])
132
133 def test_should_not_match_bar_other(self):
134 assert not self.e.check(['bar', 'other'])
135 assert not self.e.check(['other', 'bar'])
136
137 def test_should_not_match_zap_other(self):
138 assert not self.e.check(['bar', 'other'])
139 assert not self.e.check(['other', 'bar'])
140
141 def test_should_not_match_foo_bar_other(self):
142 assert not self.e.check(['foo', 'bar', 'other'])
143 assert not self.e.check(['bar', 'other', 'foo'])
144 assert not self.e.check(['other', 'bar', 'foo'])
145
146 def test_should_match_foo_zap_other(self):
147 assert self.e.check(['foo', 'zap', 'other'])
148 assert self.e.check(['other', 'zap', 'foo'])
149
150 def test_should_not_match_bar_zap_other(self):
151 assert not self.e.check(['bar', 'zap', 'other'])
152 assert not self.e.check(['other', 'bar', 'zap'])
153
154 def test_should_not_match_zap_baz_other(self):
155 assert not self.e.check(['zap', 'baz', 'other'])
156 assert not self.e.check(['baz', 'other', 'baz'])
157 assert not self.e.check(['other', 'baz', 'zap'])
158
159
160 class TestTagExpressionNotBarAndFoo(TestTagExpressionFooAndNotBar):
161 # -- REUSE: Test suite due to symmetry in reversed expression
162 # LOGIC: not @bar and @foo == @foo and not @bar
163
164 def setUp(self):
165 self.e = TagExpression(['-bar', 'foo'])
166
167
168 class TestTagExpressionNotFooAndNotBar(unittest.TestCase):
169 # -- LOGIC: not @bar and not @foo
170
171 def setUp(self):
172 self.e = TagExpression(['-foo', '-bar'])
173
174 def test_should_match_no_tags(self):
175 assert self.e.check([])
176
177 def test_should_not_match_foo(self):
178 assert not self.e.check(['foo'])
179
180 def test_should_not_match_bar(self):
181 assert not self.e.check(['bar'])
182
183 def test_should_match_other(self):
184 assert self.e.check(['other'])
185
186 def test_should_not_match_foo_bar(self):
187 assert not self.e.check(['foo', 'bar'])
188 assert not self.e.check(['bar', 'foo'])
189
190 def test_should_not_match_foo_other(self):
191 assert not self.e.check(['foo', 'other'])
192 assert not self.e.check(['other', 'foo'])
193
194 def test_should_not_match_bar_other(self):
195 assert not self.e.check(['bar', 'other'])
196 assert not self.e.check(['other', 'bar'])
197
198 def test_should_match_zap_other(self):
199 assert self.e.check(['zap', 'other'])
200 assert self.e.check(['other', 'zap'])
201
202 def test_should_not_match_foo_bar_other(self):
203 assert not self.e.check(['foo', 'bar', 'other'])
204 assert not self.e.check(['bar', 'other', 'foo'])
205 assert not self.e.check(['other', 'bar', 'foo'])
206
207 def test_should_not_match_foo_zap_other(self):
208 assert not self.e.check(['foo', 'zap', 'other'])
209 assert not self.e.check(['other', 'zap', 'foo'])
210
211 def test_should_not_match_bar_zap_other(self):
212 assert not self.e.check(['bar', 'zap', 'other'])
213 assert not self.e.check(['other', 'bar', 'zap'])
214
215 def test_should_match_zap_baz_other(self):
216 assert self.e.check(['zap', 'baz', 'other'])
217 assert self.e.check(['baz', 'other', 'baz'])
218 assert self.e.check(['other', 'baz', 'zap'])
219
220
221 class TestTagExpressionNotBarAndNotFoo(TestTagExpressionNotFooAndNotBar):
222 # -- REUSE: Test suite due to symmetry in reversed expression
223 # LOGIC: not @bar and not @foo == not @foo and not @bar
224
225 def setUp(self):
226 self.e = TagExpression(['-bar', '-foo'])
227
228
229 # ----------------------------------------------------------------------------
230 # LOGICAL-OR TESTS: With @foo, @bar (2 tags)
231 # ----------------------------------------------------------------------------
232 class TestTagExpressionFooOrBar(unittest.TestCase):
233 def setUp(self):
234 self.e = TagExpression(['foo,bar'])
235
236 def test_should_not_match_no_tags(self):
237 assert not self.e.check([])
238
239 def test_should_match_foo(self):
240 assert self.e.check(['foo'])
241
242 def test_should_match_bar(self):
243 assert self.e.check(['bar'])
244
245 def test_should_not_match_other(self):
246 assert not self.e.check(['other'])
247
248 def test_should_match_foo_bar(self):
249 assert self.e.check(['foo', 'bar'])
250 assert self.e.check(['bar', 'foo'])
251
252 def test_should_match_foo_other(self):
253 assert self.e.check(['foo', 'other'])
254 assert self.e.check(['other', 'foo'])
255
256 def test_should_match_bar_other(self):
257 assert self.e.check(['bar', 'other'])
258 assert self.e.check(['other', 'bar'])
259
260 def test_should_not_match_zap_other(self):
261 assert not self.e.check(['zap', 'other'])
262 assert not self.e.check(['other', 'zap'])
263
264 def test_should_match_foo_bar_other(self):
265 assert self.e.check(['foo', 'bar', 'other'])
266 assert self.e.check(['bar', 'other', 'foo'])
267 assert self.e.check(['other', 'bar', 'foo'])
268
269 def test_should_match_foo_zap_other(self):
270 assert self.e.check(['foo', 'zap', 'other'])
271 assert self.e.check(['other', 'zap', 'foo'])
272
273 def test_should_match_bar_zap_other(self):
274 assert self.e.check(['bar', 'zap', 'other'])
275 assert self.e.check(['other', 'bar', 'zap'])
276
277 def test_should_not_match_zap_baz_other(self):
278 assert not self.e.check(['zap', 'baz', 'other'])
279 assert not self.e.check(['baz', 'other', 'baz'])
280 assert not self.e.check(['other', 'baz', 'zap'])
281
282
283 class TestTagExpressionBarOrFoo(TestTagExpressionFooOrBar):
284 # -- REUSE: Test suite due to symmetry in reversed expression
285 # LOGIC: @bar or @foo == @foo or @bar
286 def setUp(self):
287 self.e = TagExpression(['bar,foo'])
288
289
290 class TestTagExpressionFooOrNotBar(unittest.TestCase):
291 def setUp(self):
292 self.e = TagExpression(['foo,-bar'])
293
294 def test_should_match_no_tags(self):
295 assert self.e.check([])
296
297 def test_should_match_foo(self):
298 assert self.e.check(['foo'])
299
300 def test_should_not_match_bar(self):
301 assert not self.e.check(['bar'])
302
303 def test_should_match_other(self):
304 assert self.e.check(['other'])
305
306 def test_should_match_foo_bar(self):
307 assert self.e.check(['foo', 'bar'])
308 assert self.e.check(['bar', 'foo'])
309
310 def test_should_match_foo_other(self):
311 assert self.e.check(['foo', 'other'])
312 assert self.e.check(['other', 'foo'])
313
314 def test_should_not_match_bar_other(self):
315 assert not self.e.check(['bar', 'other'])
316 assert not self.e.check(['other', 'bar'])
317
318 def test_should_match_zap_other(self):
319 assert self.e.check(['zap', 'other'])
320 assert self.e.check(['other', 'zap'])
321
322 def test_should_match_foo_bar_other(self):
323 assert self.e.check(['foo', 'bar', 'other'])
324 assert self.e.check(['bar', 'other', 'foo'])
325 assert self.e.check(['other', 'bar', 'foo'])
326
327 def test_should_match_foo_zap_other(self):
328 assert self.e.check(['foo', 'zap', 'other'])
329 assert self.e.check(['other', 'zap', 'foo'])
330
331 def test_should_not_match_bar_zap_other(self):
332 assert not self.e.check(['bar', 'zap', 'other'])
333 assert not self.e.check(['other', 'bar', 'zap'])
334
335 def test_should_match_zap_baz_other(self):
336 assert self.e.check(['zap', 'baz', 'other'])
337 assert self.e.check(['baz', 'other', 'baz'])
338 assert self.e.check(['other', 'baz', 'zap'])
339
340
341 class TestTagExpressionNotBarOrFoo(TestTagExpressionFooOrNotBar):
342 # -- REUSE: Test suite due to symmetry in reversed expression
343 # LOGIC: not @bar or @foo == @foo or not @bar
344 def setUp(self):
345 self.e = TagExpression(['-bar,foo'])
346
347
348 class TestTagExpressionNotFooOrNotBar(unittest.TestCase):
349 def setUp(self):
350 self.e = TagExpression(['-foo,-bar'])
351
352 def test_should_match_no_tags(self):
353 assert self.e.check([])
354
355 def test_should_match_foo(self):
356 assert self.e.check(['foo'])
357
358 def test_should_match_bar(self):
359 assert self.e.check(['bar'])
360
361 def test_should_match_other(self):
362 assert self.e.check(['other'])
363
364 def test_should_not_match_foo_bar(self):
365 assert not self.e.check(['foo', 'bar'])
366 assert not self.e.check(['bar', 'foo'])
367
368 def test_should_match_foo_other(self):
369 assert self.e.check(['foo', 'other'])
370 assert self.e.check(['other', 'foo'])
371
372 def test_should_match_bar_other(self):
373 assert self.e.check(['bar', 'other'])
374 assert self.e.check(['other', 'bar'])
375
376 def test_should_match_zap_other(self):
377 assert self.e.check(['zap', 'other'])
378 assert self.e.check(['other', 'zap'])
379
380 def test_should_not_match_foo_bar_other(self):
381 assert not self.e.check(['foo', 'bar', 'other'])
382 assert not self.e.check(['bar', 'other', 'foo'])
383 assert not self.e.check(['other', 'bar', 'foo'])
384
385 def test_should_match_foo_zap_other(self):
386 assert self.e.check(['foo', 'zap', 'other'])
387 assert self.e.check(['other', 'zap', 'foo'])
388
389 def test_should_match_bar_zap_other(self):
390 assert self.e.check(['bar', 'zap', 'other'])
391 assert self.e.check(['other', 'bar', 'zap'])
392
393 def test_should_match_zap_baz_other(self):
394 assert self.e.check(['zap', 'baz', 'other'])
395 assert self.e.check(['baz', 'other', 'baz'])
396 assert self.e.check(['other', 'baz', 'zap'])
397
398
399 class TestTagExpressionNotBarOrNotFoo(TestTagExpressionNotFooOrNotBar):
400 # -- REUSE: Test suite due to symmetry in reversed expression
401 # LOGIC: not @bar or @foo == @foo or not @bar
402 def setUp(self):
403 self.e = TagExpression(['-bar,-foo'])
404
405
406 # ----------------------------------------------------------------------------
407 # MORE TESTS: With 3 tags
408 # ----------------------------------------------------------------------------
409 class TestTagExpressionFooOrBarAndNotZap(unittest.TestCase):
410 def setUp(self):
411 self.e = TagExpression(['foo,bar', '-zap'])
412
413 def test_should_match_foo(self):
414 assert self.e.check(['foo'])
415
416 def test_should_not_match_foo_zap(self):
417 assert not self.e.check(['foo', 'zap'])
418
419 def test_should_not_match_tags(self):
420 assert not self.e.check([])
421
422 def test_should_match_foo(self):
423 assert self.e.check(['foo'])
424
425 def test_should_match_bar(self):
426 assert self.e.check(['bar'])
427
428 def test_should_not_match_other(self):
429 assert not self.e.check(['other'])
430
431 def test_should_match_foo_bar(self):
432 assert self.e.check(['foo', 'bar'])
433 assert self.e.check(['bar', 'foo'])
434
435 def test_should_match_foo_other(self):
436 assert self.e.check(['foo', 'other'])
437 assert self.e.check(['other', 'foo'])
438
439 def test_should_match_bar_other(self):
440 assert self.e.check(['bar', 'other'])
441 assert self.e.check(['other', 'bar'])
442
443 def test_should_not_match_zap_other(self):
444 assert not self.e.check(['zap', 'other'])
445 assert not self.e.check(['other', 'zap'])
446
447 def test_should_match_foo_bar_other(self):
448 assert self.e.check(['foo', 'bar', 'other'])
449 assert self.e.check(['bar', 'other', 'foo'])
450 assert self.e.check(['other', 'bar', 'foo'])
451
452 def test_should_not_match_foo_bar_zap(self):
453 assert not self.e.check(['foo', 'bar', 'zap'])
454 assert not self.e.check(['bar', 'zap', 'foo'])
455 assert not self.e.check(['zap', 'bar', 'foo'])
456
457 def test_should_not_match_foo_zap_other(self):
458 assert not self.e.check(['foo', 'zap', 'other'])
459 assert not self.e.check(['other', 'zap', 'foo'])
460
461 def test_should_not_match_bar_zap_other(self):
462 assert not self.e.check(['bar', 'zap', 'other'])
463 assert not self.e.check(['other', 'bar', 'zap'])
464
465 def test_should_not_match_zap_baz_other(self):
466 assert not self.e.check(['zap', 'baz', 'other'])
467 assert not self.e.check(['baz', 'other', 'baz'])
468 assert not self.e.check(['other', 'baz', 'zap'])
469
470
471 # ----------------------------------------------------------------------------
472 # TESTS WITH LIMIT
473 # ----------------------------------------------------------------------------
474 class TestTagExpressionFoo3OrNotBar4AndZap5(unittest.TestCase):
475 def setUp(self):
476 self.e = TagExpression(['foo:3,-bar', 'zap:5'])
477
478 def test_should_count_tags_for_positive_tags(self):
479 tools.eq_(self.e.limits, {'foo': 3, 'zap': 5})
480
481 def test_should_match_foo_zap(self):
482 assert self.e.check(['foo', 'zap'])
483
484 class TestTagExpressionParsing(unittest.TestCase):
485 def setUp(self):
486 self.e = TagExpression([' foo:3 , -bar ', ' zap:5 '])
487
488 def test_should_have_limits(self):
489 tools.eq_(self.e.limits, {'zap': 5, 'foo': 3})
490
491 class TestTagExpressionTagLimits(unittest.TestCase):
492 def test_should_be_counted_for_negative_tags(self):
493 e = TagExpression(['-todo:3'])
494 tools.eq_(e.limits, {'todo': 3})
495
496 def test_should_be_counted_for_positive_tags(self):
497 e = TagExpression(['todo:3'])
498 tools.eq_(e.limits, {'todo': 3})
499
500 def test_should_raise_an_error_for_inconsistent_limits(self):
501 tools.assert_raises(Exception, TagExpression, ['todo:3', '-todo:4'])
502
503 def test_should_allow_duplicate_consistent_limits(self):
504 e = TagExpression(['todo:3', '-todo:3'])
505 tools.eq_(e.limits, {'todo': 3})
506