本文整理汇总了Python中bindertest.tabledefs.Foo类的典型用法代码示例。如果您正苦于以下问题:Python Foo类的具体用法?Python Foo怎么用?Python Foo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Foo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_by
def test_order_by(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="a")
foo2 = Foo.new(foo_id=2, i1=23, s1="B")
foo3 = Foo.new(foo_id=3, i1=42, s1="c")
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.insert(Foo, foo3)
# order by AutoIdCol
foo_list = list(conn.select(Foo, order_by=Foo.q.foo_id.ASC))
self.assertEquals([foo1, foo2, foo3], foo_list)
foo_list = list(conn.select(Foo, order_by=Foo.q.foo_id.DESC))
self.assertEquals([foo3, foo2, foo1], foo_list)
# order by IntCol
foo_list = list(conn.select(Foo, order_by=Foo.q.i1.ASC))
self.assertEquals([foo2, foo3, foo1], foo_list)
foo_list = list(conn.select(Foo, order_by=Foo.q.i1.DESC))
self.assertEquals([foo1, foo3, foo2], foo_list)
# UnicodeCol - ignore case
foo_list = list(conn.select(Foo, order_by=Foo.q.s1.ASC))
if connect == connect_postgres:
self.assertEquals([foo2, foo1, foo3], foo_list)
else:
self.assertEquals([foo1, foo2, foo3], foo_list)
foo_list = list(conn.select(Foo, order_by=Foo.q.s1.DESC))
if connect == connect_postgres:
self.assertEquals([foo3, foo1, foo2], foo_list)
else:
self.assertEquals([foo3, foo2, foo1], foo_list)
示例2: test_where_LIKE_ILIKE
def test_where_LIKE_ILIKE(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="ab pq")
foo2 = Foo.new(foo_id=2, i1=23, s1="AB PQ XY")
foo3 = Foo.new(foo_id=3, i1=42, s1="pq xy")
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.insert(Foo, foo3)
# where trailing %
if connect != connect_sqlite:
foo_list = conn.select(Foo, Foo.q.s1.LIKE('ab%'))
self.assertEquals([foo1], foo_list)
foo_list = conn.select(Foo, Foo.q.s1.ILIKE('ab%'))
self.assertEquals([foo1, foo2], foo_list)
# where trailing % - no matches
if connect != connect_sqlite:
foo_list = conn.select(Foo, Foo.q.s1.LIKE('%z%'))
self.assertEquals([], foo_list)
foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%z%'))
self.assertEquals([], foo_list)
# where leading %
if connect != connect_sqlite:
foo_list = conn.select(Foo, Foo.q.s1.LIKE('%xy'))
self.assertEquals([foo3], foo_list)
foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%xy'))
self.assertEquals([foo2, foo3], foo_list)
# where both sides %
if connect != connect_sqlite:
foo_list = conn.select(Foo, Foo.q.s1.LIKE('%x%'))
self.assertEquals([foo3], foo_list)
foo_list = conn.select(Foo, Foo.q.s1.ILIKE('%x%'))
self.assertEquals([foo2, foo3], foo_list)
示例3: test_roundtrip_check_values
def test_roundtrip_check_values(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha", d1=datetime.date(2006, 6, 12))
conn.insert(Foo, foo1)
foo_list = conn.select(Foo)
self.assertEquals([foo1], foo_list)
foo2 = foo_list[0]
Foo.check_values(foo2)
示例4: test_delete_0_rows
def test_delete_0_rows(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
foo2 = Foo.new(foo_id=2, i1=23, s1="beta")
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
rowcount = conn.delete(Foo, Foo.q.foo_id == 3)
self.assertEquals(0, rowcount)
foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
self.assertEquals([foo1, foo2], foo_list)
示例5: test_close_insert
def test_close_insert(self):
"Closing the connection prevents further operations on the connection."
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
conn.insert(Foo, foo1)
conn.close()
foo2 = Foo.new(foo_id=2, s1="beta")
try:
conn.insert(Foo, foo2)
except AssertionError, e:
self.assertEquals("Connection is closed", str(e))
示例6: test_delete_all
def test_delete_all(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
foo2 = Foo.new(foo_id=2, s1="beta")
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
found = conn.delete(Foo)
self.assertEquals(2, found)
self.assertEquals([], conn.select(Foo))
found = conn.delete(Foo)
self.assertEquals(0, found)
示例7: test_new_parse_some_fields
def test_new_parse_some_fields(self):
expected = {
"foo_id": 42,
"i1": 0,
"s1": "alpha",
"d1": None,
}
actual = Foo.new(foo_id=42, s1="alpha")
self.assertEquals(expected, actual)
actual = Foo.parse(foo_id="42", s1="alpha")
self.assertEquals(expected, actual)
示例8: test_parse_error
def test_parse_error(self):
# parse() gives parse error for bad strings
try:
Foo.parse(i1="2.3", s2=1.1)
except ValueError, e:
self.assert_(
str(e) in [
"invalid literal for int(): 2.3",
"invalid literal for int() with base 10: '2.3'",
]
)
示例9: test_select
def test_select(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
foo2 = Foo.new(foo_id=2, s1="beta")
conn.insert(Foo, foo1)
foo_list = conn.select(Foo)
self.assertEquals([foo1], foo_list)
conn.insert(Foo, foo2)
foo_list = conn.select(Foo)
# FIXME: depending on db order
self.assertEquals([foo1, foo2], foo_list)
示例10: test_insert_ascii
def test_insert_ascii(self):
foo1 = Foo.new(foo_id=1, s1=S_ENGLISH_ASCII)
foo2 = Foo.new(foo_id=2, s1=S_ENGLISH_U)
conn = connect()
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.commit()
conn.close()
conn = connect()
foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
self.assertEquals([foo1, foo2], foo_list)
conn.close()
示例11: test_insert_unicode
def test_insert_unicode(self):
foo1 = Foo.new(foo_id=1, s1=S_SPANISH_U)
foo2 = Foo.new(foo_id=2, s1=S_FRENCH_U)
conn = connect()
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.commit()
conn.close()
conn = connect()
foo_list = conn.select(Foo, order_by=Foo.q.foo_id.ASC)
self.assertEquals([foo1, foo2], foo_list)
conn.close()
示例12: test_delete_by_id_more_than_one_row
def test_delete_by_id_more_than_one_row(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101)
foo2 = Foo.new(foo_id=2, i1=101)
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
Foo2 = Table("foo", AutoIdCol("i1"), IntCol("foo_id"))
try:
conn.delete_by_id(Foo2, 101)
except AssertionError, e:
expected = "delete_by_id(): more than 1 row deleted", ("foo", "i1", 101, 2)
self.assertEquals(expected, get_assert_tuple_args(e))
示例13: test_where_gt_ge_lt_le
def test_where_gt_ge_lt_le(self):
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha", d1=datetime.date(2005, 11, 24))
foo2 = Foo.new(foo_id=2, i1=23, s1="beta", d1=datetime.date(2006, 2, 16))
foo3 = Foo.new(foo_id=3, i1=42, s1="alpha", d1=datetime.date(2006, 6, 10))
conn.insert(Foo, foo1)
conn.insert(Foo, foo2)
conn.insert(Foo, foo3)
# where __gt__ & AutoIdCol
foo_list = conn.select(Foo, Foo.q.foo_id > 2)
self.assertEquals([foo3], foo_list)
# where __ge__ & UnicodeCol
foo_list = conn.select(Foo, Foo.q.s1 >= 'beta')
self.assertEquals([foo2], foo_list)
# where __lt__ & IntCol
foo_list = conn.select(Foo, Foo.q.i1 < 42)
self.assertEquals([foo2], foo_list)
# where __le__ & IntCol
foo_list = conn.select(Foo, Foo.q.i1 <= 42)
# FIXME: depending on db order
self.assertEquals([foo2, foo3], foo_list)
# where AND, AutoIdCol, gt, IntCol, lt
foo_list = conn.select(Foo, AND(Foo.q.foo_id > 1, Foo.q.i1 < 30))
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, lt
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 > datetime.date(2005, 11, 24),
Foo.q.d1 < datetime.date(2006, 6, 10),
)
)
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, lt
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 > datetime.date(2005, 11, 24),
Foo.q.d1 < datetime.date(2006, 6, 10),
)
)
self.assertEquals([foo2], foo_list)
# where AND, DateCol, gt, le
foo_list = conn.select(
Foo,
AND(
Foo.q.d1 >= datetime.date(2005, 11, 24),
Foo.q.d1 <= datetime.date(2006, 6, 10),
)
)
# FIXME: depending on db order
self.assertEquals([foo1, foo2, foo3], foo_list)
示例14: test_select_insert
def test_select_insert(self):
"New operation closes a partly consumed cursor."
conn = connect()
foo1 = Foo.new(foo_id=1, i1=101, s1="alpha")
foo2 = Foo.new(foo_id=2, i1=23, s1="beta")
conn.insert(Foo, foo1)
foo_iter = conn.xselect(Foo)
conn.insert(Foo, foo2)
try:
foo_iter.next()
except conn.DbError, e:
self.assertEquals("Result cursor closed.", str(e))
示例15: test_new_parse_unkown_cols
def test_new_parse_unkown_cols(self):
# DONT copy unknown columns
expected = {
"foo_id": None,
"i1": 16,
"s1": "",
"d1": None,
}
actual = Foo.new(i1=16, s2="beta")
self.assertEquals(expected, actual)
actual = Foo.parse(i1="16", s2="beta")
self.assertEquals(expected, actual)