Debian Codegraph @

debian/patches/switch-from-nose-to-pytest-and-unittest.patch

raw symbols SCIP
1 Description: Switch away from nose
2 Author: Thomas Goirand <[email protected]>
3 Bug-Debian: https://bugs.debian.org/1018586
4 Forwarded: no
5 Last-Update: 2024-05-02
6
7 Index: python-sure/tests/test_old_api.py
8 ===================================================================
9 --- python-sure.orig/tests/test_old_api.py
10 +++ python-sure/tests/test_old_api.py
11 @@ -24,1598 +24,1580 @@ import sure
12 from sure.deprecated import that
13 from sure.magic import is_cpython
14 from sure import VariablesBag, expect
15 -from nose.tools import assert_equal as assert_equals
16 -from nose.tools import assert_raises
17 +import unittest
18 from sure.compat import compat_repr, safe_repr, text_type_name
19
20 +class testOldApi(unittest.TestCase):
21 + def test_setup_with_context(self):
22 + "sure.with_context() runs setup before the function itself"
23 +
24 + def setup(context):
25 + context.name = "John Resig"
26 +
27 + @sure.that_with_context(setup)
28 + def john_is_within_context(context):
29 + assert isinstance(context, VariablesBag)
30 + assert hasattr(context, "name")
31 +
32 + john_is_within_context()
33 + self.assertEqual(
34 + john_is_within_context.__name__,
35 + 'john_is_within_context',
36 + )
37
38 -def test_setup_with_context():
39 - "sure.with_context() runs setup before the function itself"
40 -
41 - def setup(context):
42 - context.name = "John Resig"
43
44 - @sure.that_with_context(setup)
45 - def john_is_within_context(context):
46 - assert isinstance(context, VariablesBag)
47 - assert hasattr(context, "name")
48 + def test_context_is_not_optional(self):
49 + "sure.that_with_context() when no context is given it fails"
50
51 - john_is_within_context()
52 - assert_equals(
53 - john_is_within_context.__name__,
54 - 'john_is_within_context',
55 - )
56 + def setup(context):
57 + context.name = "John Resig"
58
59 + @sure.that_with_context(setup)
60 + def it_crashes():
61 + assert True
62 +
63 + assert that(it_crashes).raises(
64 + TypeError, (
65 + "the function it_crashes defined at test_old_api.py line 56, is being "
66 + "decorated by either @that_with_context or @scenario, so it should "
67 + "take at least 1 parameter, which is the test context"),
68 + )
69
70 -def test_context_is_not_optional():
71 - "sure.that_with_context() when no context is given it fails"
72
73 - def setup(context):
74 - context.name = "John Resig"
75 + def test_setup_with_context_context_failing(self):
76 + "sure.that_with_context() in a failing test"
77
78 - @sure.that_with_context(setup)
79 - def it_crashes():
80 - assert True
81 + def setup(context):
82 + context.name = "John Resig"
83
84 - assert that(it_crashes).raises(
85 - TypeError, (
86 - "the function it_crashes defined at test_old_api.py line 56, is being "
87 - "decorated by either @that_with_context or @scenario, so it should "
88 - "take at least 1 parameter, which is the test context"),
89 - )
90 + @sure.that_with_context(setup)
91 + def it_fails(context):
92 + assert False, 'should fail with this exception'
93
94 + assert that(it_fails).raises('should fail with this exception')
95
96 -def test_setup_with_context_context_failing():
97 - "sure.that_with_context() in a failing test"
98
99 - def setup(context):
100 - context.name = "John Resig"
101 + def test_teardown_with_context(self):
102 + "sure.with_context() runs teardown before the function itself"
103
104 - @sure.that_with_context(setup)
105 - def it_fails(context):
106 - assert False, 'should fail with this exception'
107 + class something:
108 + pass
109
110 - assert that(it_fails).raises('should fail with this exception')
111 + def setup(context):
112 + something.modified = True
113
114 + def teardown(context):
115 + del something.modified
116
117 -def test_teardown_with_context():
118 - "sure.with_context() runs teardown before the function itself"
119 + @sure.that_with_context(setup, teardown)
120 + def something_was_modified(context):
121 + assert hasattr(something, "modified")
122 + assert something.modified
123
124 - class something:
125 - pass
126 + something_was_modified()
127 + assert not hasattr(something, "modified")
128
129 - def setup(context):
130 - something.modified = True
131
132 - def teardown(context):
133 - del something.modified
134 + def test_that_is_a(self):
135 + "that() is_a(object)"
136
137 - @sure.that_with_context(setup, teardown)
138 - def something_was_modified(context):
139 - assert hasattr(something, "modified")
140 - assert something.modified
141 + something = "something"
142
143 - something_was_modified()
144 - assert not hasattr(something, "modified")
145 + assert that(something).is_a(text_type)
146 + assert isinstance(something, text_type)
147
148
149 -def test_that_is_a():
150 - "that() is_a(object)"
151 + def test_that_equals(self):
152 + "that() equals(string)"
153
154 - something = "something"
155 + something = "something"
156
157 - assert that(something).is_a(text_type)
158 - assert isinstance(something, text_type)
159 + assert that('something').equals(something)
160 + assert something == 'something'
161
162
163 -def test_that_equals():
164 - "that() equals(string)"
165 + def test_that_differs(self):
166 + "that() differs(object)"
167
168 - something = "something"
169 + something = "something"
170
171 - assert that('something').equals(something)
172 - assert something == 'something'
173 + assert that(something).differs("23123%FYTUGIHOfdf")
174 + assert something != "23123%FYTUGIHOfdf"
175
176
177 -def test_that_differs():
178 - "that() differs(object)"
179 + def test_that_has(self):
180 + "that() has(object)"
181 + class Class:
182 + name = "some class"
183 + Object = Class()
184 + dictionary = {
185 + 'name': 'John',
186 + }
187 + name = "john"
188
189 - something = "something"
190 + assert hasattr(Class, 'name')
191 + assert that(Class).has("name")
192 + assert that(Class).like("name")
193 + assert "name" in that(Class)
194
195 - assert that(something).differs("23123%FYTUGIHOfdf")
196 - assert something != "23123%FYTUGIHOfdf"
197 + assert hasattr(Object, 'name')
198 + assert that(Object).has("name")
199 + assert that(Object).like("name")
200 + assert "name" in that(Object)
201
202 + assert 'name' in dictionary
203 + assert that(dictionary).has("name")
204 + assert that(dictionary).like("name")
205 + assert "name" in that(dictionary)
206
207 -def test_that_has():
208 - "that() has(object)"
209 - class Class:
210 - name = "some class"
211 - Object = Class()
212 - dictionary = {
213 - 'name': 'John',
214 - }
215 - name = "john"
216 + assert that(name).has("john")
217 + assert that(name).like("john")
218 + assert "john" in that(name)
219 + assert that(name).has("hn")
220 + assert that(name).like("hn")
221 + assert "hn" in that(name)
222 + assert that(name).has("jo")
223 + assert that(name).like("jo")
224 + assert "jo" in that(name)
225
226 - assert hasattr(Class, 'name')
227 - assert that(Class).has("name")
228 - assert that(Class).like("name")
229 - assert "name" in that(Class)
230
231 - assert hasattr(Object, 'name')
232 - assert that(Object).has("name")
233 - assert that(Object).like("name")
234 - assert "name" in that(Object)
235 + def test_that_at_key_equals(self):
236 + "that().at(object).equals(object)"
237
238 - assert 'name' in dictionary
239 - assert that(dictionary).has("name")
240 - assert that(dictionary).like("name")
241 - assert "name" in that(dictionary)
242 + class Class:
243 + name = "some class"
244 + Object = Class()
245 + dictionary = {
246 + 'name': 'John',
247 + }
248
249 - assert that(name).has("john")
250 - assert that(name).like("john")
251 - assert "john" in that(name)
252 - assert that(name).has("hn")
253 - assert that(name).like("hn")
254 - assert "hn" in that(name)
255 - assert that(name).has("jo")
256 - assert that(name).like("jo")
257 - assert "jo" in that(name)
258 + assert that(Class).at("name").equals('some class')
259 + assert that(Object).at("name").equals('some class')
260 + assert that(dictionary).at("name").equals('John')
261
262
263 -def test_that_at_key_equals():
264 - "that().at(object).equals(object)"
265 + def test_that_len_is(self):
266 + "that() len_is(number)"
267
268 - class Class:
269 - name = "some class"
270 - Object = Class()
271 - dictionary = {
272 - 'name': 'John',
273 - }
274 + lst = range(1000)
275
276 - assert that(Class).at("name").equals('some class')
277 - assert that(Object).at("name").equals('some class')
278 - assert that(dictionary).at("name").equals('John')
279 + assert that(lst).len_is(1000)
280 + assert len(lst) == 1000
281 + assert that(lst).len_is(lst)
282
283
284 -def test_that_len_is():
285 - "that() len_is(number)"
286 + def test_that_len_greater_than(self):
287 + "that() len_greater_than(number)"
288
289 - lst = range(1000)
290 + lst = range(1000)
291 + lst2 = range(100)
292
293 - assert that(lst).len_is(1000)
294 - assert len(lst) == 1000
295 - assert that(lst).len_is(lst)
296 + assert that(lst).len_greater_than(100)
297 + assert len(lst) == 1000
298 + assert that(lst).len_greater_than(lst2)
299
300
301 -def test_that_len_greater_than():
302 - "that() len_greater_than(number)"
303 + def test_that_len_greater_than_should_raise_assertion_error(self):
304 + "that() len_greater_than(number) raise AssertionError"
305
306 - lst = range(1000)
307 - lst2 = range(100)
308 + lst = list(range(1000))
309 + try:
310 + that(lst).len_greater_than(1000)
311 + except AssertionError as e:
312 + self.assertEqual(
313 + str(e),
314 + 'the length of the list should be greater then %d, but is %d' \
315 + % (1000, 1000))
316
317 - assert that(lst).len_greater_than(100)
318 - assert len(lst) == 1000
319 - assert that(lst).len_greater_than(lst2)
320
321 + def test_that_len_greater_than_or_equals(self):
322 + "that() len_greater_than_or_equals(number)"
323
324 -def test_that_len_greater_than_should_raise_assertion_error():
325 - "that() len_greater_than(number) raise AssertionError"
326 + lst = list(range(1000))
327 + lst2 = list(range(100))
328
329 - lst = list(range(1000))
330 - try:
331 - that(lst).len_greater_than(1000)
332 - except AssertionError as e:
333 - assert_equals(
334 - str(e),
335 - 'the length of the list should be greater then %d, but is %d' \
336 - % (1000, 1000))
337 + assert that(lst).len_greater_than_or_equals(100)
338 + assert that(lst).len_greater_than_or_equals(1000)
339 + assert len(lst) == 1000
340 + assert that(lst).len_greater_than_or_equals(lst2)
341 + assert that(lst).len_greater_than_or_equals(lst)
342
343
344 -def test_that_len_greater_than_or_equals():
345 - "that() len_greater_than_or_equals(number)"
346 + def test_that_len_greater_than_or_equals_should_raise_assertion_error(self):
347 + "that() len_greater_than_or_equals(number) raise AssertionError"
348
349 - lst = list(range(1000))
350 - lst2 = list(range(100))
351 + lst = list(range(1000))
352 + try:
353 + that(lst).len_greater_than_or_equals(1001)
354 + except AssertionError as e:
355 + self.assertEqual(
356 + str(e),
357 + 'the length of %r should be greater then or equals %d, but is %d' \
358 + % (lst, 1001, 1000))
359
360 - assert that(lst).len_greater_than_or_equals(100)
361 - assert that(lst).len_greater_than_or_equals(1000)
362 - assert len(lst) == 1000
363 - assert that(lst).len_greater_than_or_equals(lst2)
364 - assert that(lst).len_greater_than_or_equals(lst)
365
366 + def test_that_len_lower_than(self):
367 + "that() len_lower_than(number)"
368
369 -def test_that_len_greater_than_or_equals_should_raise_assertion_error():
370 - "that() len_greater_than_or_equals(number) raise AssertionError"
371 + lst = list(range(100))
372 + lst2 = list(range(1000))
373
374 - lst = list(range(1000))
375 - try:
376 - that(lst).len_greater_than_or_equals(1001)
377 - except AssertionError as e:
378 - assert_equals(
379 - str(e),
380 - 'the length of %r should be greater then or equals %d, but is %d' \
381 - % (lst, 1001, 1000))
382 + assert that(lst).len_lower_than(101)
383 + assert len(lst) == 100
384 + assert that(lst).len_lower_than(lst2)
385
386
387 -def test_that_len_lower_than():
388 - "that() len_lower_than(number)"
389 + def test_that_len_lower_than_should_raise_assertion_error(self):
390 + "that() len_lower_than(number) raise AssertionError"
391
392 - lst = list(range(100))
393 - lst2 = list(range(1000))
394 + lst = list(range(1000))
395 + try:
396 + that(lst).len_lower_than(1000)
397 + except AssertionError as e:
398 + self.assertEqual(
399 + str(e),
400 + 'the length of %r should be lower then %d, but is %d' % \
401 + (lst, 1000, 1000))
402
403 - assert that(lst).len_lower_than(101)
404 - assert len(lst) == 100
405 - assert that(lst).len_lower_than(lst2)
406
407 + def test_that_len_lower_than_or_equals(self):
408 + "that() len_lower_than_or_equals(number)"
409
410 -def test_that_len_lower_than_should_raise_assertion_error():
411 - "that() len_lower_than(number) raise AssertionError"
412 + lst = list(range(1000))
413 + lst2 = list(range(1001))
414
415 - lst = list(range(1000))
416 - try:
417 - that(lst).len_lower_than(1000)
418 - except AssertionError as e:
419 - assert_equals(
420 - str(e),
421 - 'the length of %r should be lower then %d, but is %d' % \
422 - (lst, 1000, 1000))
423 + assert that(lst).len_lower_than_or_equals(1001)
424 + assert that(lst).len_lower_than_or_equals(1000)
425 + assert len(lst) == 1000
426 + assert that(lst).len_lower_than_or_equals(lst2)
427 + assert that(lst).len_lower_than_or_equals(lst)
428
429
430 -def test_that_len_lower_than_or_equals():
431 - "that() len_lower_than_or_equals(number)"
432 + def test_that_len_lower_than_or_equals_should_raise_assertion_error(self):
433 + "that() len_lower_than_or_equals(number) raise AssertionError"
434
435 - lst = list(range(1000))
436 - lst2 = list(range(1001))
437 + lst = list(range(1000))
438 + try:
439 + that(lst).len_lower_than_or_equals(100)
440 + except AssertionError as e:
441 + self.assertEqual(
442 + str(e),
443 + 'the length of %r should be lower then or equals %d, but is %d' % \
444 + (lst, 100, 1000))
445
446 - assert that(lst).len_lower_than_or_equals(1001)
447 - assert that(lst).len_lower_than_or_equals(1000)
448 - assert len(lst) == 1000
449 - assert that(lst).len_lower_than_or_equals(lst2)
450 - assert that(lst).len_lower_than_or_equals(lst)
451
452 + def test_that_checking_all_atributes(self):
453 + "that(iterable).the_attribute('name').equals('value')"
454 + class shape(object):
455 + def __init__(self, name):
456 + self.kind = 'geometrical form'
457 + self.name = name
458
459 -def test_that_len_lower_than_or_equals_should_raise_assertion_error():
460 - "that() len_lower_than_or_equals(number) raise AssertionError"
461 + shapes = [
462 + shape('circle'),
463 + shape('square'),
464 + shape('rectangle'),
465 + shape('triangle'),
466 + ]
467
468 - lst = list(range(1000))
469 - try:
470 - that(lst).len_lower_than_or_equals(100)
471 - except AssertionError as e:
472 - assert_equals(
473 - str(e),
474 - 'the length of %r should be lower then or equals %d, but is %d' % \
475 - (lst, 100, 1000))
476 + assert that(shapes).the_attribute("kind").equals('geometrical form')
477
478
479 -def test_that_checking_all_atributes():
480 - "that(iterable).the_attribute('name').equals('value')"
481 - class shape(object):
482 - def __init__(self, name):
483 - self.kind = 'geometrical form'
484 - self.name = name
485 + def test_that_checking_all_atributes_of_range(self):
486 + "that(iterable, within_range=(1, 2)).the_attribute('name').equals('value')"
487 + class shape(object):
488 + def __init__(self, name):
489 + self.kind = 'geometrical form'
490 + self.name = name
491
492 - shapes = [
493 - shape('circle'),
494 - shape('square'),
495 - shape('rectangle'),
496 - shape('triangle'),
497 - ]
498 + def __repr__(self):
499 + return '<%s:%s>' % (self.kind, self.name)
500
501 - assert that(shapes).the_attribute("kind").equals('geometrical form')
502 + shapes = [
503 + shape('circle'),
504 + shape('square'),
505 + shape('square'),
506 + shape('triangle'),
507 + ]
508
509 + assert shapes[0].name != 'square'
510 + assert shapes[3].name != 'square'
511
512 -def test_that_checking_all_atributes_of_range():
513 - "that(iterable, within_range=(1, 2)).the_attribute('name').equals('value')"
514 - class shape(object):
515 - def __init__(self, name):
516 - self.kind = 'geometrical form'
517 - self.name = name
518 + assert shapes[1].name == 'square'
519 + assert shapes[2].name == 'square'
520
521 - def __repr__(self):
522 - return '<%s:%s>' % (self.kind, self.name)
523 + assert that(shapes, within_range=(1, 2)). \
524 + the_attribute("name"). \
525 + equals('square')
526
527 - shapes = [
528 - shape('circle'),
529 - shape('square'),
530 - shape('square'),
531 - shape('triangle'),
532 - ]
533
534 - assert shapes[0].name != 'square'
535 - assert shapes[3].name != 'square'
536 + def test_that_checking_all_elements(self):
537 + "that(iterable).every_one_is('value')"
538 + shapes = [
539 + 'cube',
540 + 'ball',
541 + 'ball',
542 + 'piramid',
543 + ]
544
545 - assert shapes[1].name == 'square'
546 - assert shapes[2].name == 'square'
547 + assert shapes[0] != 'ball'
548 + assert shapes[3] != 'ball'
549
550 - assert that(shapes, within_range=(1, 2)). \
551 - the_attribute("name"). \
552 - equals('square')
553 + assert shapes[1] == 'ball'
554 + assert shapes[2] == 'ball'
555
556 + assert that(shapes, within_range=(1, 2)).every_one_is('ball')
557
558 -def test_that_checking_all_elements():
559 - "that(iterable).every_one_is('value')"
560 - shapes = [
561 - 'cube',
562 - 'ball',
563 - 'ball',
564 - 'piramid',
565 - ]
566
567 - assert shapes[0] != 'ball'
568 - assert shapes[3] != 'ball'
569 + def test_that_checking_each_matches(self):
570 + "that(iterable).in_each('').equals('value')"
571 + class animal(object):
572 + def __init__(self, kind):
573 + self.attributes = {
574 + 'class': 'mammal',
575 + 'kind': kind,
576 + }
577
578 - assert shapes[1] == 'ball'
579 - assert shapes[2] == 'ball'
580 + animals = [
581 + animal('dog'),
582 + animal('cat'),
583 + animal('cow'),
584 + animal('cow'),
585 + animal('cow'),
586 + ]
587
588 - assert that(shapes, within_range=(1, 2)).every_one_is('ball')
589 + assert animals[0].attributes['kind'] != 'cow'
590 + assert animals[1].attributes['kind'] != 'cow'
591
592 + assert animals[2].attributes['kind'] == 'cow'
593 + assert animals[3].attributes['kind'] == 'cow'
594 + assert animals[4].attributes['kind'] == 'cow'
595
596 -def test_that_checking_each_matches():
597 - "that(iterable).in_each('').equals('value')"
598 - class animal(object):
599 - def __init__(self, kind):
600 - self.attributes = {
601 - 'class': 'mammal',
602 - 'kind': kind,
603 - }
604 + assert animals[0].attributes['class'] == 'mammal'
605 + assert animals[1].attributes['class'] == 'mammal'
606 + assert animals[2].attributes['class'] == 'mammal'
607 + assert animals[3].attributes['class'] == 'mammal'
608 + assert animals[4].attributes['class'] == 'mammal'
609
610 - animals = [
611 - animal('dog'),
612 - animal('cat'),
613 - animal('cow'),
614 - animal('cow'),
615 - animal('cow'),
616 - ]
617 + assert that(animals).in_each("attributes['class']").matches('mammal')
618 + assert that(animals).in_each("attributes['class']"). \
619 + matches(['mammal','mammal','mammal','mammal','mammal'])
620
621 - assert animals[0].attributes['kind'] != 'cow'
622 - assert animals[1].attributes['kind'] != 'cow'
623 + assert that(animals).in_each("attributes['kind']"). \
624 + matches(['dog','cat','cow','cow','cow'])
625
626 - assert animals[2].attributes['kind'] == 'cow'
627 - assert animals[3].attributes['kind'] == 'cow'
628 - assert animals[4].attributes['kind'] == 'cow'
629 + try:
630 + assert that(animals).in_each("attributes['kind']").matches(['dog'])
631 + assert False, 'should not reach here'
632 + except AssertionError as e:
633 + assert that(text_type(e)).equals(
634 + '%r has 5 items, but the matching list has 1: %r' % (
635 + ['dog','cat','cow','cow','cow'], ['dog'],
636 + )
637 + )
638
639 - assert animals[0].attributes['class'] == 'mammal'
640 - assert animals[1].attributes['class'] == 'mammal'
641 - assert animals[2].attributes['class'] == 'mammal'
642 - assert animals[3].attributes['class'] == 'mammal'
643 - assert animals[4].attributes['class'] == 'mammal'
644
645 - assert that(animals).in_each("attributes['class']").matches('mammal')
646 - assert that(animals).in_each("attributes['class']"). \
647 - matches(['mammal','mammal','mammal','mammal','mammal'])
648 + def test_that_raises(self):
649 + "that(callable, with_args=[arg1], and_kwargs={'arg2': 'value'}).raises(SomeException)"
650 + global called
651
652 - assert that(animals).in_each("attributes['kind']"). \
653 - matches(['dog','cat','cow','cow','cow'])
654 + called = False
655
656 - try:
657 - assert that(animals).in_each("attributes['kind']").matches(['dog'])
658 - assert False, 'should not reach here'
659 - except AssertionError as e:
660 - assert that(text_type(e)).equals(
661 - '%r has 5 items, but the matching list has 1: %r' % (
662 - ['dog','cat','cow','cow','cow'], ['dog'],
663 - )
664 - )
665 + def function(arg1=None, arg2=None):
666 + global called
667 + called = True
668 + if arg1 == 1 and arg2 == 2:
669 + raise RuntimeError('yeah, it failed')
670
671 + return "OK"
672
673 -def test_that_raises():
674 - "that(callable, with_args=[arg1], and_kwargs={'arg2': 'value'}).raises(SomeException)"
675 - global called
676 + try:
677 + function(1, 2)
678 + assert False, 'should not reach here'
679
680 - called = False
681 + except RuntimeError as e:
682 + assert text_type(e) == 'yeah, it failed'
683
684 - def function(arg1=None, arg2=None):
685 - global called
686 - called = True
687 - if arg1 == 1 and arg2 == 2:
688 - raise RuntimeError('yeah, it failed')
689 + except Exception:
690 + assert False, 'should not reach here'
691
692 - return "OK"
693 + finally:
694 + assert called
695 + called = False
696
697 - try:
698 - function(1, 2)
699 - assert False, 'should not reach here'
700 + self.assertRaises(RuntimeError, function, 1, 2)
701
702 - except RuntimeError as e:
703 - assert text_type(e) == 'yeah, it failed'
704 + called = False
705 + self.assertEqual(function(3, 5), 'OK')
706 + assert called
707
708 - except Exception:
709 - assert False, 'should not reach here'
710 + called = False
711 + assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
712 + raises(RuntimeError)
713 + assert called
714
715 - finally:
716 + called = False
717 + assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
718 + raises(RuntimeError, 'yeah, it failed')
719 assert called
720 +
721 called = False
722 + assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
723 + raises('yeah, it failed')
724 + assert called
725
726 - assert_raises(RuntimeError, function, 1, 2)
727 + called = False
728 + assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
729 + raises(RuntimeError)
730 + assert called
731
732 - called = False
733 - assert_equals(function(3, 5), 'OK')
734 - assert called
735 + called = False
736 + assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
737 + raises(RuntimeError, 'yeah, it failed')
738 + assert called
739
740 - called = False
741 - assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
742 - raises(RuntimeError)
743 - assert called
744 + called = False
745 + assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
746 + raises('yeah, it failed')
747 + assert called
748
749 - called = False
750 - assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
751 - raises(RuntimeError, 'yeah, it failed')
752 - assert called
753 + called = False
754 + assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
755 + raises(r'it fail')
756 + assert called
757
758 - called = False
759 - assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \
760 - raises('yeah, it failed')
761 - assert called
762 + called = False
763 + assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
764 + raises(RuntimeError, r'it fail')
765 + assert called
766
767 - called = False
768 - assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
769 - raises(RuntimeError)
770 - assert called
771
772 - called = False
773 - assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
774 - raises(RuntimeError, 'yeah, it failed')
775 - assert called
776 + def test_that_looks_like(self):
777 + "that('String\\n with BREAKLINE').looks_like('string with breakline')"
778 + assert that('String\n with BREAKLINE').looks_like('string with breakline')
779
780 - called = False
781 - assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
782 - raises('yeah, it failed')
783 - assert called
784
785 - called = False
786 - assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
787 - raises(r'it fail')
788 - assert called
789 + def test_that_raises_does_raise_for_exception_type_mismatch(self):
790 + "that(callable(RuntimeError)).raises(TypeError)"
791
792 - called = False
793 - assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \
794 - raises(RuntimeError, r'it fail')
795 - assert called
796 + error = r'.*should raise <class .*FooError.*, but raised <class .*BarError.*'
797
798 + class FooError(Exception):
799 + pass
800
801 -def test_that_looks_like():
802 - "that('String\\n with BREAKLINE').looks_like('string with breakline')"
803 - assert that('String\n with BREAKLINE').looks_like('string with breakline')
804 + class BarError(Exception):
805 + pass
806
807 + def my_function():
808 + raise BarError('OOps')
809
810 -def test_that_raises_does_raise_for_exception_type_mismatch():
811 - "that(callable(RuntimeError)).raises(TypeError)"
812 + try:
813 + assert that(my_function).raises(FooError, 'OOps')
814 + assert False, 'should never reach here'
815 + except AssertionError as e:
816 + import re
817 + assert re.match(error, text_type(e))
818
819 - error = r'.*should raise <class .*FooError.*, but raised <class .*BarError.*'
820
821 - class FooError(Exception):
822 - pass
823 + def test_that_raises_with_args(self):
824 + "that(callable, with_args=['foo']).raises(FooError)"
825
826 - class BarError(Exception):
827 - pass
828 + class FooError(Exception):
829 + pass
830
831 - def my_function():
832 - raise BarError('OOps')
833 + def my_function(string):
834 + if string == 'foo':
835 + raise FooError('OOps')
836
837 - try:
838 - assert that(my_function).raises(FooError, 'OOps')
839 - assert False, 'should never reach here'
840 - except AssertionError as e:
841 - import re
842 - assert re.match(error, text_type(e))
843 + assert that(my_function, with_args=['foo']).raises(FooError, 'OOps')
844
845
846 -def test_that_raises_with_args():
847 - "that(callable, with_args=['foo']).raises(FooError)"
848 + def test_that_does_not_raise_with_args(self):
849 + "that(callable).doesnt_raise(FooError) and does_not_raise"
850
851 - class FooError(Exception):
852 - pass
853 + class FooError(Exception):
854 + pass
855
856 - def my_function(string):
857 - if string == 'foo':
858 - raise FooError('OOps')
859 + def my_function(string):
860 + if string == 'foo':
861 + raise FooError('OOps')
862
863 - assert that(my_function, with_args=['foo']).raises(FooError, 'OOps')
864 + assert that(my_function, with_args=['foo']).raises(FooError, 'OOps')
865
866
867 -def test_that_does_not_raise_with_args():
868 - "that(callable).doesnt_raise(FooError) and does_not_raise"
869 + def test_that_contains_string(self):
870 + "that('foobar').contains('foo')"
871
872 - class FooError(Exception):
873 - pass
874 + assert 'foo' in 'foobar'
875 + assert that('foobar').contains('foo')
876
877 - def my_function(string):
878 - if string == 'foo':
879 - raise FooError('OOps')
880
881 - assert that(my_function, with_args=['foo']).raises(FooError, 'OOps')
882 + def test_that_doesnt_contain_string(self):
883 + "that('foobar').does_not_contain('123'), .doesnt_contain"
884
885 + assert '123' not in 'foobar'
886 + assert that('foobar').doesnt_contain('123')
887 + assert that('foobar').does_not_contain('123')
888
889 -def test_that_contains_string():
890 - "that('foobar').contains('foo')"
891
892 - assert 'foo' in 'foobar'
893 - assert that('foobar').contains('foo')
894 + def test_that_contains_none(self):
895 + "that('foobar').contains(None)"
896
897 + def assertions():
898 + # We can't use unicode in Py2, otherwise it will try to coerce
899 + assert that(b'foobar' if PY2 else 'foobar').contains(None)
900
901 -def test_that_doesnt_contain_string():
902 - "that('foobar').does_not_contain('123'), .doesnt_contain"
903 + error_msg = "'in <string>' requires string as left operand, not NoneType" if is_cpython else "'NoneType' does not have the buffer interface"
904
905 - assert '123' not in 'foobar'
906 - assert that('foobar').doesnt_contain('123')
907 - assert that('foobar').does_not_contain('123')
908 + assert that(assertions).raises(
909 + TypeError,
910 + error_msg
911 + )
912
913
914 -def test_that_contains_none():
915 - "that('foobar').contains(None)"
916 + def test_that_none_contains_string(self):
917 + "that(None).contains('bungalow')"
918
919 - def assertions():
920 - # We can't use unicode in Py2, otherwise it will try to coerce
921 - assert that(b'foobar' if PY2 else 'foobar').contains(None)
922 + try:
923 + assert that(None).contains('bungalow')
924 + assert False, 'should not reach here'
925 + except Exception as e:
926 + error_msg = "argument of type 'NoneType' is not iterable" if is_cpython else "'NoneType' object is not iterable"
927 + self.assertEqual(
928 + text_type(e),
929 + error_msg
930 + )
931
932 - error_msg = "'in <string>' requires string as left operand, not NoneType" if is_cpython else "'NoneType' does not have the buffer interface"
933
934 - assert that(assertions).raises(
935 - TypeError,
936 - error_msg
937 - )
938 + def test_that_some_iterable_is_empty(self):
939 + "that(some_iterable).is_empty and that(something).are_empty"
940
941 + assert that([]).is_empty
942 + assert that([]).are_empty
943
944 -def test_that_none_contains_string():
945 - "that(None).contains('bungalow')"
946 + assert that(tuple()).is_empty
947 + assert that({}).are_empty
948
949 - try:
950 - assert that(None).contains('bungalow')
951 - assert False, 'should not reach here'
952 - except Exception as e:
953 - error_msg = "argument of type 'NoneType' is not iterable" if is_cpython else "'NoneType' object is not iterable"
954 - assert_equals(
955 - text_type(e),
956 - error_msg
957 - )
958 + def fail_single():
959 + assert that((1,)).is_empty
960
961 + assert that(fail_single).raises('(1,) is not empty, it has 1 item')
962
963 -def test_that_some_iterable_is_empty():
964 - "that(some_iterable).is_empty and that(something).are_empty"
965 + def fail_plural():
966 + assert that((1, 2)).is_empty
967
968 - assert that([]).is_empty
969 - assert that([]).are_empty
970 + assert that(fail_plural).raises('(1, 2) is not empty, it has 2 items')
971
972 - assert that(tuple()).is_empty
973 - assert that({}).are_empty
974
975 - def fail_single():
976 - assert that((1,)).is_empty
977 + def test_that_something_is_empty_raises(self):
978 + "that(something_not_iterable).is_empty and that(something_not_iterable).are_empty raises"
979
980 - assert that(fail_single).raises('(1,) is not empty, it has 1 item')
981 + obj = object()
982
983 - def fail_plural():
984 - assert that((1, 2)).is_empty
985 + def fail():
986 + assert that(obj).is_empty
987 + assert False, 'should not reach here'
988
989 - assert that(fail_plural).raises('(1, 2) is not empty, it has 2 items')
990 + assert that(fail).raises('%r is not iterable' % obj)
991
992
993 -def test_that_something_is_empty_raises():
994 - "that(something_not_iterable).is_empty and that(something_not_iterable).are_empty raises"
995 + def test_that_something_iterable_matches_another(self):
996 + "that(something_iterable).matches(another_iterable)"
997
998 - obj = object()
999 + # types must be unicode in py3, bute bytestrings in py2
1000 + KlassOne = type(b'KlassOne' if PY2 else 'KlassOne', (object,), {})
1001 + KlassTwo = type(b'KlassTwo' if PY2 else 'KlassTwo', (object,), {})
1002 + one = [
1003 + ("/1", KlassOne),
1004 + ("/2", KlassTwo),
1005 + ]
1006
1007 - def fail():
1008 - assert that(obj).is_empty
1009 - assert False, 'should not reach here'
1010 + two = [
1011 + ("/1", KlassOne),
1012 + ("/2", KlassTwo),
1013 + ]
1014
1015 - assert that(fail).raises('%r is not iterable' % obj)
1016 + assert that(one).matches(two)
1017 + assert that(one).equals(two)
1018
1019 + def fail_1():
1020 + assert that([1]).matches(xrange(2))
1021
1022 -def test_that_something_iterable_matches_another():
1023 - "that(something_iterable).matches(another_iterable)"
1024 + class Fail2(object):
1025 + def __init__(self):
1026 + assert that(xrange(1)).matches([2])
1027
1028 - # types must be unicode in py3, bute bytestrings in py2
1029 - KlassOne = type(b'KlassOne' if PY2 else 'KlassOne', (object,), {})
1030 - KlassTwo = type(b'KlassTwo' if PY2 else 'KlassTwo', (object,), {})
1031 - one = [
1032 - ("/1", KlassOne),
1033 - ("/2", KlassTwo),
1034 - ]
1035 + class Fail3(object):
1036 + def __call__(self):
1037 + assert that(xrange(1)).matches([2])
1038
1039 - two = [
1040 - ("/1", KlassOne),
1041 - ("/2", KlassTwo),
1042 - ]
1043 + xrange_name = xrange.__name__
1044 + assert that(fail_1).raises('X is a list and Y is a {0} instead'.format(xrange_name))
1045 + assert that(Fail2).raises('X is a {0} and Y is a list instead'.format(xrange_name))
1046 + assert that(Fail3()).raises('X is a {0} and Y is a list instead'.format(xrange_name))
1047
1048 - assert that(one).matches(two)
1049 - assert that(one).equals(two)
1050
1051 - def fail_1():
1052 - assert that([1]).matches(xrange(2))
1053 + def test_within_pass(self):
1054 + "within(five=miliseconds) will pass"
1055 + from sure import within, miliseconds
1056
1057 - class Fail2(object):
1058 - def __init__(self):
1059 - assert that(xrange(1)).matches([2])
1060 + within(five=miliseconds)(lambda *a: None)()
1061
1062 - class Fail3(object):
1063 - def __call__(self):
1064 - assert that(xrange(1)).matches([2])
1065
1066 - xrange_name = xrange.__name__
1067 - assert that(fail_1).raises('X is a list and Y is a {0} instead'.format(xrange_name))
1068 - assert that(Fail2).raises('X is a {0} and Y is a list instead'.format(xrange_name))
1069 - assert that(Fail3()).raises('X is a {0} and Y is a list instead'.format(xrange_name))
1070 + def test_within_fail(self):
1071 + "within(five=miliseconds) will fail"
1072 + import time
1073 + from sure import within, miliseconds
1074
1075 + def sleepy(*a):
1076 + time.sleep(0.7)
1077
1078 -def test_within_pass():
1079 - "within(five=miliseconds) will pass"
1080 - from sure import within, miliseconds
1081 + failed = False
1082 + try:
1083 + within(five=miliseconds)(sleepy)()
1084 + except AssertionError as e:
1085 + failed = True
1086 + self.assertEqual('sleepy did not run within five miliseconds', str(e))
1087
1088 - within(five=miliseconds)(lambda *a: None)()
1089 + assert failed, 'within(five=miliseconds)(sleepy) did not fail'
1090
1091
1092 -def test_within_fail():
1093 - "within(five=miliseconds) will fail"
1094 - import time
1095 - from sure import within, miliseconds
1096 + def test_word_to_number(self):
1097 + self.assertEqual(sure.word_to_number('one'), 1)
1098 + self.assertEqual(sure.word_to_number('two'), 2)
1099 + self.assertEqual(sure.word_to_number('three'), 3)
1100 + self.assertEqual(sure.word_to_number('four'), 4)
1101 + self.assertEqual(sure.word_to_number('five'), 5)
1102 + self.assertEqual(sure.word_to_number('six'), 6)
1103 + self.assertEqual(sure.word_to_number('seven'), 7)
1104 + self.assertEqual(sure.word_to_number('eight'), 8)
1105 + self.assertEqual(sure.word_to_number('nine'), 9)
1106 + self.assertEqual(sure.word_to_number('ten'), 10)
1107 + self.assertEqual(sure.word_to_number('eleven'), 11)
1108 + self.assertEqual(sure.word_to_number('twelve'), 12)
1109
1110 - def sleepy(*a):
1111 - time.sleep(0.7)
1112
1113 - failed = False
1114 - try:
1115 - within(five=miliseconds)(sleepy)()
1116 - except AssertionError as e:
1117 - failed = True
1118 - assert_equals('sleepy did not run within five miliseconds', str(e))
1119 + def test_word_to_number_fail(self):
1120 + failed = False
1121 + try:
1122 + sure.word_to_number('twenty')
1123 + except AssertionError as e:
1124 + failed = True
1125 + self.assertEqual(
1126 + text_type(e),
1127 + 'sure supports only literal numbers from one ' \
1128 + 'to twelve, you tried the word "twenty"')
1129
1130 - assert failed, 'within(five=miliseconds)(sleepy) did not fail'
1131 + assert failed, 'should raise assertion error'
1132
1133
1134 -def test_word_to_number():
1135 - assert_equals(sure.word_to_number('one'), 1)
1136 - assert_equals(sure.word_to_number('two'), 2)
1137 - assert_equals(sure.word_to_number('three'), 3)
1138 - assert_equals(sure.word_to_number('four'), 4)
1139 - assert_equals(sure.word_to_number('five'), 5)
1140 - assert_equals(sure.word_to_number('six'), 6)
1141 - assert_equals(sure.word_to_number('seven'), 7)
1142 - assert_equals(sure.word_to_number('eight'), 8)
1143 - assert_equals(sure.word_to_number('nine'), 9)
1144 - assert_equals(sure.word_to_number('ten'), 10)
1145 - assert_equals(sure.word_to_number('eleven'), 11)
1146 - assert_equals(sure.word_to_number('twelve'), 12)
1147 + def test_microsecond_unit(self):
1148 + "testing microseconds convertion"
1149 + cfrom, cto = sure.UNITS[sure.microsecond]
1150
1151 + self.assertEqual(cfrom(1), 100000)
1152 + self.assertEqual(cto(1), 1)
1153
1154 -def test_word_to_number_fail():
1155 - failed = False
1156 - try:
1157 - sure.word_to_number('twenty')
1158 - except AssertionError as e:
1159 - failed = True
1160 - assert_equals(
1161 - text_type(e),
1162 - 'sure supports only literal numbers from one ' \
1163 - 'to twelve, you tried the word "twenty"')
1164 + cfrom, cto = sure.UNITS[sure.microseconds]
1165
1166 - assert failed, 'should raise assertion error'
1167 + self.assertEqual(cfrom(1), 100000)
1168 + self.assertEqual(cto(1), 1)
1169
1170
1171 -def test_microsecond_unit():
1172 - "testing microseconds convertion"
1173 - cfrom, cto = sure.UNITS[sure.microsecond]
1174 + def test_milisecond_unit(self):
1175 + "testing miliseconds convertion"
1176 + cfrom, cto = sure.UNITS[sure.milisecond]
1177
1178 - assert_equals(cfrom(1), 100000)
1179 - assert_equals(cto(1), 1)
1180 + self.assertEqual(cfrom(1), 1000)
1181 + self.assertEqual(cto(100), 1)
1182
1183 - cfrom, cto = sure.UNITS[sure.microseconds]
1184 + cfrom, cto = sure.UNITS[sure.miliseconds]
1185
1186 - assert_equals(cfrom(1), 100000)
1187 - assert_equals(cto(1), 1)
1188 + self.assertEqual(cfrom(1), 1000)
1189 + self.assertEqual(cto(100), 1)
1190
1191
1192 -def test_milisecond_unit():
1193 - "testing miliseconds convertion"
1194 - cfrom, cto = sure.UNITS[sure.milisecond]
1195 + def test_second_unit(self):
1196 + "testing seconds convertion"
1197 + cfrom, cto = sure.UNITS[sure.second]
1198
1199 - assert_equals(cfrom(1), 1000)
1200 - assert_equals(cto(100), 1)
1201 + self.assertEqual(cfrom(1), 1)
1202 + self.assertEqual(cto(100000), 1)
1203
1204 - cfrom, cto = sure.UNITS[sure.miliseconds]
1205 + cfrom, cto = sure.UNITS[sure.seconds]
1206
1207 - assert_equals(cfrom(1), 1000)
1208 - assert_equals(cto(100), 1)
1209 + self.assertEqual(cfrom(1), 1)
1210 + self.assertEqual(cto(100000), 1)
1211
1212
1213 -def test_second_unit():
1214 - "testing seconds convertion"
1215 - cfrom, cto = sure.UNITS[sure.second]
1216 + def test_minute_unit(self):
1217 + "testing minutes convertion"
1218 + cfrom, cto = sure.UNITS[sure.minute]
1219
1220 - assert_equals(cfrom(1), 1)
1221 - assert_equals(cto(100000), 1)
1222 + self.assertEqual(cfrom(60), 1)
1223 + self.assertEqual(cto(1), 6000000)
1224
1225 - cfrom, cto = sure.UNITS[sure.seconds]
1226 + cfrom, cto = sure.UNITS[sure.minutes]
1227
1228 - assert_equals(cfrom(1), 1)
1229 - assert_equals(cto(100000), 1)
1230 + self.assertEqual(cfrom(60), 1)
1231 + self.assertEqual(cto(1), 6000000)
1232
1233
1234 -def test_minute_unit():
1235 - "testing minutes convertion"
1236 - cfrom, cto = sure.UNITS[sure.minute]
1237 + def test_within_pass_utc(self):
1238 + "within(five=miliseconds) gives utc parameter"
1239 + from sure import within, miliseconds
1240 + from datetime import datetime
1241
1242 - assert_equals(cfrom(60), 1)
1243 - assert_equals(cto(1), 6000000)
1244 + def assert_utc(utc):
1245 + assert isinstance(utc, datetime)
1246
1247 - cfrom, cto = sure.UNITS[sure.minutes]
1248 + within(five=miliseconds)(assert_utc)()
1249
1250 - assert_equals(cfrom(60), 1)
1251 - assert_equals(cto(1), 6000000)
1252
1253 + def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher(self):
1254 + "that.is_a_matcher should absorb callables to be used as matcher"
1255 + @that.is_a_matcher
1256 + def is_truthful(what):
1257 + assert bool(what), '%s is so untrue' % (what)
1258 + return 'foobar'
1259
1260 -def test_within_pass_utc():
1261 - "within(five=miliseconds) gives utc parameter"
1262 - from sure import within, miliseconds
1263 - from datetime import datetime
1264 + assert that('friend').is_truthful()
1265 + self.assertEqual(that('friend').is_truthful(), 'foobar')
1266
1267 - def assert_utc(utc):
1268 - assert isinstance(utc, datetime)
1269
1270 - within(five=miliseconds)(assert_utc)()
1271 + def test_accepts_setup_list(self):
1272 + "sure.with_context() accepts a list of callbacks for setup"
1273
1274 + def setup1(context):
1275 + context.first_name = "John"
1276
1277 -def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher():
1278 - "that.is_a_matcher should absorb callables to be used as matcher"
1279 - @that.is_a_matcher
1280 - def is_truthful(what):
1281 - assert bool(what), '%s is so untrue' % (what)
1282 - return 'foobar'
1283 + def setup2(context):
1284 + context.last_name = "Resig"
1285
1286 - assert that('friend').is_truthful()
1287 - assert_equals(that('friend').is_truthful(), 'foobar')
1288 + @sure.that_with_context([setup1, setup2])
1289 + def john_is_within_context(context):
1290 + assert context.first_name == 'John'
1291 + assert context.last_name == 'Resig'
1292
1293 + john_is_within_context()
1294 + self.assertEqual(
1295 + john_is_within_context.__name__,
1296 + 'john_is_within_context',
1297 + )
1298
1299 -def test_accepts_setup_list():
1300 - "sure.with_context() accepts a list of callbacks for setup"
1301
1302 - def setup1(context):
1303 - context.first_name = "John"
1304 + def test_accepts_teardown_list(self):
1305 + "sure.with_context() runs teardown before the function itself"
1306
1307 - def setup2(context):
1308 - context.last_name = "Resig"
1309 + class something:
1310 + modified = True
1311 + finished = 'nope'
1312
1313 - @sure.that_with_context([setup1, setup2])
1314 - def john_is_within_context(context):
1315 - assert context.first_name == 'John'
1316 - assert context.last_name == 'Resig'
1317 + def setup(context):
1318 + something.modified = False
1319
1320 - john_is_within_context()
1321 - assert_equals(
1322 - john_is_within_context.__name__,
1323 - 'john_is_within_context',
1324 - )
1325 + def teardown1(context):
1326 + something.modified = True
1327
1328 + def teardown2(context):
1329 + something.finished = 'yep'
1330
1331 -def test_accepts_teardown_list():
1332 - "sure.with_context() runs teardown before the function itself"
1333 + @sure.that_with_context(setup, [teardown1, teardown2])
1334 + def something_was_modified(context):
1335 + assert not something.modified
1336 + assert something.finished == 'nope'
1337
1338 - class something:
1339 - modified = True
1340 - finished = 'nope'
1341 + something_was_modified()
1342 + assert something.modified
1343 + assert something.finished == 'yep'
1344
1345 - def setup(context):
1346 - something.modified = False
1347
1348 - def teardown1(context):
1349 - something.modified = True
1350 + def test_scenario_is_alias_for_context_on_setup_and_teardown(self):
1351 + "@scenario aliases @that_with_context for setup and teardown"
1352 + from sure import scenario
1353 +
1354 + def setup(context):
1355 + context.name = "Robert C Martin"
1356 +
1357 + def teardown(context):
1358 + self.assertEqual(context.name, "Robert C Martin")
1359 +
1360 + @scenario([setup], [teardown])
1361 + def robert_is_within_context(context):
1362 + "Robert is within context"
1363 + assert isinstance(context, VariablesBag)
1364 + assert hasattr(context, "name")
1365 + self.assertEqual(context.name, "Robert C Martin")
1366 +
1367 + robert_is_within_context()
1368 + self.assertEqual(
1369 + robert_is_within_context.__name__,
1370 + 'robert_is_within_context',
1371 + )
1372
1373 - def teardown2(context):
1374 - something.finished = 'yep'
1375
1376 - @sure.that_with_context(setup, [teardown1, teardown2])
1377 - def something_was_modified(context):
1378 - assert not something.modified
1379 - assert something.finished == 'nope'
1380 + def test_actions_returns_context(self):
1381 + "the actions always returns the context"
1382 + from sure import action_for, scenario
1383
1384 - something_was_modified()
1385 - assert something.modified
1386 - assert something.finished == 'yep'
1387 + def with_setup(context):
1388 + @action_for(context)
1389 + def action1():
1390 + pass
1391
1392 + @action_for(context)
1393 + def action2():
1394 + pass
1395
1396 -def test_scenario_is_alias_for_context_on_setup_and_teardown():
1397 - "@scenario aliases @that_with_context for setup and teardown"
1398 - from sure import scenario
1399 + @scenario(with_setup)
1400 + def i_can_use_actions(context):
1401 + assert that(context.action1()).equals(context)
1402 + assert that(context.action2()).equals(context)
1403 + return True
1404
1405 - def setup(context):
1406 - context.name = "Robert C Martin"
1407 + assert i_can_use_actions()
1408
1409 - def teardown(context):
1410 - assert_equals(context.name, "Robert C Martin")
1411
1412 - @scenario([setup], [teardown])
1413 - def robert_is_within_context(context):
1414 - "Robert is within context"
1415 - assert isinstance(context, VariablesBag)
1416 - assert hasattr(context, "name")
1417 - assert_equals(context.name, "Robert C Martin")
1418 + def test_actions_providing_variables_in_the_context(self):
1419 + "the actions should be able to declare the variables they provide"
1420 + from sure import action_for, scenario
1421
1422 - robert_is_within_context()
1423 - assert_equals(
1424 - robert_is_within_context.__name__,
1425 - 'robert_is_within_context',
1426 - )
1427 + def with_setup(context):
1428 + @action_for(context, provides=['var1', 'foobar'])
1429 + def the_context_has_variables():
1430 + context.var1 = 123
1431 + context.foobar = "qwerty"
1432
1433 + @scenario(with_setup)
1434 + def the_providers_are_working(Then):
1435 + Then.the_context_has_variables()
1436 + assert hasattr(Then, 'var1')
1437 + assert hasattr(Then, 'foobar')
1438 + assert hasattr(Then, '__sure_providers_of__')
1439
1440 -def test_actions_returns_context():
1441 - "the actions always returns the context"
1442 - from sure import action_for, scenario
1443 + providers = Then.__sure_providers_of__
1444 + action = Then.the_context_has_variables.__name__
1445
1446 - def with_setup(context):
1447 - @action_for(context)
1448 - def action1():
1449 - pass
1450 + providers_of_var1 = [p.__name__ for p in providers['var1']]
1451 + assert that(providers_of_var1).contains(action)
1452
1453 - @action_for(context)
1454 - def action2():
1455 - pass
1456 + providers_of_foobar = [p.__name__ for p in providers['foobar']]
1457 + assert that(providers_of_foobar).contains(action)
1458
1459 - @scenario(with_setup)
1460 - def i_can_use_actions(context):
1461 - assert that(context.action1()).equals(context)
1462 - assert that(context.action2()).equals(context)
1463 - return True
1464 + return True
1465
1466 - assert i_can_use_actions()
1467 + assert the_providers_are_working()
1468
1469
1470 -def test_actions_providing_variables_in_the_context():
1471 - "the actions should be able to declare the variables they provide"
1472 - from sure import action_for, scenario
1473 + def test_fails_when_action_doesnt_fulfill_the_agreement_of_provides(self):
1474 + "it fails when an action doesn't fulfill its agreements"
1475 + from sure import action_for, scenario
1476
1477 - def with_setup(context):
1478 - @action_for(context, provides=['var1', 'foobar'])
1479 - def the_context_has_variables():
1480 - context.var1 = 123
1481 - context.foobar = "qwerty"
1482 + error = 'the action "bad_action" was supposed to provide the ' \
1483 + 'attribute "two" into the context, but it did not. Please ' \
1484 + 'double check its implementation'
1485
1486 - @scenario(with_setup)
1487 - def the_providers_are_working(Then):
1488 - Then.the_context_has_variables()
1489 - assert hasattr(Then, 'var1')
1490 - assert hasattr(Then, 'foobar')
1491 - assert hasattr(Then, '__sure_providers_of__')
1492 + def with_setup(context):
1493 + @action_for(context, provides=['one', 'two'])
1494 + def bad_action():
1495 + context.one = 123
1496
1497 - providers = Then.__sure_providers_of__
1498 - action = Then.the_context_has_variables.__name__
1499 + @scenario(with_setup)
1500 + def the_providers_are_working(the):
1501 + assert that(the.bad_action).raises(AssertionError, error)
1502 + return True
1503
1504 - providers_of_var1 = [p.__name__ for p in providers['var1']]
1505 - assert that(providers_of_var1).contains(action)
1506 + assert the_providers_are_working()
1507
1508 - providers_of_foobar = [p.__name__ for p in providers['foobar']]
1509 - assert that(providers_of_foobar).contains(action)
1510
1511 - return True
1512 + def test_depends_on_failing_due_nothing_found(self):
1513 + "it fails when an action depends on some attribute that is not " \
1514 + "provided by any other previous action"
1515 + import os
1516 + from sure import action_for, scenario
1517
1518 - assert the_providers_are_working()
1519 + fullpath = os.path.abspath(__file__).replace('.pyc', '.py')
1520 + error = 'the action "lonely_action" defined at %s:926 ' \
1521 + 'depends on the attribute "something" to be available in the' \
1522 + ' context. It turns out that there are no actions providing ' \
1523 + 'that. Please double-check the implementation' % fullpath
1524
1525 + def with_setup(context):
1526 + @action_for(context, depends_on=['something'])
1527 + def lonely_action():
1528 + pass
1529
1530 -def test_fails_when_action_doesnt_fulfill_the_agreement_of_provides():
1531 - "it fails when an action doesn't fulfill its agreements"
1532 - from sure import action_for, scenario
1533 + @scenario(with_setup)
1534 + def depends_on_fails(the):
1535 + assert that(the.lonely_action).raises(AssertionError, error)
1536 + return True
1537
1538 - error = 'the action "bad_action" was supposed to provide the ' \
1539 - 'attribute "two" into the context, but it did not. Please ' \
1540 - 'double check its implementation'
1541 + assert depends_on_fails()
1542
1543 - def with_setup(context):
1544 - @action_for(context, provides=['one', 'two'])
1545 - def bad_action():
1546 - context.one = 123
1547
1548 - @scenario(with_setup)
1549 - def the_providers_are_working(the):
1550 - assert that(the.bad_action).raises(AssertionError, error)
1551 - return True
1552 + def test_depends_on_failing_due_not_calling_a_previous_action(self):
1553 + "it fails when an action depends on some attribute that is being " \
1554 + "provided by other actions"
1555
1556 - assert the_providers_are_working()
1557 + import os
1558 + from sure import action_for, scenario
1559
1560 + fullpath = os.path.abspath(__file__).replace('.pyc', '.py')
1561 + error = 'the action "my_action" defined at {0}:956 ' \
1562 + 'depends on the attribute "some_attr" to be available in the context.'\
1563 + ' You need to call one of the following actions beforehand:\n' \
1564 + ' -> dependency_action at {0}:952'.replace('{0}', fullpath)
1565
1566 -def test_depends_on_failing_due_nothing_found():
1567 - "it fails when an action depends on some attribute that is not " \
1568 - "provided by any other previous action"
1569 - import os
1570 - from sure import action_for, scenario
1571 + def with_setup(context):
1572 + @action_for(context, provides=['some_attr'])
1573 + def dependency_action():
1574 + context.some_attr = True
1575
1576 - fullpath = os.path.abspath(__file__).replace('.pyc', '.py')
1577 - error = 'the action "lonely_action" defined at %s:926 ' \
1578 - 'depends on the attribute "something" to be available in the' \
1579 - ' context. It turns out that there are no actions providing ' \
1580 - 'that. Please double-check the implementation' % fullpath
1581 + @action_for(context, depends_on=['some_attr'])
1582 + def my_action():
1583 + pass
1584
1585 - def with_setup(context):
1586 - @action_for(context, depends_on=['something'])
1587 - def lonely_action():
1588 - pass
1589 + @scenario(with_setup)
1590 + def depends_on_fails(the):
1591 + assert that(the.my_action).raises(AssertionError, error)
1592 + return True
1593
1594 - @scenario(with_setup)
1595 - def depends_on_fails(the):
1596 - assert that(the.lonely_action).raises(AssertionError, error)
1597 - return True
1598 -
1599 - assert depends_on_fails()
1600 -
1601 -
1602 -def test_depends_on_failing_due_not_calling_a_previous_action():
1603 - "it fails when an action depends on some attribute that is being " \
1604 - "provided by other actions"
1605 -
1606 - import os
1607 - from sure import action_for, scenario
1608 -
1609 - fullpath = os.path.abspath(__file__).replace('.pyc', '.py')
1610 - error = 'the action "my_action" defined at {0}:956 ' \
1611 - 'depends on the attribute "some_attr" to be available in the context.'\
1612 - ' You need to call one of the following actions beforehand:\n' \
1613 - ' -> dependency_action at {0}:952'.replace('{0}', fullpath)
1614 -
1615 - def with_setup(context):
1616 - @action_for(context, provides=['some_attr'])
1617 - def dependency_action():
1618 - context.some_attr = True
1619 + assert depends_on_fails()
1620
1621 - @action_for(context, depends_on=['some_attr'])
1622 - def my_action():
1623 - pass
1624
1625 - @scenario(with_setup)
1626 - def depends_on_fails(the):
1627 - assert that(the.my_action).raises(AssertionError, error)
1628 - return True
1629 + def test_that_contains_dictionary_keys(self):
1630 + "that(dict(name='foobar')).contains('name')"
1631
1632 - assert depends_on_fails()
1633 + data = dict(name='foobar')
1634 + assert 'name' in data
1635 + assert 'name' in data.keys()
1636 + assert that(data).contains('name')
1637
1638
1639 -def test_that_contains_dictionary_keys():
1640 - "that(dict(name='foobar')).contains('name')"
1641 + def test_that_contains_list(self):
1642 + "that(['foobar', '123']).contains('foobar')"
1643
1644 - data = dict(name='foobar')
1645 - assert 'name' in data
1646 - assert 'name' in data.keys()
1647 - assert that(data).contains('name')
1648 + data = ['foobar', '123']
1649 + assert 'foobar' in data
1650 + assert that(data).contains('foobar')
1651
1652
1653 -def test_that_contains_list():
1654 - "that(['foobar', '123']).contains('foobar')"
1655 + def test_that_contains_set(self):
1656 + "that(set(['foobar', '123']).contains('foobar')"
1657
1658 - data = ['foobar', '123']
1659 - assert 'foobar' in data
1660 - assert that(data).contains('foobar')
1661 + data = set(['foobar', '123'])
1662 + assert 'foobar' in data
1663 + assert that(data).contains('foobar')
1664
1665
1666 -def test_that_contains_set():
1667 - "that(set(['foobar', '123']).contains('foobar')"
1668 + def test_that_contains_tuple(self):
1669 + "that(('foobar', '123')).contains('foobar')"
1670
1671 - data = set(['foobar', '123'])
1672 - assert 'foobar' in data
1673 - assert that(data).contains('foobar')
1674 + data = ('foobar', '123')
1675 + assert 'foobar' in data
1676 + assert that(data).contains('foobar')
1677
1678
1679 -def test_that_contains_tuple():
1680 - "that(('foobar', '123')).contains('foobar')"
1681 + def test_variables_bag_provides_meaningful_error_on_nonexisting_attribute(self):
1682 + "VariablesBag() provides a meaningful error when attr does not exist"
1683
1684 - data = ('foobar', '123')
1685 - assert 'foobar' in data
1686 - assert that(data).contains('foobar')
1687 + context = VariablesBag()
1688
1689 + context.name = "John"
1690 + context.foo = "bar"
1691
1692 -def test_variables_bag_provides_meaningful_error_on_nonexisting_attribute():
1693 - "VariablesBag() provides a meaningful error when attr does not exist"
1694 + assert that(context.name).equals("John")
1695 + assert that(context.foo).equals("bar")
1696
1697 - context = VariablesBag()
1698 + def access_nonexisting_attr():
1699 + assert context.bleh == 'crash :('
1700
1701 - context.name = "John"
1702 - context.foo = "bar"
1703 + assert that(access_nonexisting_attr).raises(
1704 + AssertionError,
1705 + 'you have tried to access the attribute \'bleh\' from the context ' \
1706 + '(aka VariablesBag), but there is no such attribute assigned to it. ' \
1707 + 'Maybe you misspelled it ? Well, here are the options: ' \
1708 + '[\'name\', \'foo\']',
1709 + )
1710
1711 - assert that(context.name).equals("John")
1712 - assert that(context.foo).equals("bar")
1713
1714 - def access_nonexisting_attr():
1715 - assert context.bleh == 'crash :('
1716 + def test_actions_providing_dinamically_named_variables(self):
1717 + "the actions should be able to declare the variables they provide"
1718 + from sure import action_for, scenario
1719
1720 - assert that(access_nonexisting_attr).raises(
1721 - AssertionError,
1722 - 'you have tried to access the attribute \'bleh\' from the context ' \
1723 - '(aka VariablesBag), but there is no such attribute assigned to it. ' \
1724 - 'Maybe you misspelled it ? Well, here are the options: ' \
1725 - '[\'name\', \'foo\']',
1726 - )
1727 + def with_setup(context):
1728 + @action_for(context, provides=['var1', '{0}'])
1729 + def the_context_has_variables(first_arg):
1730 + context.var1 = 123
1731 + context[first_arg] = "qwerty"
1732
1733 + @scenario(with_setup)
1734 + def the_providers_are_working(Then):
1735 + Then.the_context_has_variables('JohnDoe')
1736 + assert hasattr(Then, 'var1')
1737 + assert 'JohnDoe' in Then
1738 + assert hasattr(Then, '__sure_providers_of__')
1739
1740 -def test_actions_providing_dinamically_named_variables():
1741 - "the actions should be able to declare the variables they provide"
1742 - from sure import action_for, scenario
1743 + providers = Then.__sure_providers_of__
1744 + action = Then.the_context_has_variables.__name__
1745
1746 - def with_setup(context):
1747 - @action_for(context, provides=['var1', '{0}'])
1748 - def the_context_has_variables(first_arg):
1749 - context.var1 = 123
1750 - context[first_arg] = "qwerty"
1751 + providers_of_var1 = [p.__name__ for p in providers['var1']]
1752 + assert that(providers_of_var1).contains(action)
1753
1754 - @scenario(with_setup)
1755 - def the_providers_are_working(Then):
1756 - Then.the_context_has_variables('JohnDoe')
1757 - assert hasattr(Then, 'var1')
1758 - assert 'JohnDoe' in Then
1759 - assert hasattr(Then, '__sure_providers_of__')
1760 + providers_of_JohnDoe = [p.__name__ for p in providers['JohnDoe']]
1761 + assert that(providers_of_JohnDoe).contains(action)
1762
1763 - providers = Then.__sure_providers_of__
1764 - action = Then.the_context_has_variables.__name__
1765 + return True
1766
1767 - providers_of_var1 = [p.__name__ for p in providers['var1']]
1768 - assert that(providers_of_var1).contains(action)
1769 + assert the_providers_are_working()
1770
1771 - providers_of_JohnDoe = [p.__name__ for p in providers['JohnDoe']]
1772 - assert that(providers_of_JohnDoe).contains(action)
1773
1774 - return True
1775 + def test_deep_equals_dict_level1_success(self):
1776 + "that() deep_equals(dict) succeeding on level 1"
1777
1778 - assert the_providers_are_working()
1779 + something = {
1780 + 'one': 'yeah',
1781 + }
1782
1783 + assert that(something).deep_equals({
1784 + 'one': 'yeah',
1785 + })
1786
1787 -def test_deep_equals_dict_level1_success():
1788 - "that() deep_equals(dict) succeeding on level 1"
1789
1790 - something = {
1791 - 'one': 'yeah',
1792 - }
1793 + def test_deep_equals_dict_level1_fail(self):
1794 + "that() deep_equals(dict) failing on level 1"
1795
1796 - assert that(something).deep_equals({
1797 - 'one': 'yeah',
1798 - })
1799 + something = {
1800 + 'one': 'yeah',
1801 + }
1802
1803 + def assertions():
1804 + assert that(something).deep_equals({
1805 + 'one': 'oops',
1806 + })
1807 +
1808 + assert that(assertions).raises(
1809 + AssertionError, compat_repr(
1810 + "given\n" \
1811 + "X = {'one': 'yeah'}\n" \
1812 + " and\n" \
1813 + "Y = {'one': 'oops'}\n" \
1814 + "X['one'] is 'yeah' whereas Y['one'] is 'oops'",
1815 + ))
1816
1817 -def test_deep_equals_dict_level1_fail():
1818 - "that() deep_equals(dict) failing on level 1"
1819
1820 - something = {
1821 - 'one': 'yeah',
1822 - }
1823 + def test_deep_equals_list_level1_success(self):
1824 + "that(list) deep_equals(list) succeeding on level 1"
1825
1826 - def assertions():
1827 - assert that(something).deep_equals({
1828 - 'one': 'oops',
1829 - })
1830 + something = ['one', 'yeah']
1831 + assert that(something).deep_equals(['one', 'yeah'])
1832
1833 - assert that(assertions).raises(
1834 - AssertionError, compat_repr(
1835 - "given\n" \
1836 - "X = {'one': 'yeah'}\n" \
1837 - " and\n" \
1838 - "Y = {'one': 'oops'}\n" \
1839 - "X['one'] is 'yeah' whereas Y['one'] is 'oops'",
1840 - ))
1841
1842 + def test_deep_equals_list_level1_fail_by_value(self):
1843 + "that(list) deep_equals(list) failing on level 1"
1844
1845 -def test_deep_equals_list_level1_success():
1846 - "that(list) deep_equals(list) succeeding on level 1"
1847 + something = ['one', 'yeahs']
1848
1849 - something = ['one', 'yeah']
1850 - assert that(something).deep_equals(['one', 'yeah'])
1851 + def assertions():
1852 + assert that(something).deep_equals(['one', 'yeah'])
1853
1854 + assert that(assertions).raises(
1855 + AssertionError, compat_repr(
1856 + "given\n" \
1857 + "X = ['one', 'yeahs']\n" \
1858 + " and\n" \
1859 + "Y = ['one', 'yeah']\n" \
1860 + "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
1861 + ))
1862
1863 -def test_deep_equals_list_level1_fail_by_value():
1864 - "that(list) deep_equals(list) failing on level 1"
1865
1866 - something = ['one', 'yeahs']
1867 + def test_deep_equals_list_level1_fail_by_length_x_gt_y(self):
1868 + "that(list) deep_equals(list) failing by length (len(X) > len(Y))"
1869
1870 - def assertions():
1871 - assert that(something).deep_equals(['one', 'yeah'])
1872 + something = ['one', 'yeah', 'awesome!']
1873
1874 - assert that(assertions).raises(
1875 - AssertionError, compat_repr(
1876 - "given\n" \
1877 - "X = ['one', 'yeahs']\n" \
1878 - " and\n" \
1879 - "Y = ['one', 'yeah']\n" \
1880 - "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
1881 - ))
1882 + def assertions():
1883 + assert that(something).deep_equals(['one', 'yeah'])
1884
1885 + assert that(assertions).raises(
1886 + AssertionError, compat_repr(
1887 + "given\n" \
1888 + "X = ['one', 'yeah', 'awesome!']\n" \
1889 + " and\n" \
1890 + "Y = ['one', 'yeah']\n" \
1891 + "X has 3 items whereas Y has only 2",
1892 + ))
1893
1894 -def test_deep_equals_list_level1_fail_by_length_x_gt_y():
1895 - "that(list) deep_equals(list) failing by length (len(X) > len(Y))"
1896
1897 - something = ['one', 'yeah', 'awesome!']
1898 + def test_deep_equals_list_level1_fail_by_length_y_gt_x(self):
1899 + "that(list) deep_equals(list) failing by length (len(Y) > len(X))"
1900
1901 - def assertions():
1902 - assert that(something).deep_equals(['one', 'yeah'])
1903 + something = ['one', 'yeah']
1904
1905 - assert that(assertions).raises(
1906 - AssertionError, compat_repr(
1907 - "given\n" \
1908 - "X = ['one', 'yeah', 'awesome!']\n" \
1909 - " and\n" \
1910 - "Y = ['one', 'yeah']\n" \
1911 - "X has 3 items whereas Y has only 2",
1912 - ))
1913 -
1914 -
1915 -def test_deep_equals_list_level1_fail_by_length_y_gt_x():
1916 - "that(list) deep_equals(list) failing by length (len(Y) > len(X))"
1917 + def assertions():
1918 + assert that(something).deep_equals(['one', 'yeah', 'damn'])
1919
1920 - something = ['one', 'yeah']
1921 + assert that(assertions).raises(
1922 + AssertionError, compat_repr(
1923 + "given\n"
1924 + "X = ['one', 'yeah']\n"
1925 + " and\n"
1926 + "Y = ['one', 'yeah', 'damn']\n"
1927 + "Y has 3 items whereas X has only 2"
1928 + )
1929 + )
1930
1931 - def assertions():
1932 - assert that(something).deep_equals(['one', 'yeah', 'damn'])
1933
1934 - assert that(assertions).raises(
1935 - AssertionError, compat_repr(
1936 - "given\n"
1937 - "X = ['one', 'yeah']\n"
1938 - " and\n"
1939 - "Y = ['one', 'yeah', 'damn']\n"
1940 - "Y has 3 items whereas X has only 2"
1941 - )
1942 - )
1943 + def test_deep_equals_dict_level1_fails_missing_key_on_y(self):
1944 + "that(X) deep_equals(Y) fails when Y is missing a key that X has"
1945
1946 + something = {
1947 + 'one': 'yeah',
1948 + }
1949
1950 -def test_deep_equals_dict_level1_fails_missing_key_on_y():
1951 - "that(X) deep_equals(Y) fails when Y is missing a key that X has"
1952 + def assertions():
1953 + assert that(something).deep_equals({
1954 + 'two': 'yeah',
1955 + })
1956 +
1957 + assert that(assertions).raises(
1958 + AssertionError, compat_repr(
1959 + "given\n"
1960 + "X = {{'one': 'yeah'}}\n"
1961 + " and\n"
1962 + "Y = {{'two': 'yeah'}}\n"
1963 + "X has the key \"{0}\" whereas Y does not"
1964 + ).format(safe_repr('one'))
1965 + )
1966
1967 - something = {
1968 - 'one': 'yeah',
1969 - }
1970
1971 - def assertions():
1972 - assert that(something).deep_equals({
1973 - 'two': 'yeah',
1974 - })
1975 + def test_deep_equals_failing_basic_vs_complex(self):
1976 + "that(X) deep_equals(Y) fails with basic vc complex type"
1977
1978 - assert that(assertions).raises(
1979 - AssertionError, compat_repr(
1980 - "given\n"
1981 - "X = {{'one': 'yeah'}}\n"
1982 - " and\n"
1983 - "Y = {{'two': 'yeah'}}\n"
1984 - "X has the key \"{0}\" whereas Y does not"
1985 - ).format(safe_repr('one'))
1986 - )
1987 + def assertions():
1988 + assert that('two yeah').deep_equals({
1989 + 'two': 'yeah',
1990 + })
1991 +
1992 + assert that(assertions).raises(
1993 + AssertionError, compat_repr(
1994 + "given\n" \
1995 + "X = 'two yeah'\n"
1996 + " and\n" \
1997 + "Y = {'two': 'yeah'}\n" \
1998 + "X is a %s and Y is a dict instead" % text_type_name,
1999 + ))
2000 +
2001 +
2002 + def test_deep_equals_failing_complex_vs_basic(self):
2003 + "that(X) deep_equals(Y) fails with complex vc basic type"
2004 +
2005 + def assertions():
2006 + assert that({'two': 'yeah'}).deep_equals('two yeah')
2007 +
2008 + assert that(assertions).raises(
2009 + AssertionError, compat_repr(
2010 + "given\n" \
2011 + "X = {'two': 'yeah'}\n" \
2012 + " and\n" \
2013 + "Y = 'two yeah'\n"
2014 + "X is a dict and Y is a %s instead" % text_type_name,
2015 + ))
2016
2017
2018 -def test_deep_equals_failing_basic_vs_complex():
2019 - "that(X) deep_equals(Y) fails with basic vc complex type"
2020 -
2021 - def assertions():
2022 - assert that('two yeah').deep_equals({
2023 - 'two': 'yeah',
2024 - })
2025 + def test_deep_equals_tuple_level1_success(self):
2026 + "that(tuple) deep_equals(tuple) succeeding on level 1"
2027
2028 - assert that(assertions).raises(
2029 - AssertionError, compat_repr(
2030 - "given\n" \
2031 - "X = 'two yeah'\n"
2032 - " and\n" \
2033 - "Y = {'two': 'yeah'}\n" \
2034 - "X is a %s and Y is a dict instead" % text_type_name,
2035 - ))
2036 + something = ('one', 'yeah')
2037 + assert that(something).deep_equals(('one', 'yeah'))
2038
2039
2040 -def test_deep_equals_failing_complex_vs_basic():
2041 - "that(X) deep_equals(Y) fails with complex vc basic type"
2042 + def test_deep_equals_tuple_level1_fail_by_value(self):
2043 + "that(tuple) deep_equals(tuple) failing on level 1"
2044
2045 - def assertions():
2046 - assert that({'two': 'yeah'}).deep_equals('two yeah')
2047 + something = ('one', 'yeahs')
2048
2049 - assert that(assertions).raises(
2050 - AssertionError, compat_repr(
2051 - "given\n" \
2052 - "X = {'two': 'yeah'}\n" \
2053 - " and\n" \
2054 - "Y = 'two yeah'\n"
2055 - "X is a dict and Y is a %s instead" % text_type_name,
2056 - ))
2057 + def assertions():
2058 + assert that(something).deep_equals(('one', 'yeah'))
2059
2060 + assert that(assertions).raises(
2061 + AssertionError, compat_repr(
2062 + "given\n" \
2063 + "X = ('one', 'yeahs')\n" \
2064 + " and\n" \
2065 + "Y = ('one', 'yeah')\n" \
2066 + "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
2067 + ))
2068
2069 -def test_deep_equals_tuple_level1_success():
2070 - "that(tuple) deep_equals(tuple) succeeding on level 1"
2071
2072 - something = ('one', 'yeah')
2073 - assert that(something).deep_equals(('one', 'yeah'))
2074 + def test_deep_equals_tuple_level1_fail_by_length_x_gt_y(self):
2075 + "that(tuple) deep_equals(tuple) failing by length (len(X) > len(Y))"
2076
2077 + something = ('one', 'yeah', 'awesome!')
2078
2079 -def test_deep_equals_tuple_level1_fail_by_value():
2080 - "that(tuple) deep_equals(tuple) failing on level 1"
2081 + def assertions():
2082 + assert that(something).deep_equals(('one', 'yeah'))
2083
2084 - something = ('one', 'yeahs')
2085 + assert that(assertions).raises(
2086 + AssertionError, compat_repr(
2087 + "given\n" \
2088 + "X = ('one', 'yeah', 'awesome!')\n" \
2089 + " and\n" \
2090 + "Y = ('one', 'yeah')\n" \
2091 + "X has 3 items whereas Y has only 2",
2092 + ))
2093
2094 - def assertions():
2095 - assert that(something).deep_equals(('one', 'yeah'))
2096
2097 - assert that(assertions).raises(
2098 - AssertionError, compat_repr(
2099 - "given\n" \
2100 - "X = ('one', 'yeahs')\n" \
2101 - " and\n" \
2102 - "Y = ('one', 'yeah')\n" \
2103 - "X[1] is 'yeahs' whereas Y[1] is 'yeah'",
2104 - ))
2105 + def test_deep_equals_tuple_level1_fail_by_length_y_gt_x(self):
2106 + "that(tuple) deep_equals(tuple) failing by length (len(Y) > len(X))"
2107
2108 + something = ('one', 'yeah')
2109
2110 -def test_deep_equals_tuple_level1_fail_by_length_x_gt_y():
2111 - "that(tuple) deep_equals(tuple) failing by length (len(X) > len(Y))"
2112 + def assertions():
2113 + assert that(something).deep_equals(('one', 'yeah', 'damn'))
2114
2115 - something = ('one', 'yeah', 'awesome!')
2116 + assert that(assertions).raises(
2117 + AssertionError, compat_repr(
2118 + "given\n" \
2119 + "X = ('one', 'yeah')\n" \
2120 + " and\n" \
2121 + "Y = ('one', 'yeah', 'damn')\n" \
2122 + "Y has 3 items whereas X has only 2",
2123 + ))
2124
2125 - def assertions():
2126 - assert that(something).deep_equals(('one', 'yeah'))
2127
2128 - assert that(assertions).raises(
2129 - AssertionError, compat_repr(
2130 - "given\n" \
2131 - "X = ('one', 'yeah', 'awesome!')\n" \
2132 - " and\n" \
2133 - "Y = ('one', 'yeah')\n" \
2134 - "X has 3 items whereas Y has only 2",
2135 - ))
2136 -
2137 -
2138 -def test_deep_equals_tuple_level1_fail_by_length_y_gt_x():
2139 - "that(tuple) deep_equals(tuple) failing by length (len(Y) > len(X))"
2140 -
2141 - something = ('one', 'yeah')
2142 -
2143 - def assertions():
2144 - assert that(something).deep_equals(('one', 'yeah', 'damn'))
2145 -
2146 - assert that(assertions).raises(
2147 - AssertionError, compat_repr(
2148 - "given\n" \
2149 - "X = ('one', 'yeah')\n" \
2150 - " and\n" \
2151 - "Y = ('one', 'yeah', 'damn')\n" \
2152 - "Y has 3 items whereas X has only 2",
2153 - ))
2154 -
2155 -
2156 -def test_deep_equals_fallsback_to_generic_comparator():
2157 - "that() deep_equals(dict) falling back to generic comparator"
2158 - from datetime import datetime
2159 - now = datetime.now()
2160 - something = {
2161 - 'one': 'yeah',
2162 - 'date': now,
2163 - }
2164 -
2165 - assert that(something).deep_equals({
2166 - 'one': 'yeah',
2167 - 'date': now,
2168 - })
2169 -
2170 -
2171 -def test_deep_equals_fallsback_to_generic_comparator_failing():
2172 - "that() deep_equals(dict) with generic comparator failing"
2173 - from datetime import datetime
2174 - now = datetime(2012, 3, 5)
2175 - tomorrow = datetime(2012, 3, 6)
2176 - something = {
2177 - 'date': now,
2178 - }
2179 + def test_deep_equals_fallsback_to_generic_comparator(self):
2180 + "that() deep_equals(dict) falling back to generic comparator"
2181 + from datetime import datetime
2182 + now = datetime.now()
2183 + something = {
2184 + 'one': 'yeah',
2185 + 'date': now,
2186 + }
2187
2188 - def assertions():
2189 assert that(something).deep_equals({
2190 - 'date': tomorrow,
2191 + 'one': 'yeah',
2192 + 'date': now,
2193 })
2194
2195 - assert that(assertions).raises(
2196 - AssertionError, compat_repr(
2197 - "given\n" \
2198 - "X = {'date': datetime.datetime(2012, 3, 5, 0, 0)}\n" \
2199 - " and\n" \
2200 - "Y = {'date': datetime.datetime(2012, 3, 6, 0, 0)}\n" \
2201 - "X['date'] != Y['date']",
2202 - ))
2203 -
2204 -
2205 -def test_deep_equals_fallsback_to_generic_comparator_failing_type():
2206 - "that() deep_equals(dict) with generic comparator failing"
2207 - from datetime import datetime
2208 - now = datetime(2012, 3, 5)
2209 - something = {
2210 - 'date': now,
2211 - }
2212
2213 - def assertions():
2214 - assert that(something).deep_equals({
2215 - 'date': None,
2216 - })
2217 + def test_deep_equals_fallsback_to_generic_comparator_failing(self):
2218 + "that() deep_equals(dict) with generic comparator failing"
2219 + from datetime import datetime
2220 + now = datetime(2012, 3, 5)
2221 + tomorrow = datetime(2012, 3, 6)
2222 + something = {
2223 + 'date': now,
2224 + }
2225 +
2226 + def assertions():
2227 + assert that(something).deep_equals({
2228 + 'date': tomorrow,
2229 + })
2230 +
2231 + assert that(assertions).raises(
2232 + AssertionError, compat_repr(
2233 + "given\n" \
2234 + "X = {'date': datetime.datetime(2012, 3, 5, 0, 0)}\n" \
2235 + " and\n" \
2236 + "Y = {'date': datetime.datetime(2012, 3, 6, 0, 0)}\n" \
2237 + "X['date'] != Y['date']",
2238 + ))
2239 +
2240 +
2241 + def test_deep_equals_fallsback_to_generic_comparator_failing_type(self):
2242 + "that() deep_equals(dict) with generic comparator failing"
2243 + from datetime import datetime
2244 + now = datetime(2012, 3, 5)
2245 + something = {
2246 + 'date': now,
2247 + }
2248 +
2249 + def assertions():
2250 + assert that(something).deep_equals({
2251 + 'date': None,
2252 + })
2253 +
2254 + assert that(assertions).raises(
2255 + AssertionError, compat_repr(
2256 + "given\n" \
2257 + "X = {'date': datetime.datetime(2012, 3, 5, 0, 0)}\n" \
2258 + " and\n" \
2259 + "Y = {'date': None}\n" \
2260 + "X['date'] is a datetime and Y['date'] is a NoneType instead",
2261 + ))
2262
2263 - assert that(assertions).raises(
2264 - AssertionError, compat_repr(
2265 - "given\n" \
2266 - "X = {'date': datetime.datetime(2012, 3, 5, 0, 0)}\n" \
2267 - " and\n" \
2268 - "Y = {'date': None}\n" \
2269 - "X['date'] is a datetime and Y['date'] is a NoneType instead",
2270 - ))
2271 -
2272 -
2273 -def test_deep_equals_dict_level2_success():
2274 - "that() deep_equals(dict) succeeding on level 2"
2275 -
2276 - something = {
2277 - 'one': 'yeah',
2278 - 'another': {
2279 - 'two': 'cool',
2280 - },
2281 - }
2282 -
2283 - assert that(something).deep_equals({
2284 - 'one': 'yeah',
2285 - 'another': {
2286 - 'two': 'cool',
2287 - },
2288 - })
2289 -
2290 -
2291 -def test_deep_equals_dict_level2_list_success():
2292 - "that() deep_equals(dict) succeeding on level 2"
2293 -
2294 - something = {
2295 - 'one': 'yeah',
2296 - 'another': ['one', 'two', 3],
2297 - }
2298 -
2299 - assert that(something).deep_equals({
2300 - 'one': 'yeah',
2301 - 'another': ['one', 'two', 3],
2302 - })
2303 -
2304 -
2305 -def test_deep_equals_dict_level2_fail():
2306 - "that() deep_equals(dict) failing on level 2"
2307 -
2308 - something = {
2309 - 'one': 'yeah',
2310 - 'another': {
2311 - 'two': '##',
2312 - },
2313 - }
2314
2315 - def assertions():
2316 - assert that(something).deep_equals({
2317 + def test_deep_equals_dict_level2_success(self):
2318 + "that() deep_equals(dict) succeeding on level 2"
2319 +
2320 + something = {
2321 'one': 'yeah',
2322 'another': {
2323 - 'two': '$$',
2324 + 'two': 'cool',
2325 },
2326 - })
2327 - assert that(assertions).raises(
2328 - AssertionError, compat_repr(
2329 - "given\n" \
2330 - "X = {'another': {'two': '##'}, 'one': 'yeah'}\n" \
2331 - " and\n" \
2332 - "Y = {'another': {'two': '$$'}, 'one': 'yeah'}\n" \
2333 - "X['another']['two'] is '##' whereas Y['another']['two'] is '$$'",
2334 - ))
2335 -
2336 -
2337 -def test_deep_equals_dict_level3_fail_values():
2338 - "that() deep_equals(dict) failing on level 3"
2339 -
2340 - something = {
2341 - 'my::all_users': [
2342 - {'name': 'John', 'age': 33},
2343 - ],
2344 - }
2345 + }
2346
2347 - def assertions():
2348 assert that(something).deep_equals({
2349 - 'my::all_users': [
2350 - {'name': 'John', 'age': 30},
2351 - ],
2352 + 'one': 'yeah',
2353 + 'another': {
2354 + 'two': 'cool',
2355 + },
2356 })
2357
2358 - assert that(assertions).raises(
2359 - AssertionError, compat_repr(
2360 - "given\n" \
2361 - "X = {'my::all_users': [{'age': 33, 'name': 'John'}]}\n" \
2362 - " and\n" \
2363 - "Y = {'my::all_users': [{'age': 30, 'name': 'John'}]}\n" \
2364 - "X['my::all_users'][0]['age'] is 33 whereas Y['my::all_users'][0]['age'] is 30",
2365 - ))
2366 -
2367 -
2368 -def test_deep_equals_dict_level3_fails_missing_key():
2369 - "that() deep_equals(dict) failing on level 3 when missing a key"
2370 -
2371 - something = {
2372 - 'my::all_users': [
2373 - {'name': 'John', 'age': 33},
2374 - ],
2375 - }
2376
2377 - def assertions():
2378 - assert that(something).deep_equals({
2379 - 'my::all_users': [
2380 - {'name': 'John', 'age': 30, 'foo': 'bar'},
2381 - ],
2382 - })
2383 + def test_deep_equals_dict_level2_list_success(self):
2384 + "that() deep_equals(dict) succeeding on level 2"
2385
2386 - assert that(assertions).raises(
2387 - AssertionError, compat_repr(
2388 - "given\n"
2389 - "X = {{'my::all_users': [{{'age': 33, 'name': 'John'}}]}}\n"
2390 - " and\n"
2391 - "Y = {{'my::all_users': [{{'age': 30, 'foo': 'bar', 'name': 'John'}}]}}\n"
2392 - "X['my::all_users'][0] does not have the key \"{0}\" whereas Y['my::all_users'][0] has it"
2393 - ).format(safe_repr('foo'))
2394 - )
2395 -
2396 -
2397 -def test_deep_equals_dict_level3_fails_extra_key():
2398 - "that() deep_equals(dict) failing on level 3 when has an extra key"
2399 -
2400 - something = {
2401 - 'my::all_users': [
2402 - {'name': 'John', 'age': 33, 'foo': 'bar'},
2403 - ],
2404 - }
2405 + something = {
2406 + 'one': 'yeah',
2407 + 'another': ['one', 'two', 3],
2408 + }
2409
2410 - def assertions():
2411 assert that(something).deep_equals({
2412 - 'my::all_users': [
2413 - {'name': 'John', 'age': 30},
2414 - ],
2415 + 'one': 'yeah',
2416 + 'another': ['one', 'two', 3],
2417 })
2418
2419 - assert that(assertions).raises(
2420 - AssertionError, compat_repr(
2421 - "given\n"
2422 - "X = {{'my::all_users': [{{'age': 33, 'foo': 'bar', 'name': 'John'}}]}}\n"
2423 - " and\n"
2424 - "Y = {{'my::all_users': [{{'age': 30, 'name': 'John'}}]}}\n"
2425 - "X['my::all_users'][0] has the key \"{0}\" whereas Y['my::all_users'][0] does not"
2426 - ).format(safe_repr('foo')))
2427 -
2428 -
2429 -def test_deep_equals_dict_level3_fails_different_key():
2430 - "that() deep_equals(dict) failing on level 3 when has an extra key"
2431 -
2432 - something = {
2433 - 'my::all_users': [
2434 - {'name': 'John', 'age': 33, 'foo': 'bar'},
2435 - ],
2436 - }
2437
2438 - def assertions():
2439 - assert that(something).deep_equals({
2440 - 'my::all_users': [
2441 - {'name': 'John', 'age': 33, 'bar': 'foo'},
2442 - ],
2443 - })
2444 + def test_deep_equals_dict_level2_fail(self):
2445 + "that() deep_equals(dict) failing on level 2"
2446
2447 - assert that(assertions).raises(
2448 - AssertionError, compat_repr(
2449 - "given\n"
2450 - "X = {{'my::all_users': [{{'age': 33, 'foo': 'bar', 'name': 'John'}}]}}\n"
2451 - " and\n"
2452 - "Y = {{'my::all_users': [{{'age': 33, 'bar': 'foo', 'name': 'John'}}]}}\n"
2453 - "X['my::all_users'][0] has the key \"{0}\" whereas Y['my::all_users'][0] does not"
2454 - ).format(safe_repr('foo')))
2455 + something = {
2456 + 'one': 'yeah',
2457 + 'another': {
2458 + 'two': '##',
2459 + },
2460 + }
2461
2462 + def assertions():
2463 + assert that(something).deep_equals({
2464 + 'one': 'yeah',
2465 + 'another': {
2466 + 'two': '$$',
2467 + },
2468 + })
2469 + assert that(assertions).raises(
2470 + AssertionError, compat_repr(
2471 + "given\n" \
2472 + "X = {'another': {'two': '##'}, 'one': 'yeah'}\n" \
2473 + " and\n" \
2474 + "Y = {'another': {'two': '$$'}, 'one': 'yeah'}\n" \
2475 + "X['another']['two'] is '##' whereas Y['another']['two'] is '$$'",
2476 + ))
2477
2478 -def test_deep_equals_list_level2_fail_by_length_x_gt_y():
2479 - "that(list) deep_equals(list) failing by length (len(X) > len(Y))"
2480
2481 - something = {'iterable': ['one', 'yeah', 'awesome!']}
2482 + def test_deep_equals_dict_level3_fail_values(self):
2483 + "that() deep_equals(dict) failing on level 3"
2484
2485 - def assertions():
2486 - assert that(something).deep_equals({'iterable': ['one', 'yeah']})
2487 + something = {
2488 + 'my::all_users': [
2489 + {'name': 'John', 'age': 33},
2490 + ],
2491 + }
2492
2493 - assert that(assertions).raises(
2494 - AssertionError, compat_repr(
2495 - "given\n" \
2496 - "X = {'iterable': ['one', 'yeah', 'awesome!']}\n" \
2497 - " and\n" \
2498 - "Y = {'iterable': ['one', 'yeah']}\n" \
2499 - "X has 3 items whereas Y has only 2",
2500 - ))
2501 + def assertions():
2502 + assert that(something).deep_equals({
2503 + 'my::all_users': [
2504 + {'name': 'John', 'age': 30},
2505 + ],
2506 + })
2507 +
2508 + assert that(assertions).raises(
2509 + AssertionError, compat_repr(
2510 + "given\n" \
2511 + "X = {'my::all_users': [{'age': 33, 'name': 'John'}]}\n" \
2512 + " and\n" \
2513 + "Y = {'my::all_users': [{'age': 30, 'name': 'John'}]}\n" \
2514 + "X['my::all_users'][0]['age'] is 33 whereas Y['my::all_users'][0]['age'] is 30",
2515 + ))
2516
2517
2518 -def test_deep_equals_list_level2_fail_by_length_y_gt_x():
2519 - "that(list) deep_equals(list) failing by length (len(Y) > len(X))"
2520 + def test_deep_equals_dict_level3_fails_missing_key(self):
2521 + "that() deep_equals(dict) failing on level 3 when missing a key"
2522
2523 - something = ['one', 'yeah']
2524 + something = {
2525 + 'my::all_users': [
2526 + {'name': 'John', 'age': 33},
2527 + ],
2528 + }
2529
2530 - def assertions():
2531 - assert that(something).deep_equals(['one', 'yeah', 'damn'])
2532 + def assertions():
2533 + assert that(something).deep_equals({
2534 + 'my::all_users': [
2535 + {'name': 'John', 'age': 30, 'foo': 'bar'},
2536 + ],
2537 + })
2538 +
2539 + assert that(assertions).raises(
2540 + AssertionError, compat_repr(
2541 + "given\n"
2542 + "X = {{'my::all_users': [{{'age': 33, 'name': 'John'}}]}}\n"
2543 + " and\n"
2544 + "Y = {{'my::all_users': [{{'age': 30, 'foo': 'bar', 'name': 'John'}}]}}\n"
2545 + "X['my::all_users'][0] does not have the key \"{0}\" whereas Y['my::all_users'][0] has it"
2546 + ).format(safe_repr('foo'))
2547 + )
2548
2549 - assert that(assertions).raises(
2550 - AssertionError, compat_repr(
2551 - "given\n" \
2552 - "X = ['one', 'yeah']\n" \
2553 - " and\n" \
2554 - "Y = ['one', 'yeah', 'damn']\n" \
2555 - "Y has 3 items whereas X has only 2",
2556 - ))
2557
2558 + def test_deep_equals_dict_level3_fails_extra_key(self):
2559 + "that() deep_equals(dict) failing on level 3 when has an extra key"
2560
2561 -def test_function_decorated_with_wip_should_set_a_flag():
2562 - "@sure.work_in_progress should set an internal flag into `sure`"
2563 + something = {
2564 + 'my::all_users': [
2565 + {'name': 'John', 'age': 33, 'foo': 'bar'},
2566 + ],
2567 + }
2568
2569 - @sure.work_in_progress
2570 - def this_was_called():
2571 - assert sure.it('is_running')
2572 - return True
2573 + def assertions():
2574 + assert that(something).deep_equals({
2575 + 'my::all_users': [
2576 + {'name': 'John', 'age': 30},
2577 + ],
2578 + })
2579
2580 - assert not sure._registry['is_running']
2581 - assert this_was_called()
2582 - assert not sure._registry['is_running']
2583 + assert that(assertions).raises(
2584 + AssertionError, compat_repr(
2585 + "given\n"
2586 + "X = {{'my::all_users': [{{'age': 33, 'foo': 'bar', 'name': 'John'}}]}}\n"
2587 + " and\n"
2588 + "Y = {{'my::all_users': [{{'age': 30, 'name': 'John'}}]}}\n"
2589 + "X['my::all_users'][0] has the key \"{0}\" whereas Y['my::all_users'][0] does not"
2590 + ).format(safe_repr('foo')))
2591
2592
2593 -def test_that_equals_fails():
2594 - "that() equals(string) when it's supposed to fail"
2595 + def test_deep_equals_dict_level3_fails_different_key(self):
2596 + "that() deep_equals(dict) failing on level 3 when has an extra key"
2597
2598 - something = "else"
2599 + something = {
2600 + 'my::all_users': [
2601 + {'name': 'John', 'age': 33, 'foo': 'bar'},
2602 + ],
2603 + }
2604
2605 - def fail():
2606 - assert that('something').equals(something)
2607 + def assertions():
2608 + assert that(something).deep_equals({
2609 + 'my::all_users': [
2610 + {'name': 'John', 'age': 33, 'bar': 'foo'},
2611 + ],
2612 + })
2613
2614 - assert that(fail).raises(
2615 - AssertionError, compat_repr(
2616 - "given\n" \
2617 - "X = 'something'\n" \
2618 - " and\n" \
2619 - "Y = 'else'\n" \
2620 - "X is 'something' whereas Y is 'else'",
2621 - ))
2622 -
2623 -
2624 -def test_raises_with_string():
2625 - "that(callable).raises('message') should compare the message"
2626 -
2627 - def it_fails():
2628 - assert False, 'should fail with this exception'
2629 -
2630 - try:
2631 - that(it_fails).raises('wrong msg')
2632 - raise RuntimeError('should not reach here')
2633 - except AssertionError as e:
2634 - assert that(text_type(e)).contains('''EXPECTED:
2635 -wrong msg
2636 -
2637 -GOT:
2638 -should fail with this exception''')
2639 -
2640 -
2641 -def test_deep_equals_weird():
2642 - part1 = [
2643 - ('Bootstraping Redis role', []),
2644 - ('Restart scalarizr', []),
2645 - ('Rebundle server', ['rebundle']),
2646 - ('Use new role', ['rebundle']),
2647 - ('Restart scalarizr after bundling', ['rebundle']),
2648 - ('Bundling data', []),
2649 - ('Modifying data', []),
2650 - ('Reboot server', []),
2651 - ('Backuping data on Master', []),
2652 - ('Setup replication', []),
2653 - ('Restart scalarizr in slave', []),
2654 - ('Slave force termination', []),
2655 - ('Slave delete EBS', ['ec2']),
2656 - ('Setup replication for EBS test', ['ec2']),
2657 - ('Writing on Master, reading on Slave', []),
2658 - ('Slave -> Master promotion', []),
2659 - ('Restart farm', ['restart_farm']),
2660 - ]
2661 -
2662 - part2 = [
2663 - ('Bootstraping Redis role', ['rebundle', 'rebundle', 'rebundle']),
2664 - ('Restart scalarizr', []),
2665 - ('Rebundle server', ['rebundle']),
2666 - ('Use new role', ['rebundle']),
2667 - ('Restart scalarizr after bundling', ['rebundle']),
2668 - ('Bundling data', []),
2669 - ('Modifying data', []),
2670 - ('Reboot server', []),
2671 - ('Backuping data on Master', []),
2672 - ('Setup replication', []),
2673 - ('Restart scalarizr in slave', []),
2674 - ('Slave force termination', []),
2675 - ('Slave delete EBS', ['ec2']),
2676 - ('Setup replication for EBS test', ['ec2']),
2677 - ('Writing on Master, reading on Slave', []),
2678 - ('Slave -> Master promotion', []),
2679 - ('Restart farm', ['restart_farm']),
2680 - ]
2681 + assert that(assertions).raises(
2682 + AssertionError, compat_repr(
2683 + "given\n"
2684 + "X = {{'my::all_users': [{{'age': 33, 'foo': 'bar', 'name': 'John'}}]}}\n"
2685 + " and\n"
2686 + "Y = {{'my::all_users': [{{'age': 33, 'bar': 'foo', 'name': 'John'}}]}}\n"
2687 + "X['my::all_users'][0] has the key \"{0}\" whereas Y['my::all_users'][0] does not"
2688 + ).format(safe_repr('foo')))
2689 +
2690 +
2691 + def test_deep_equals_list_level2_fail_by_length_x_gt_y(self):
2692 + "that(list) deep_equals(list) failing by length (len(X) > len(Y))"
2693 +
2694 + something = {'iterable': ['one', 'yeah', 'awesome!']}
2695 +
2696 + def assertions():
2697 + assert that(something).deep_equals({'iterable': ['one', 'yeah']})
2698 +
2699 + assert that(assertions).raises(
2700 + AssertionError, compat_repr(
2701 + "given\n" \
2702 + "X = {'iterable': ['one', 'yeah', 'awesome!']}\n" \
2703 + " and\n" \
2704 + "Y = {'iterable': ['one', 'yeah']}\n" \
2705 + "X has 3 items whereas Y has only 2",
2706 + ))
2707 +
2708 +
2709 + def test_deep_equals_list_level2_fail_by_length_y_gt_x(self):
2710 + "that(list) deep_equals(list) failing by length (len(Y) > len(X))"
2711 +
2712 + something = ['one', 'yeah']
2713 +
2714 + def assertions():
2715 + assert that(something).deep_equals(['one', 'yeah', 'damn'])
2716 +
2717 + assert that(assertions).raises(
2718 + AssertionError, compat_repr(
2719 + "given\n" \
2720 + "X = ['one', 'yeah']\n" \
2721 + " and\n" \
2722 + "Y = ['one', 'yeah', 'damn']\n" \
2723 + "Y has 3 items whereas X has only 2",
2724 + ))
2725 +
2726 +
2727 + def test_function_decorated_with_wip_should_set_a_flag(self):
2728 + "@sure.work_in_progress should set an internal flag into `sure`"
2729 +
2730 + @sure.work_in_progress
2731 + def this_was_called():
2732 + assert sure.it('is_running')
2733 + return True
2734 +
2735 + assert not sure._registry['is_running']
2736 + assert this_was_called()
2737 + assert not sure._registry['is_running']
2738 +
2739 +
2740 + def test_that_equals_fails(self):
2741 + "that() equals(string) when it's supposed to fail"
2742 +
2743 + something = "else"
2744 +
2745 + def fail():
2746 + assert that('something').equals(something)
2747 +
2748 + assert that(fail).raises(
2749 + AssertionError, compat_repr(
2750 + "given\n" \
2751 + "X = 'something'\n" \
2752 + " and\n" \
2753 + "Y = 'else'\n" \
2754 + "X is 'something' whereas Y is 'else'",
2755 + ))
2756 +
2757 +
2758 + def test_deep_equals_weird(self):
2759 + part1 = [
2760 + ('Bootstraping Redis role', []),
2761 + ('Restart scalarizr', []),
2762 + ('Rebundle server', ['rebundle']),
2763 + ('Use new role', ['rebundle']),
2764 + ('Restart scalarizr after bundling', ['rebundle']),
2765 + ('Bundling data', []),
2766 + ('Modifying data', []),
2767 + ('Reboot server', []),
2768 + ('Backuping data on Master', []),
2769 + ('Setup replication', []),
2770 + ('Restart scalarizr in slave', []),
2771 + ('Slave force termination', []),
2772 + ('Slave delete EBS', ['ec2']),
2773 + ('Setup replication for EBS test', ['ec2']),
2774 + ('Writing on Master, reading on Slave', []),
2775 + ('Slave -> Master promotion', []),
2776 + ('Restart farm', ['restart_farm']),
2777 + ]
2778 +
2779 + part2 = [
2780 + ('Bootstraping Redis role', ['rebundle', 'rebundle', 'rebundle']),
2781 + ('Restart scalarizr', []),
2782 + ('Rebundle server', ['rebundle']),
2783 + ('Use new role', ['rebundle']),
2784 + ('Restart scalarizr after bundling', ['rebundle']),
2785 + ('Bundling data', []),
2786 + ('Modifying data', []),
2787 + ('Reboot server', []),
2788 + ('Backuping data on Master', []),
2789 + ('Setup replication', []),
2790 + ('Restart scalarizr in slave', []),
2791 + ('Slave force termination', []),
2792 + ('Slave delete EBS', ['ec2']),
2793 + ('Setup replication for EBS test', ['ec2']),
2794 + ('Writing on Master, reading on Slave', []),
2795 + ('Slave -> Master promotion', []),
2796 + ('Restart farm', ['restart_farm']),
2797 + ]
2798
2799 - expect(that(part1).equals).when.called_with(part2).should.throw("")
2800 + expect(that(part1).equals).when.called_with(part2).should.throw("")