Beispiel #1
0
    def setup(self):
        self.db = Database()

        @self.db.add
        class T(Table):
            pass
        self.T = T
Beispiel #2
0
class TestDatabase(object):

    def setup(self):
        self.db = Database()

        @self.db.add
        class T(Table):
            pass
        self.T = T

    def test_contains_table(self):
        assert self.T in self.db

    def test_contains_name(self):
        assert 'T' in self.db

    def test_getitem(self):
        assert self.db['T'] is self.T

    def test_getitem_raises(self):
        with assert_raises(KeyError):
            self.db['not a table']

    def test_setitem_raises(self):
        'Cannot set a table.'
        with assert_raises(TypeError):
            self.db['key'] = 'value'

    def test_tablenames(self):
        assert set(self.db.tablenames()) == set([u'T'])

    def test_iter(self):
        assert set(iter(self.db)) == set([self.T])

    def test_add(self):
        class Tb(Table):
            pass
        r = self.db.add(Tb)
        assert r is Tb
        assert Tb in self.db