Example #1
0
    def test__fielditer__1(self):
        dogs = Dogs()
        persons = Persons()
        dog = DogRec(('Snoopy',12), dogs)
        person = PersonRec(('John', 'Smith', 'New York'), persons)

        rs = record_.RecordSequence((dog, person))
        it = functions_.fielditer(rs)

        fld = next(it)
        self.assertIs(fld.record, dog)
        self.assertIs(fld.index, 0)

        fld = next(it)
        self.assertIs(fld.record, dog)
        self.assertIs(fld.index, 1)

        fld = next(it)
        self.assertIs(fld.record, person)
        self.assertIs(fld.index, 0)

        fld = next(it)
        self.assertIs(fld.record, person)
        self.assertIs(fld.index, 1)

        fld = next(it)
        self.assertIs(fld.record, person)
        self.assertIs(fld.index, 2)

        with self.assertRaises(StopIteration): next(it)
Example #2
0
 def test__delitem__2(self):
     dogs = Dogs()
     persons = Persons()
     dog = DogRec(('Snoopy',12), dogs)
     person = PersonRec(('John', 'Smith', 'New York'), persons)
     rs = record_.RecordSequence((dog, person))
     del rs[:]
     self.assertEqual(len(rs), 0)
Example #3
0
    def test__setitem__3(self):
        dogs = Dogs()
        persons = Persons()
        dog = DogRec(('Snoopy',12), dogs)
        person = PersonRec(('John', 'Smith', 'New York'), persons)
        ts = record_.RecordSequence((dog, person))

        with self.assertRaisesRegex(TypeError, "%s is not an instance of %s" % (repr('foo'), repr(record_.Record))):
            ts[0] = 'foo'
Example #4
0
 def test__init__2(self):
     dogs = Dogs()
     persons = Persons()
     dog = DogRec(('Snoopy',12), dogs)
     person = PersonRec(('John', 'Smith', 'New York'), persons)
     ts = record_.RecordSequence((dog, person))
     self.assertEqual(len(ts._data), 2)
     self.assertIs(ts._data[0], dog)
     self.assertIs(ts._data[1], person)
Example #5
0
 def test__getitem__1(self):
     dogs = Dogs()
     persons = Persons()
     dog = DogRec(('Snoopy',12), dogs)
     person = PersonRec(('John', 'Smith', 'New York'), persons)
     ts = record_.RecordSequence((dog, person))
     self.assertIs(ts[0], dog)
     self.assertIs(ts[1], person)
     with self.assertRaises(IndexError): ts[ 2]
     with self.assertRaises(IndexError): ts[-3]
Example #6
0
    def test__setitem__2(self):
        dogs = Dogs()
        persons = Persons()
        dog = DogRec(('Snoopy',12), dogs)
        person = PersonRec(('John', 'Smith', 'New York'), persons)
        records = [dog, person]

        rs = record_.RecordSequence()
        rs[:] = records

        self.assertEqual(len(rs), 2)
        self.assertIs(rs[0], dog)
        self.assertIs(rs[1], person)
Example #7
0
    def test__insert__1(self):
        dogs = Dogs()
        persons = Persons()
        cars = Cars()
        dog = DogRec(('Snoopy',12), dogs)
        person = PersonRec(('John', 'Smith', 'New York'), persons)
        car = CarRec(('Chevrolet', 12000), cars)

        rs = record_.RecordSequence((dog, person))

        rs.insert(1, car)
        self.assertEqual(len(rs), 3)
        self.assertIs(rs[0], dog)
        self.assertIs(rs[1], car)
        self.assertIs(rs[2], person)
Example #8
0
    def test__delitem__1(self):
        dogs = Dogs()
        persons = Persons()
        dog = DogRec(('Snoopy',12), dogs)
        person = PersonRec(('John', 'Smith', 'New York'), persons)
        rs = record_.RecordSequence((dog, person))

        self.assertEqual(len(rs), 2)
        del rs[0]
        self.assertEqual(len(rs), 1)
        self.assertIs(rs[0], person)

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

        with self.assertRaises(IndexError): del rs[0]
Example #9
0
 def test__init__1(self):
     ts = record_.RecordSequence()
     self.assertEqual(len(ts), 0)