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