def test_get_gets(self): """__get__ should pull from __getitem__ on owner""" self.owner['foo'] = "FunTimes!" attr = Field() attr.name = 'foo' self.owner.__class__.foo = attr self.assertEqual(self.owner.foo, 'FunTimes!')
def test_get_gets_with_type(self): """__get__ should cast value retreived to `type` if set""" attr = Field(type=int) attr.name = 'id' self.owner.__class__.id = attr self.owner['id'] = '123' self.assertEqual(self.owner.id, 123)
def test_set_sets(self): """__set__ should push to __setitem__ on owner""" attr = Field() attr.name = 'bar' self.owner.__class__.bar = attr self.owner.bar = "Setting this thing!" self.assertEqual(self.owner['bar'], 'Setting this thing!')
def test_get_gets_with_type(self): """__get__ should cast value retreived to `type` if set""" attr = Field(type=int) attr.name = 'id' self.owner.__class__.id = attr self.owner['id'] = '123' self.assertEqual(self.owner.id, 123)
def test_set_sets(self): """__set__ should push to __setitem__ on owner""" attr = Field() attr.name = 'bar' self.owner.__class__.bar = attr self.owner.bar = "Setting this thing!" self.assertEqual(self.owner['bar'], 'Setting this thing!')
def test_get_gets(self): """__get__ should pull from __getitem__ on owner""" self.owner['foo'] = "FunTimes!" attr = Field() attr.name = 'foo' self.owner.__class__.foo = attr self.assertEqual(self.owner.foo, 'FunTimes!')
def test_del_dels(self): """__delete__ should call __delitem__ on owner""" attr = Field() self.owner['baz'] = 42 attr.name = 'baz' self.owner.__class__.baz = attr del self.owner.baz assert not self.owner.dict.has_key('baz')
def test_del_dels(self): """__delete__ should call __delitem__ on owner""" attr = Field() self.owner['baz'] = 42 attr.name = 'baz' self.owner.__class__.baz = attr del self.owner.baz assert not self.owner.dict.has_key('baz')
def test_leaves_none_alone(self): """should not cast None""" attr = Field(type=int) attr.name = 'foo' self.owner.__class__.foo = attr try: self.owner.foo = None except TypeError: assert False, "should not cast None, but did"
def test_leaves_none_alone(self): """should not cast None""" attr = Field(type=int) attr.name = 'foo' self.owner.__class__.foo = attr try: self.owner.foo = None except TypeError: assert False, "should not cast None, but did"
def test_set_sets_with_type(self): attr = Field(type=int) attr.name = 'id' self.owner.__class__.id = attr self.owner.id = '123' self.assertEqual(self.owner.dict['id'], 123)
def test_set_sets_with_type(self): attr = Field(type=int) attr.name = 'id' self.owner.__class__.id = attr self.owner.id = '123' self.assertEqual(self.owner.dict['id'], 123)