Example #1
0
 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!')
Example #2
0
 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)
Example #3
0
 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!')
Example #4
0
 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)
Example #5
0
 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!')
Example #6
0
 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!')
Example #7
0
 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')
Example #8
0
 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')
Example #9
0
 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"
Example #10
0
 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"
Example #11
0
 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)
Example #12
0
 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)