| 407 | eq_(row._mapping["anon_2"], 10) |
| 408 | |
| 409 | def test_row_comparison(self, connection): |
| 410 | users = self.tables.users |
| 411 | |
| 412 | connection.execute(users.insert(), dict(user_id=7, user_name="jack")) |
| 413 | rp = connection.execute(users.select()).first() |
| 414 | |
| 415 | eq_(rp, rp) |
| 416 | is_(not (rp != rp), True) |
| 417 | |
| 418 | equal = (7, "jack") |
| 419 | |
| 420 | eq_(rp, equal) |
| 421 | eq_(equal, rp) |
| 422 | is_((not (rp != equal)), True) |
| 423 | is_(not (equal != equal), True) |
| 424 | |
| 425 | def endless(): |
| 426 | while True: |
| 427 | yield 1 |
| 428 | |
| 429 | ne_(rp, endless()) |
| 430 | ne_(endless(), rp) |
| 431 | |
| 432 | # test that everything compares the same |
| 433 | # as it would against a tuple |
| 434 | for compare in [False, 8, endless(), "xyz", (7, "jack")]: |
| 435 | for op in [ |
| 436 | operator.eq, |
| 437 | operator.ne, |
| 438 | operator.gt, |
| 439 | operator.lt, |
| 440 | operator.ge, |
| 441 | operator.le, |
| 442 | ]: |
| 443 | try: |
| 444 | control = op(equal, compare) |
| 445 | except TypeError: |
| 446 | # Py3K raises TypeError for some invalid comparisons |
| 447 | assert_raises(TypeError, op, rp, compare) |
| 448 | else: |
| 449 | eq_(control, op(rp, compare)) |
| 450 | |
| 451 | try: |
| 452 | control = op(compare, equal) |
| 453 | except TypeError: |
| 454 | # Py3K raises TypeError for some invalid comparisons |
| 455 | assert_raises(TypeError, op, compare, rp) |
| 456 | else: |
| 457 | eq_(control, op(compare, rp)) |
| 458 | |
| 459 | @testing.provide_metadata |
| 460 | def test_column_label_overlap_fallback(self, connection): |