MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_sort_states_comparisons

Method test_sort_states_comparisons

test/orm/test_mapper.py:500–530  ·  view source on GitHub ↗

test that _sort_states() doesn't compare insert_order to state.key, for set of mixed persistent/pending. In particular Python 3 disallows this.

(self)

Source from the content-addressed store, hash-verified

498 assert_raises(TypeError, Bar, x=5)
499
500 def test_sort_states_comparisons(self):
501 """test that _sort_states() doesn't compare
502 insert_order to state.key, for set of mixed
503 persistent/pending. In particular Python 3 disallows
504 this.
505
506 """
507
508 class Foo:
509 def __init__(self, id_):
510 self.id = id_
511
512 m = MetaData()
513 foo_t = Table("foo", m, Column("id", String, primary_key=True))
514 m = self.mapper(Foo, foo_t)
515
516 class DontCompareMeToString(int):
517 pass
518
519 foos = [Foo(id_="f%d" % i) for i in range(5)]
520 states = [attributes.instance_state(f) for f in foos]
521
522 for s in states[0:3]:
523 s.key = m._identity_key_from_state(s)
524 states[3].insert_order = DontCompareMeToString(5)
525 states[4].insert_order = DontCompareMeToString(1)
526 states[2].insert_order = DontCompareMeToString(3)
527 eq_(
528 _sort_states(m, states),
529 [states[4], states[3], states[0], states[1], states[2]],
530 )
531
532 def test_props(self):
533 users, Address, addresses, User = (

Callers

nothing calls this directly

Calls 9

MetaDataClass · 0.90
TableClass · 0.90
ColumnClass · 0.90
eq_Function · 0.90
_sort_statesFunction · 0.90
FooClass · 0.70
mapperMethod · 0.45

Tested by

no test coverage detected