| 1 |
Descriptionscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/patches/`switch-from-nose-to-pytest-and-unittest.patch`#Description.: Switch away from nose |
| 2 |
Authorscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/patches/`switch-from-nose-to-pytest-and-unittest.patch`#Author.: Thomas Goirand <[email protected]scip-debian . . . identity/`[email protected]`.> |
| 3 |
Bug-Debianscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/patches/`switch-from-nose-to-pytest-and-unittest.patch`#Bug-Debian.: https://bugs.debian.org/1018586scip-debian-bts debian-bts . . 1018586: |
| 4 |
Forwardedscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/patches/`switch-from-nose-to-pytest-and-unittest.patch`#Forwarded.: no |
| 5 |
Last-Updatescip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/patches/`switch-from-nose-to-pytest-and-unittest.patch`#Last-Update.: 2024-05-02 |
| 6 |
|
| 7 |
Index: python-sure/tests/test_old_api.pyscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/upstream/`python-sure/tests/test_old_api.py`: |
| 8 |
=================================================================== |
| 9 |
--- python-sure.orig/tests/test_old_api.pyscip-debian debian python-sure 2.0.1+git.2023.02.06.3aef950b7c-5 python-sure/upstream/`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 |
|
| 16 |
|
| 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 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
+ def test_context_is_not_optional(self): |
| 49 |
+ "sure.that_with_context() when no context is given it fails" |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 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 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
+ def test_setup_with_context_context_failing(self): |
| 76 |
+ "sure.that_with_context() in a failing test" |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
+ def setup(context): |
| 82 |
+ context.name = "John Resig" |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 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 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
+ def test_teardown_with_context(self): |
| 102 |
+ "sure.with_context() runs teardown before the function itself" |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
+ class something: |
| 108 |
+ pass |
| 109 |
|
| 110 |
|
| 111 |
+ def setup(context): |
| 112 |
+ something.modified = True |
| 113 |
|
| 114 |
+ def teardown(context): |
| 115 |
+ del something.modified |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
+ @sure.that_with_context(setup, teardown) |
| 120 |
+ def something_was_modified(context): |
| 121 |
+ assert hasattr(something, "modified") |
| 122 |
+ assert something.modified |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
+ something_was_modified() |
| 127 |
+ assert not hasattr(something, "modified") |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
+ def test_that_is_a(self): |
| 135 |
+ "that() is_a(object)" |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
+ something = "something" |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
+ assert that(something).is_a(text_type) |
| 146 |
+ assert isinstance(something, text_type) |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
+ def test_that_equals(self): |
| 152 |
+ "that() equals(string)" |
| 153 |
|
| 154 |
|
| 155 |
+ something = "something" |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
+ assert that('something').equals(something) |
| 160 |
+ assert something == 'something' |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
+ def test_that_differs(self): |
| 166 |
+ "that() differs(object)" |
| 167 |
|
| 168 |
|
| 169 |
+ something = "something" |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
+ assert that(something).differs("23123%FYTUGIHOfdf") |
| 174 |
+ assert something != "23123%FYTUGIHOfdf" |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 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 |
|
| 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 |
|
| 196 |
|
| 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 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 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 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
+ def test_that_at_key_equals(self): |
| 236 |
+ "that().at(object).equals(object)" |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
+ class Class: |
| 243 |
+ name = "some class" |
| 244 |
+ Object = Class() |
| 245 |
+ dictionary = { |
| 246 |
+ 'name': 'John', |
| 247 |
+ } |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 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 |
|
| 264 |
|
| 265 |
+ def test_that_len_is(self): |
| 266 |
+ "that() len_is(number)" |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
+ lst = range(1000) |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
+ assert that(lst).len_is(1000) |
| 280 |
+ assert len(lst) == 1000 |
| 281 |
+ assert that(lst).len_is(lst) |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
+ def test_that_len_greater_than(self): |
| 287 |
+ "that() len_greater_than(number)" |
| 288 |
|
| 289 |
|
| 290 |
+ lst = range(1000) |
| 291 |
+ lst2 = range(100) |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
+ assert that(lst).len_greater_than(100) |
| 297 |
+ assert len(lst) == 1000 |
| 298 |
+ assert that(lst).len_greater_than(lst2) |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
+ def test_that_len_greater_than_should_raise_assertion_error(self): |
| 304 |
+ "that() len_greater_than(number) raise AssertionError" |
| 305 |
|
| 306 |
|
| 307 |
|
| 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 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
+ def test_that_len_greater_than_or_equals(self): |
| 322 |
+ "that() len_greater_than_or_equals(number)" |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
+ lst = list(range(1000)) |
| 327 |
+ lst2 = list(range(100)) |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 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 |
|
| 345 |
|
| 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 |
|
| 350 |
|
| 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 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
+ def test_that_len_lower_than(self): |
| 367 |
+ "that() len_lower_than(number)" |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
+ lst = list(range(100)) |
| 372 |
+ lst2 = list(range(1000)) |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
+ assert that(lst).len_lower_than(101) |
| 383 |
+ assert len(lst) == 100 |
| 384 |
+ assert that(lst).len_lower_than(lst2) |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
+ def test_that_len_lower_than_should_raise_assertion_error(self): |
| 390 |
+ "that() len_lower_than(number) raise AssertionError" |
| 391 |
|
| 392 |
|
| 393 |
|
| 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 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
+ def test_that_len_lower_than_or_equals(self): |
| 408 |
+ "that() len_lower_than_or_equals(number)" |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
+ lst = list(range(1000)) |
| 413 |
+ lst2 = list(range(1001)) |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 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 |
|
| 431 |
|
| 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 |
|
| 436 |
|
| 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 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 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 |
|
| 460 |
|
| 461 |
+ shapes = [ |
| 462 |
+ shape('circle'), |
| 463 |
+ shape('square'), |
| 464 |
+ shape('rectangle'), |
| 465 |
+ shape('triangle'), |
| 466 |
+ ] |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
+ assert that(shapes).the_attribute("kind").equals('geometrical form') |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 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 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
+ def __repr__(self): |
| 499 |
+ return '<%s:%s>' % (self.kind, self.name) |
| 500 |
|
| 501 |
|
| 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 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
+ assert shapes[1].name == 'square' |
| 519 |
+ assert shapes[2].name == 'square' |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
+ assert that(shapes, within_range=(1, 2)). \ |
| 524 |
+ the_attribute("name"). \ |
| 525 |
+ equals('square') |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 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 |
|
| 546 |
|
| 547 |
+ assert shapes[0] != 'ball' |
| 548 |
+ assert shapes[3] != 'ball' |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 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 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 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 |
|
| 579 |
|
| 580 |
+ animals = [ |
| 581 |
+ animal('dog'), |
| 582 |
+ animal('cat'), |
| 583 |
+ animal('cow'), |
| 584 |
+ animal('cow'), |
| 585 |
+ animal('cow'), |
| 586 |
+ ] |
| 587 |
|
| 588 |
|
| 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 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 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 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 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 |
|
| 622 |
|
| 623 |
+ assert that(animals).in_each("attributes['kind']"). \ |
| 624 |
+ matches(['dog','cat','cow','cow','cow']) |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 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 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
+ def test_that_raises(self): |
| 649 |
+ "that(callable, with_args=[arg1], and_kwargs={'arg2': 'value'}).raises(SomeException)" |
| 650 |
+ global called |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
+ called = False |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 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 |
|
| 674 |
|
| 675 |
|
| 676 |
+ try: |
| 677 |
+ function(1, 2) |
| 678 |
+ assert False, 'should not reach here' |
| 679 |
|
| 680 |
|
| 681 |
+ except RuntimeError as e: |
| 682 |
+ assert text_type(e) == 'yeah, it failed' |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
+ except Exception: |
| 690 |
+ assert False, 'should not reach here' |
| 691 |
|
| 692 |
|
| 693 |
+ finally: |
| 694 |
+ assert called |
| 695 |
+ called = False |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
+ self.assertRaises(RuntimeError, function, 1, 2) |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
+ called = False |
| 705 |
+ self.assertEqual(function(3, 5), 'OK') |
| 706 |
+ assert called |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
+ called = False |
| 711 |
+ assert that(function, with_args=[1], and_kwargs={'arg2': 2}). \ |
| 712 |
+ raises(RuntimeError) |
| 713 |
+ assert called |
| 714 |
|
| 715 |
|
| 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 |
|
| 727 |
+ called = False |
| 728 |
+ assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \ |
| 729 |
+ raises(RuntimeError) |
| 730 |
+ assert called |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
+ called = False |
| 736 |
+ assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \ |
| 737 |
+ raises(RuntimeError, 'yeah, it failed') |
| 738 |
+ assert called |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
+ called = False |
| 745 |
+ assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \ |
| 746 |
+ raises('yeah, it failed') |
| 747 |
+ assert called |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
+ called = False |
| 754 |
+ assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \ |
| 755 |
+ raises(r'it fail') |
| 756 |
+ assert called |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
+ called = False |
| 763 |
+ assert that(function, with_kwargs={'arg1': 1, 'arg2': 2}). \ |
| 764 |
+ raises(RuntimeError, r'it fail') |
| 765 |
+ assert called |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 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 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
+ def test_that_raises_does_raise_for_exception_type_mismatch(self): |
| 790 |
+ "that(callable(RuntimeError)).raises(TypeError)" |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
+ error = r'.*should raise <class .*FooError.*, but raised <class .*BarError.*' |
| 797 |
|
| 798 |
+ class FooError(Exception): |
| 799 |
+ pass |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
+ class BarError(Exception): |
| 805 |
+ pass |
| 806 |
|
| 807 |
+ def my_function(): |
| 808 |
+ raise BarError('OOps') |
| 809 |
|
| 810 |
|
| 811 |
|
| 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 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
+ def test_that_raises_with_args(self): |
| 824 |
+ "that(callable, with_args=['foo']).raises(FooError)" |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
+ class FooError(Exception): |
| 829 |
+ pass |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
+ def my_function(string): |
| 834 |
+ if string == 'foo': |
| 835 |
+ raise FooError('OOps') |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
+ assert that(my_function, with_args=['foo']).raises(FooError, 'OOps') |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
+ def test_that_does_not_raise_with_args(self): |
| 849 |
+ "that(callable).doesnt_raise(FooError) and does_not_raise" |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
+ class FooError(Exception): |
| 854 |
+ pass |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
+ def my_function(string): |
| 860 |
+ if string == 'foo': |
| 861 |
+ raise FooError('OOps') |
| 862 |
|
| 863 |
|
| 864 |
+ assert that(my_function, with_args=['foo']).raises(FooError, 'OOps') |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
+ def test_that_contains_string(self): |
| 870 |
+ "that('foobar').contains('foo')" |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
+ assert 'foo' in 'foobar' |
| 875 |
+ assert that('foobar').contains('foo') |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 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 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 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 |
|
| 902 |
|
| 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 |
|
| 906 |
|
| 907 |
|
| 908 |
+ assert that(assertions).raises( |
| 909 |
+ TypeError, |
| 910 |
+ error_msg |
| 911 |
+ ) |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
+ def test_that_none_contains_string(self): |
| 917 |
+ "that(None).contains('bungalow')" |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 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 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 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 |
|
| 945 |
|
| 946 |
+ assert that(tuple()).is_empty |
| 947 |
+ assert that({}).are_empty |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 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 |
|
| 964 |
|
| 965 |
+ def fail_plural(): |
| 966 |
+ assert that((1, 2)).is_empty |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
+ assert that(fail_plural).raises('(1, 2) is not empty, it has 2 items') |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 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 |
|
| 981 |
+ obj = object() |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
+ def fail(): |
| 986 |
+ assert that(obj).is_empty |
| 987 |
+ assert False, 'should not reach here' |
| 988 |
|
| 989 |
|
| 990 |
+ assert that(fail).raises('%r is not iterable' % obj) |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
+ def test_that_something_iterable_matches_another(self): |
| 996 |
+ "that(something_iterable).matches(another_iterable)" |
| 997 |
|
| 998 |
|
| 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 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
+ two = [ |
| 1011 |
+ ("/1", KlassOne), |
| 1012 |
+ ("/2", KlassTwo), |
| 1013 |
+ ] |
| 1014 |
|
| 1015 |
|
| 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 |
|
| 1023 |
|
| 1024 |
+ class Fail2(object): |
| 1025 |
+ def __init__(self): |
| 1026 |
+ assert that(xrange(1)).matches([2]) |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
+ class Fail3(object): |
| 1036 |
+ def __call__(self): |
| 1037 |
+ assert that(xrange(1)).matches([2]) |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 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 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
+ def test_within_pass(self): |
| 1054 |
+ "within(five=miliseconds) will pass" |
| 1055 |
+ from sure import within, miliseconds |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
+ within(five=miliseconds)(lambda *a: None)() |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 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 |
|
| 1079 |
|
| 1080 |
|
| 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 |
|
| 1089 |
+ assert failed, 'within(five=miliseconds)(sleepy) did not fail' |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 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 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 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 |
|
| 1131 |
+ assert failed, 'should raise assertion error' |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 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 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
+ cfrom, cto = sure.UNITS[sure.microseconds] |
| 1165 |
|
| 1166 |
|
| 1167 |
+ self.assertEqual(cfrom(1), 100000) |
| 1168 |
+ self.assertEqual(cto(1), 1) |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
+ def test_milisecond_unit(self): |
| 1175 |
+ "testing miliseconds convertion" |
| 1176 |
+ cfrom, cto = sure.UNITS[sure.milisecond] |
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
+ self.assertEqual(cfrom(1), 1000) |
| 1181 |
+ self.assertEqual(cto(100), 1) |
| 1182 |
|
| 1183 |
|
| 1184 |
+ cfrom, cto = sure.UNITS[sure.miliseconds] |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
+ self.assertEqual(cfrom(1), 1000) |
| 1189 |
+ self.assertEqual(cto(100), 1) |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
+ def test_second_unit(self): |
| 1196 |
+ "testing seconds convertion" |
| 1197 |
+ cfrom, cto = sure.UNITS[sure.second] |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
+ self.assertEqual(cfrom(1), 1) |
| 1202 |
+ self.assertEqual(cto(100000), 1) |
| 1203 |
|
| 1204 |
|
| 1205 |
+ cfrom, cto = sure.UNITS[sure.seconds] |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
+ self.assertEqual(cfrom(1), 1) |
| 1210 |
+ self.assertEqual(cto(100000), 1) |
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
+ def test_minute_unit(self): |
| 1217 |
+ "testing minutes convertion" |
| 1218 |
+ cfrom, cto = sure.UNITS[sure.minute] |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
+ self.assertEqual(cfrom(60), 1) |
| 1223 |
+ self.assertEqual(cto(1), 6000000) |
| 1224 |
|
| 1225 |
|
| 1226 |
+ cfrom, cto = sure.UNITS[sure.minutes] |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
+ self.assertEqual(cfrom(60), 1) |
| 1231 |
+ self.assertEqual(cto(1), 6000000) |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 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 |
|
| 1243 |
|
| 1244 |
+ def assert_utc(utc): |
| 1245 |
+ assert isinstance(utc, datetime) |
| 1246 |
|
| 1247 |
|
| 1248 |
+ within(five=miliseconds)(assert_utc)() |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 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 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
+ assert that('friend').is_truthful() |
| 1265 |
+ self.assertEqual(that('friend').is_truthful(), 'foobar') |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 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 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
+ def setup2(context): |
| 1284 |
+ context.last_name = "Resig" |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 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 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
+ def test_accepts_teardown_list(self): |
| 1305 |
+ "sure.with_context() runs teardown before the function itself" |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
+ class something: |
| 1310 |
+ modified = True |
| 1311 |
+ finished = 'nope' |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
+ def setup(context): |
| 1318 |
+ something.modified = False |
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
+ def teardown1(context): |
| 1326 |
+ something.modified = True |
| 1327 |
|
| 1328 |
+ def teardown2(context): |
| 1329 |
+ something.finished = 'yep' |
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 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 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
+ something_was_modified() |
| 1342 |
+ assert something.modified |
| 1343 |
+ assert something.finished == 'yep' |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 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 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
+ def test_actions_returns_context(self): |
| 1381 |
+ "the actions always returns the context" |
| 1382 |
+ from sure import action_for, scenario |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 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 |
|
| 1397 |
|
| 1398 |
|
| 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 |
|
| 1406 |
|
| 1407 |
+ assert i_can_use_actions() |
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 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 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 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 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
+ providers = Then.__sure_providers_of__ |
| 1444 |
+ action = Then.the_context_has_variables.__name__ |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
+ providers_of_var1 = [p.__name__ for p in providers['var1']] |
| 1451 |
+ assert that(providers_of_var1).contains(action) |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
+ providers_of_foobar = [p.__name__ for p in providers['foobar']] |
| 1457 |
+ assert that(providers_of_foobar).contains(action) |
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
+ return True |
| 1465 |
|
| 1466 |
|
| 1467 |
+ assert the_providers_are_working() |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 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 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 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 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
+ def with_setup(context): |
| 1493 |
+ @action_for(context, provides=['one', 'two']) |
| 1494 |
+ def bad_action(): |
| 1495 |
+ context.one = 123 |
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 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 |
|
| 1505 |
|
| 1506 |
+ assert the_providers_are_working() |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 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 |
|
| 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 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
+ @scenario(with_setup) |
| 1534 |
+ def depends_on_fails(the): |
| 1535 |
+ assert that(the.lonely_action).raises(AssertionError, error) |
| 1536 |
+ return True |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
+ assert depends_on_fails() |
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 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 |
|
| 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 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
+ def with_setup(context): |
| 1572 |
+ @action_for(context, provides=['some_attr']) |
| 1573 |
+ def dependency_action(): |
| 1574 |
+ context.some_attr = True |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
+ @action_for(context, depends_on=['some_attr']) |
| 1582 |
+ def my_action(): |
| 1583 |
+ pass |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
+ @scenario(with_setup) |
| 1590 |
+ def depends_on_fails(the): |
| 1591 |
+ assert that(the.my_action).raises(AssertionError, error) |
| 1592 |
+ return True |
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
+ assert depends_on_fails() |
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
+ def test_that_contains_dictionary_keys(self): |
| 1630 |
+ "that(dict(name='foobar')).contains('name')" |
| 1631 |
|
| 1632 |
|
| 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 |
|
| 1640 |
|
| 1641 |
+ def test_that_contains_list(self): |
| 1642 |
+ "that(['foobar', '123']).contains('foobar')" |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
+ data = ['foobar', '123'] |
| 1649 |
+ assert 'foobar' in data |
| 1650 |
+ assert that(data).contains('foobar') |
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
+ def test_that_contains_set(self): |
| 1656 |
+ "that(set(['foobar', '123']).contains('foobar')" |
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
+ data = set(['foobar', '123']) |
| 1662 |
+ assert 'foobar' in data |
| 1663 |
+ assert that(data).contains('foobar') |
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
+ def test_that_contains_tuple(self): |
| 1669 |
+ "that(('foobar', '123')).contains('foobar')" |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
+ data = ('foobar', '123') |
| 1675 |
+ assert 'foobar' in data |
| 1676 |
+ assert that(data).contains('foobar') |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 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 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
+ context = VariablesBag() |
| 1688 |
|
| 1689 |
+ context.name = "John" |
| 1690 |
+ context.foo = "bar" |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
+ assert that(context.name).equals("John") |
| 1695 |
+ assert that(context.foo).equals("bar") |
| 1696 |
|
| 1697 |
|
| 1698 |
+ def access_nonexisting_attr(): |
| 1699 |
+ assert context.bleh == 'crash :(' |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 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 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 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 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 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 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
+ providers = Then.__sure_providers_of__ |
| 1744 |
+ action = Then.the_context_has_variables.__name__ |
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
+ providers_of_var1 = [p.__name__ for p in providers['var1']] |
| 1752 |
+ assert that(providers_of_var1).contains(action) |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
+ providers_of_JohnDoe = [p.__name__ for p in providers['JohnDoe']] |
| 1761 |
+ assert that(providers_of_JohnDoe).contains(action) |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
+ return True |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
+ assert the_providers_are_working() |
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
+ def test_deep_equals_dict_level1_success(self): |
| 1776 |
+ "that() deep_equals(dict) succeeding on level 1" |
| 1777 |
|
| 1778 |
|
| 1779 |
+ something = { |
| 1780 |
+ 'one': 'yeah', |
| 1781 |
+ } |
| 1782 |
|
| 1783 |
+ assert that(something).deep_equals({ |
| 1784 |
+ 'one': 'yeah', |
| 1785 |
+ }) |
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
+ def test_deep_equals_dict_level1_fail(self): |
| 1794 |
+ "that() deep_equals(dict) failing on level 1" |
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 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 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
+ def test_deep_equals_list_level1_success(self): |
| 1824 |
+ "that(list) deep_equals(list) succeeding on level 1" |
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
+ something = ['one', 'yeah'] |
| 1831 |
+ assert that(something).deep_equals(['one', 'yeah']) |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 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 |
|
| 1846 |
|
| 1847 |
+ something = ['one', 'yeahs'] |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 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 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 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 |
|
| 1871 |
|
| 1872 |
+ something = ['one', 'yeah', 'awesome!'] |
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 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 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 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 |
|
| 1902 |
|
| 1903 |
+ something = ['one', 'yeah'] |
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
+ def assertions(): |
| 1918 |
+ assert that(something).deep_equals(['one', 'yeah', 'damn']) |
| 1919 |
|
| 1920 |
|
| 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 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 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 |
|
| 1951 |
|
| 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 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 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 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 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 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
+ def test_deep_equals_tuple_level1_success(self): |
| 2026 |
+ "that(tuple) deep_equals(tuple) succeeding on level 1" |
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
+ something = ('one', 'yeah') |
| 2037 |
+ assert that(something).deep_equals(('one', 'yeah')) |
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
+ def test_deep_equals_tuple_level1_fail_by_value(self): |
| 2043 |
+ "that(tuple) deep_equals(tuple) failing on level 1" |
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
+ something = ('one', 'yeahs') |
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 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 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 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 |
|
| 2080 |
|
| 2081 |
+ def assertions(): |
| 2082 |
+ assert that(something).deep_equals(('one', 'yeah')) |
| 2083 |
|
| 2084 |
|
| 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 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 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 |
|
| 2111 |
|
| 2112 |
+ def assertions(): |
| 2113 |
+ assert that(something).deep_equals(('one', 'yeah', 'damn')) |
| 2114 |
|
| 2115 |
|
| 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 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 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 |
|
| 2189 |
assert that(something).deep_equals({ |
| 2190 |
|
| 2191 |
+ 'one': 'yeah', |
| 2192 |
+ 'date': now, |
| 2193 |
}) |
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 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 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 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 |
|
| 2324 |
+ 'two': 'cool', |
| 2325 |
}, |
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
+ } |
| 2346 |
|
| 2347 |
|
| 2348 |
assert that(something).deep_equals({ |
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
+ 'one': 'yeah', |
| 2353 |
+ 'another': { |
| 2354 |
+ 'two': 'cool', |
| 2355 |
+ }, |
| 2356 |
}) |
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
+ def test_deep_equals_dict_level2_list_success(self): |
| 2384 |
+ "that() deep_equals(dict) succeeding on level 2" |
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
+ something = { |
| 2406 |
+ 'one': 'yeah', |
| 2407 |
+ 'another': ['one', 'two', 3], |
| 2408 |
+ } |
| 2409 |
|
| 2410 |
|
| 2411 |
assert that(something).deep_equals({ |
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
+ 'one': 'yeah', |
| 2416 |
+ 'another': ['one', 'two', 3], |
| 2417 |
}) |
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
+ def test_deep_equals_dict_level2_fail(self): |
| 2445 |
+ "that() deep_equals(dict) failing on level 2" |
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 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 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
+ def test_deep_equals_dict_level3_fail_values(self): |
| 2483 |
+ "that() deep_equals(dict) failing on level 3" |
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
+ something = { |
| 2488 |
+ 'my::all_users': [ |
| 2489 |
+ {'name': 'John', 'age': 33}, |
| 2490 |
+ ], |
| 2491 |
+ } |
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 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 |
|
| 2519 |
|
| 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 |
|
| 2524 |
+ something = { |
| 2525 |
+ 'my::all_users': [ |
| 2526 |
+ {'name': 'John', 'age': 33}, |
| 2527 |
+ ], |
| 2528 |
+ } |
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 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 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 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 |
|
| 2562 |
|
| 2563 |
+ something = { |
| 2564 |
+ 'my::all_users': [ |
| 2565 |
+ {'name': 'John', 'age': 33, 'foo': 'bar'}, |
| 2566 |
+ ], |
| 2567 |
+ } |
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
+ def assertions(): |
| 2574 |
+ assert that(something).deep_equals({ |
| 2575 |
+ 'my::all_users': [ |
| 2576 |
+ {'name': 'John', 'age': 30}, |
| 2577 |
+ ], |
| 2578 |
+ }) |
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 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 |
|
| 2594 |
|
| 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 |
|
| 2599 |
+ something = { |
| 2600 |
+ 'my::all_users': [ |
| 2601 |
+ {'name': 'John', 'age': 33, 'foo': 'bar'}, |
| 2602 |
+ ], |
| 2603 |
+ } |
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
+ def assertions(): |
| 2608 |
+ assert that(something).deep_equals({ |
| 2609 |
+ 'my::all_users': [ |
| 2610 |
+ {'name': 'John', 'age': 33, 'bar': 'foo'}, |
| 2611 |
+ ], |
| 2612 |
+ }) |
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 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 |
|
| 2800 |
+ expect(that(part1).equals).when.called_with(part2).should.throw("") |