mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-13 04:07:20 -04:00
6228e72cb1
- also omitted all modules and classes that aren't expicitly public - omitted 'Smallinteger' (small i), but it's still in schema - omitted NullType-related items from types.__all__ - patched up a few tests to use sql.table and sql.column, other related.
68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
import testbase
|
|
from sqlalchemy import util, sql, exceptions
|
|
from testlib import *
|
|
|
|
|
|
class OrderedDictTest(PersistTest):
|
|
def test_odict(self):
|
|
o = util.OrderedDict()
|
|
o['a'] = 1
|
|
o['b'] = 2
|
|
o['snack'] = 'attack'
|
|
o['c'] = 3
|
|
|
|
self.assert_(o.keys() == ['a', 'b', 'snack', 'c'])
|
|
self.assert_(o.values() == [1, 2, 'attack', 3])
|
|
|
|
o.pop('snack')
|
|
|
|
self.assert_(o.keys() == ['a', 'b', 'c'])
|
|
self.assert_(o.values() == [1, 2, 3])
|
|
|
|
o2 = util.OrderedDict(d=4)
|
|
o2['e'] = 5
|
|
|
|
self.assert_(o2.keys() == ['d', 'e'])
|
|
self.assert_(o2.values() == [4, 5])
|
|
|
|
o.update(o2)
|
|
self.assert_(o.keys() == ['a', 'b', 'c', 'd', 'e'])
|
|
self.assert_(o.values() == [1, 2, 3, 4, 5])
|
|
|
|
o.setdefault('c', 'zzz')
|
|
o.setdefault('f', 6)
|
|
self.assert_(o.keys() == ['a', 'b', 'c', 'd', 'e', 'f'])
|
|
self.assert_(o.values() == [1, 2, 3, 4, 5, 6])
|
|
|
|
class ColumnCollectionTest(PersistTest):
|
|
def test_in(self):
|
|
cc = sql.ColumnCollection()
|
|
cc.add(sql.column('col1'))
|
|
cc.add(sql.column('col2'))
|
|
cc.add(sql.column('col3'))
|
|
assert 'col1' in cc
|
|
assert 'col2' in cc
|
|
|
|
try:
|
|
cc['col1'] in cc
|
|
assert False
|
|
except exceptions.ArgumentError, e:
|
|
assert str(e) == "__contains__ requires a string argument"
|
|
|
|
def test_compare(self):
|
|
cc1 = sql.ColumnCollection()
|
|
cc2 = sql.ColumnCollection()
|
|
cc3 = sql.ColumnCollection()
|
|
c1 = sql.column('col1')
|
|
c2 = c1.label('col2')
|
|
c3 = sql.column('col3')
|
|
cc1.add(c1)
|
|
cc2.add(c2)
|
|
cc3.add(c3)
|
|
assert (cc1==cc2).compare(c1 == c2)
|
|
assert not (cc1==cc3).compare(c2 == c3)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
testbase.main()
|