예제 #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)
예제 #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)
예제 #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']")
예제 #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')
예제 #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])
예제 #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])
예제 #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)
예제 #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'
예제 #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))
예제 #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)
예제 #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')
예제 #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
예제 #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])
예제 #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))
예제 #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)