Example #1
0
 def test_isinstance_warnings(self):
     msg_format = ("%r is deprecated and slated for removal in astroid "
                   "2.0, use %r instead")
     for cls in (nodes.Discard, nodes.Backquote, nodes.AssName,
                 nodes.AssAttr, nodes.Getattr, nodes.CallFunc, nodes.From):
         with warnings.catch_warnings(record=True) as w:
             with test_utils.enable_warning(PendingDeprecationWarning):
                 isinstance(42, cls)
         self.assertIsInstance(w[0].message, PendingDeprecationWarning)
         actual_msg = msg_format % (cls.__class__.__name__, cls.__wrapped__.__name__)
         self.assertEqual(str(w[0].message), actual_msg)
Example #2
0
    def test_asstype_warnings(self):
        string = '''
        class C: pass
        c = C()
        with warnings.catch_warnings(record=True) as w:
            pass
        '''
        module = parse(string)
        filter_stmts_mixin = module.body[0]
        assign_type_mixin = module.body[1].targets[0]
        parent_assign_type_mixin = module.body[2]

        with warnings.catch_warnings(record=True) as w:
            with test_utils.enable_warning(PendingDeprecationWarning):
                filter_stmts_mixin.ass_type()
                self.assertIsInstance(w[0].message, PendingDeprecationWarning)
        with warnings.catch_warnings(record=True) as w:
            with test_utils.enable_warning(PendingDeprecationWarning):
                assign_type_mixin.ass_type()
                self.assertIsInstance(w[0].message, PendingDeprecationWarning)
        with warnings.catch_warnings(record=True) as w:
            with test_utils.enable_warning(PendingDeprecationWarning):
                parent_assign_type_mixin.ass_type()
                self.assertIsInstance(w[0].message, PendingDeprecationWarning)