Exemple #1
0
            self.edits.add('b', g)

    def test_config(self):
        def f(cursor_offset, line):
            return ('hi', 2)

        def g(cursor_offset, line):
            return ('hey', 3)

        self.edits.add_config_attr('att', f)
        self.assertNotIn('att', self.edits)

        class config(object):
            att = 'c'

        key_dispatch = {'c': 'c'}
        configured_edits = self.edits.mapping_with_config(config, key_dispatch)
        self.assertTrue(configured_edits.__contains__, 'c')
        self.assertNotIn('c', self.edits)
        with self.assertRaises(NotImplementedError):
            configured_edits.add_config_attr('att2', g)
        with self.assertRaises(NotImplementedError):
            configured_edits.add('d', g)
        self.assertEqual(
            configured_edits.call('c', cursor_offset=5, line='asfd'),
            ('hi', 2))


if __name__ == '__main__':
    unittest.main()
Exemple #2
0
        sga = safe_get_attribute
        s = SlotsSubclass()
        self.assertIsInstance(sga(Slots, "s1"), member_descriptor)
        self.assertIsInstance(sga(SlotsSubclass, "s1"), member_descriptor)
        self.assertIsInstance(sga(SlotsSubclass, "s4"), property)
        self.assertIsInstance(sga(s, "s4"), property)

    @unittest.skipIf(py3, "Py 3 doesn't allow slots and prop in same class")
    def test_lookup_with_property_and_slots(self):
        sga = safe_get_attribute
        s = SlotsSubclass()
        self.assertIsInstance(sga(Slots, "s3"), property)
        self.assertEquals(safe_get_attribute(s, "s3"), Slots.__dict__["s3"])
        self.assertIsInstance(sga(SlotsSubclass, "s3"), property)

    def test_lookup_on_overriden_methods(self):
        sga = safe_get_attribute
        self.assertEqual(sga(OverridenGetattr(), "a"), 1)
        self.assertEqual(sga(OverridenGetattribute(), "a"), 1)
        self.assertEqual(sga(OverridenMRO(), "a"), 1)
        with self.assertRaises(AttributeError):
            sga(OverridenGetattr(), "b")
        with self.assertRaises(AttributeError):
            sga(OverridenGetattribute(), "b")
        with self.assertRaises(AttributeError):
            sga(OverridenMRO(), "b")


if __name__ == "__main__":
    unittest.main()