Example #1
0
 def test_lookup_with_slots(self):
     s = Slots()
     s.s1 = "s1"
     self.assertEquals(safe_get_attribute(s, "s1"), "s1")
     self.assertIsInstance(safe_get_attribute_new_style(s, "s1"), member_descriptor)
     with self.assertRaises(AttributeError):
         safe_get_attribute(s, "s2")
     self.assertIsInstance(safe_get_attribute_new_style(s, "s2"), member_descriptor)
Example #2
0
 def test_lookup_on_object(self):
     a = A()
     a.x = 1
     self.assertEquals(safe_get_attribute_new_style(a, "x"), 1)
     self.assertEquals(safe_get_attribute_new_style(a, "a"), "a")
     b = B()
     b.y = 2
     self.assertEquals(safe_get_attribute_new_style(b, "y"), 2)
     self.assertEquals(safe_get_attribute_new_style(b, "a"), "a")
     self.assertEquals(safe_get_attribute_new_style(b, "b"), "b")
Example #3
0
 def test_lookup_on_object(self):
     a = A()
     a.x = 1
     self.assertEquals(safe_get_attribute_new_style(a, 'x'), 1)
     self.assertEquals(safe_get_attribute_new_style(a, 'a'), 'a')
     b = B()
     b.y = 2
     self.assertEquals(safe_get_attribute_new_style(b, 'y'), 2)
     self.assertEquals(safe_get_attribute_new_style(b, 'a'), 'a')
     self.assertEquals(safe_get_attribute_new_style(b, 'b'), 'b')
Example #4
0
 def test_lookup_with_slots(self):
     s = Slots()
     s.s1 = 's1'
     self.assertEquals(safe_get_attribute(s, 's1'), 's1')
     self.assertIsInstance(safe_get_attribute_new_style(s, 's1'),
                           member_descriptor)
     with self.assertRaises(AttributeError):
         safe_get_attribute(s, 's2')
     self.assertIsInstance(safe_get_attribute_new_style(s, 's2'),
                           member_descriptor)
Example #5
0
 def test_lookup_on_object(self):
     a = A()
     a.x = 1
     self.assertEquals(safe_get_attribute_new_style(a, 'x'), 1)
     self.assertEquals(safe_get_attribute_new_style(a, 'a'), 'a')
     b = B()
     b.y = 2
     self.assertEquals(safe_get_attribute_new_style(b, 'y'), 2)
     self.assertEquals(safe_get_attribute_new_style(b, 'a'), 'a')
     self.assertEquals(safe_get_attribute_new_style(b, 'b'), 'b')
 def test_lookup_with_slots(self):
     s = Slots()
     s.s1 = "s1"
     self.assertEqual(safe_get_attribute(s, "s1"), "s1")
     self.assertIsInstance(safe_get_attribute_new_style(s, "s1"),
                           member_descriptor)
     with self.assertRaises(AttributeError):
         safe_get_attribute(s, "s2")
     self.assertIsInstance(safe_get_attribute_new_style(s, "s2"),
                           member_descriptor)
 def test_lookup_on_object(self):
     a = A()
     a.x = 1
     self.assertEqual(safe_get_attribute_new_style(a, "x"), 1)
     self.assertEqual(safe_get_attribute_new_style(a, "a"), "a")
     b = B()
     b.y = 2
     self.assertEqual(safe_get_attribute_new_style(b, "y"), 2)
     self.assertEqual(safe_get_attribute_new_style(b, "a"), "a")
     self.assertEqual(safe_get_attribute_new_style(b, "b"), "b")
Example #8
0
    def test_raises_on_old_style_class(self):
        class Old:
            pass

        with self.assertRaises(ValueError):
            safe_get_attribute_new_style(Old, "asdf")
Example #9
0
 def test_avoid_running_properties(self):
     p = Property()
     self.assertEquals(safe_get_attribute_new_style(p, "prop"), Property.prop)
Example #10
0
    def test_raises_on_old_style_class(self):
        class Old:
            pass

        with self.assertRaises(ValueError):
            safe_get_attribute_new_style(Old, 'asdf')
Example #11
0
 def test_avoid_running_properties(self):
     p = Property()
     self.assertEquals(safe_get_attribute_new_style(p, 'prop'),
                       Property.prop)