Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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")
Exemplo n.º 8
0
    def test_raises_on_old_style_class(self):
        class Old:
            pass

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

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