Beispiel #1
0
 def test__init__3(self):
     dogs = Dogs()
     dog = DogRec(('Snoopy', 12), dogs)
     with self.assertRaisesRegex(IndexError, "record field index out of range"):
         record_.RecordFieldProxy(dog, -3)
     with self.assertRaisesRegex(IndexError, "record field index out of range"):
         record_.RecordFieldProxy(dog, 2)
Beispiel #2
0
    def test__index__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertEqual(fld.index, 0)

        fld = record_.RecordFieldProxy(dog, -1)
        self.assertEqual(fld.index, -1)
Beispiel #3
0
    def test__modelname__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertEqual(fld.modelname, "Dog['name']")
        self.assertEqual(functions_.modelname(fld), "Dog['name']")

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertEqual(fld.modelname, "Dog['age']")
        self.assertEqual(functions_.modelname(fld), "Dog['age']")
Beispiel #4
0
    def test__schemaname__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertEqual(fld.schemaname, 'dogs.name')
        self.assertEqual(functions_.schemaname(fld), 'dogs.name')

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertEqual(fld.schemaname, 'dogs.age')
        self.assertEqual(functions_.schemaname(fld), 'dogs.age')
Beispiel #5
0
    def test__value__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertIs(fld.value, dog.values()[0])

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertIs(fld.value, dog.values()[1])

        fld = record_.RecordFieldProxy(dog, -1)
        self.assertIs(fld.value, dog.values()[-1])

        fld = record_.RecordFieldProxy(dog, -2)
        self.assertIs(fld.value, dog.values()[-2])
Beispiel #6
0
    def test__key__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertEqual(fld.key, DogRec.keys()[0])

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertEqual(fld.key, DogRec.keys()[1])

        fld = record_.RecordFieldProxy(dog, -1)
        self.assertEqual(fld.key, DogRec.keys()[-1])

        fld = record_.RecordFieldProxy(dog, -2)
        self.assertEqual(fld.key, DogRec.keys()[-2])
Beispiel #7
0
    def test__init__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        self.assertIs(fld._record, dog)
        self.assertEqual(fld._index, 0)

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertIs(fld._record, dog)
        self.assertEqual(fld._index, 1)

        fld = record_.RecordFieldProxy(dog, -2)
        self.assertIs(fld._record, dog)
        self.assertEqual(fld._index, -2)
Beispiel #8
0
    def test__modelname_setter__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        with self.assertRaisesRegex(AttributeError, "can't set attribute"):
            fld.modelname = 'foo'
Beispiel #9
0
    def test__entityclass_setter__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        with self.assertRaisesRegex(AttributeError, "can't set attribute"):
            fld.entityclass = Dog(('Snoopy',12))
Beispiel #10
0
    def test__entityclass__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertIs(fld.entityclass, Dog)
        self.assertIs(functions_.entityclass(fld), Dog)
Beispiel #11
0
    def test__value_setter__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 0)
        fld.value = 'Lessie'

        self.assertEqual(dog[0], 'Lessie')
Beispiel #12
0
 def test__recordclass_setter__1(self):
     dogs = Dogs()
     dog = DogRec(('Snoopy', 12), dogs)
     persons = Persons()
     person = PersonRec(('John', 'Smith', 'New York'), persons)
     fld = record_.RecordFieldProxy(dog, 0)
     with self.assertRaisesRegex(AttributeError, "can't set attribute"):
         fld.record = person
Beispiel #13
0
    def test__type__1(self):
        class MyEnt(entity_.Entity):
            _keys = keystuple_.KeysTuple(('foo', 'bar'))
            _types = (str,int)
        class MyTab(table_.Table):
            _entityclass = MyEnt
        class MyRec(record_.Record):
            _entityclass = MyEnt
            _tableclass = MyTab

        tab = MyTab()
        rec = MyRec(('FOO','BAR'), tab)

        fld = record_.RecordFieldProxy(rec, 0)
        self.assertIs(fld.type, MyEnt.types()[0])

        fld = record_.RecordFieldProxy(rec, 1)
        self.assertIs(fld.type, MyEnt.types()[1])

        fld = record_.RecordFieldProxy(rec, -1)
        self.assertIs(fld.type, MyEnt.types()[-1])

        fld = record_.RecordFieldProxy(rec, -2)
        self.assertIs(fld.type, MyEnt.types()[-2])
Beispiel #14
0
    def test__repr__1(self):
        dogs = Dogs()
        dog = DogRec(('Snoopy', 12), dogs)

        fld = record_.RecordFieldProxy(dog, 1)
        self.assertEqual(repr(fld), "%s(%s,%d)" % (functions_.modelname(fld), functions_.modelname(DogRec), 1))
Beispiel #15
0
 def test__init__2(self):
     with self.assertRaisesRegex(TypeError, "%s is not an instance of %s" % (repr('foo'), repr(record_.Record))):
         record_.RecordFieldProxy('foo', 1)