MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_array

Method test_array

test/ext/test_indexable.py:23–44  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

21
22class IndexPropertyTest(fixtures.TestBase):
23 def test_array(self):
24 Base = declarative_base()
25
26 class A(Base):
27 __tablename__ = "a"
28 id = Column("id", Integer, primary_key=True)
29 array = Column("_array", ARRAY(Integer), default=[])
30 first = index_property("array", 0)
31 tenth = index_property("array", 9)
32
33 a = A(array=[1, 2, 3])
34 eq_(a.first, 1)
35 assert_raises(AttributeError, lambda: a.tenth)
36 a.first = 100
37 eq_(a.first, 100)
38 eq_(a.array, [100, 2, 3])
39 del a.first
40 eq_(a.first, 2)
41
42 a2 = A(first=5)
43 eq_(a2.first, 5)
44 eq_(a2.array, [5])
45
46 def test_array_longinit(self):
47 Base = declarative_base()

Callers

nothing calls this directly

Calls 4

declarative_baseFunction · 0.90
eq_Function · 0.90
assert_raisesFunction · 0.90
AClass · 0.70

Tested by

no test coverage detected