예제 #1
0
    def test__columniter__1(self):
        dogs = Dogs()
        persons = Persons()
        ts = table_.TableList((dogs, persons))
        it = functions_.columniter(ts)

        col = next(it)
        self.assertIs(col.table, dogs)
        self.assertIs(col.index, 0)

        col = next(it)
        self.assertIs(col.table, dogs)
        self.assertIs(col.index, 1)

        col = next(it)
        self.assertIs(col.table, persons)
        self.assertIs(col.index, 0)

        col = next(it)
        self.assertIs(col.table, persons)
        self.assertIs(col.index, 1)

        col = next(it)
        self.assertIs(col.table, persons)
        self.assertIs(col.index, 2)

        with self.assertRaises(StopIteration):
            next(it)
예제 #2
0
    def test__columndict__1(self):
        dogs = Dogs()
        persons = Persons()

        ts = table_.TableList((dogs, persons))

        cd = ts.columndict

        self.assertEqual(len(cd), len(Dog) + len(Person))
        self.assertIsInstance(cd['dogs.name'], table_.TableColumnDescriptor)
        self.assertIs(cd['dogs.name'].table, dogs)
        self.assertEqual(cd['dogs.name'].index, 0)
        self.assertEqual(cd['dogs.name'].key, 'name')

        self.assertIsInstance(cd['dogs.age'], table_.TableColumnDescriptor)
        self.assertIs(cd['dogs.age'].table, dogs)
        self.assertEqual(cd['dogs.age'].index, 1)
        self.assertEqual(cd['dogs.age'].key, 'age')

        self.assertIsInstance(cd['persons.name'], table_.TableColumnDescriptor)
        self.assertIs(cd['persons.name'].table, persons)
        self.assertEqual(cd['persons.name'].index, 0)
        self.assertEqual(cd['persons.name'].key, 'name')

        self.assertIsInstance(cd['persons.surname'],
                              table_.TableColumnDescriptor)
        self.assertEqual(cd['persons.surname'].table, persons)
        self.assertEqual(cd['persons.surname'].index, 1)
        self.assertEqual(cd['persons.surname'].key, 'surname')

        self.assertIsInstance(cd['persons.address'],
                              table_.TableColumnDescriptor)
        self.assertEqual(cd['persons.address'].table, persons)
        self.assertEqual(cd['persons.address'].index, 2)
        self.assertEqual(cd['persons.address'].key, 'address')
예제 #3
0
    def test__columndict_setter__1(self):
        dogs = Dogs()
        persons = Persons()

        ts = table_.TableList((dogs, persons))

        with self.assertRaisesRegex(AttributeError, "can't set attribute"):
            ts.columndict = 'foo'
예제 #4
0
    def test__setitem__3(self):
        dogs = Dogs()
        persons = Persons()
        ts = table_.TableList((dogs, persons))

        with self.assertRaisesRegex(
                TypeError, "%s is not an instance of %s" %
            (repr('foo'), repr(table_.Table))):
            ts[0] = 'foo'
예제 #5
0
 def test__init__2(self):
     dogs = Dogs()
     persons = Persons()
     ts = table_.TableList((dogs, persons))
     self.assertEqual(len(ts._data), 2)
     self.assertIsInstance(ts._data[0], ref_.Ref)
     self.assertIsInstance(ts._data[1], ref_.Ref)
     self.assertIs(ts._data[0].obj, dogs)
     self.assertIs(ts._data[1].obj, persons)
예제 #6
0
    def __init__(self):
        # initialize empty tables
        for (name, datatype) in self.tabletuples():
            setattr(self, name, (tableclass(datatype))())

        for (name, reltabs, relnames) in self.relationtuples():
            reltabs = (getattr(self, reltabs[0]), getattr(self, reltabs[1]))
            setattr(self, name, Junction(reltabs, relnames))
        # tables
        self._tables = table_.TableList([ getattr(self, t) for (t,_) in self.tabletuples() ])
예제 #7
0
 def test__getitem__1(self):
     dogs = Dogs()
     persons = Persons()
     ts = table_.TableList((dogs, persons))
     self.assertIs(ts[0], dogs)
     self.assertIs(ts[1], persons)
     with self.assertRaises(IndexError):
         ts[2]
     with self.assertRaises(IndexError):
         ts[-3]
예제 #8
0
    def clone(self):
        db = type(self)()
        for (name, datatype) in db.tabletuples():
            setattr(db, name, (tableclass(datatype))(getattr(self, name)))

        for (name, reltabs, relnames) in db.relationtuples():
            reltabs = (getattr(db, reltabs[0]), getattr(db, reltabs[1]))
            setattr(db, name, Junction(reltabs, relnames, getattr(self, name)))
        # tables
        db._tables = table_.TableList([ getattr(db, t) for (t,_) in db.tabletuples() ])
        return db
예제 #9
0
    def test__insert__1(self):
        dogs = Dogs()
        persons = Persons()
        cars = Cars()
        ts = table_.TableList((dogs, persons))

        ts.insert(1, cars)
        self.assertEqual(len(ts), 3)
        self.assertIs(ts[0], dogs)
        self.assertIs(ts[1], cars)
        self.assertIs(ts[2], persons)
예제 #10
0
    def test__setitem__2(self):
        dogs = Dogs()
        persons = Persons()
        tables = [dogs, persons]

        ts = table_.TableList()
        ts[:] = tables

        self.assertEqual(len(ts), 2)
        self.assertIs(ts[0], dogs)
        self.assertIs(ts[1], persons)
예제 #11
0
    def test__delitem__1(self):
        dogs = Dogs()
        persons = Persons()
        ts = table_.TableList((dogs, persons))

        self.assertEqual(len(ts), 2)
        del ts[0]
        self.assertEqual(len(ts), 1)
        self.assertIs(ts[0], persons)

        del ts[0]
        self.assertEqual(len(ts), 0)

        with self.assertRaises(IndexError):
            del ts[0]
예제 #12
0
    def test__setitem__1(self):
        dogs = Dogs()
        persons = Persons()
        ts = table_.TableList((dogs, persons))
        ts[0] = persons
        ts[1] = dogs

        self.assertIs(ts[0], persons)
        self.assertIs(ts[1], dogs)

        with self.assertRaises(IndexError):
            ts[2] = persons
        with self.assertRaises(IndexError):
            ts[-3] = persons

        self.assertEqual(len(ts), 2)
        self.assertIs(ts[0], persons)
        self.assertIs(ts[1], dogs)
예제 #13
0
 def test__delitem__2(self):
     dogs = Dogs()
     persons = Persons()
     ts = table_.TableList((dogs, persons))
     del ts[:]
     self.assertEqual(len(ts), 0)
예제 #14
0
 def test__init__1(self):
     ts = table_.TableList()
     self.assertEqual(len(ts), 0)