blob: 4a8ffc806dfe629cd3f59291d8c2f40617a0666f [file] [log] [blame]
# Copyright (c) 2015-2018, 2020 Claudiu Popa <[email protected]>
# Copyright (c) 2015 Rene Zhang <[email protected]>
# Copyright (c) 2015 Steven Myint <[email protected]>
# Copyright (c) 2015 Pavel Roskin <[email protected]>
# Copyright (c) 2015 Ionel Cristian Maries <[email protected]>
# Copyright (c) 2016 Derek Gustafson <[email protected]>
# Copyright (c) 2018 Brian Shaginaw <[email protected]>
# Copyright (c) 2019 Ashley Whetter <[email protected]>
# Copyright (c) 2020-2021 Pierre Sassoulas <[email protected]>
# Copyright (c) 2020 hippo91 <[email protected]>
# Copyright (c) 2021 Marc Mueller <[email protected]>
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
"""Tests for pylint.checkers.exceptions."""
import astroid
from pylint.checkers import exceptions
from pylint.testutils import CheckerTestCase, Message
class TestExceptionsChecker(CheckerTestCase):
"""Tests for pylint.checkers.exceptions."""
CHECKER_CLASS = exceptions.ExceptionsChecker
# These tests aren't in the functional test suite,
# since they will be converted with 2to3 for Python 3
# and `raise (Error, ...)` will be converted to
# `raise Error(...)`, so it beats the purpose of the test.
def test_raising_bad_type_python3(self):
node = astroid.extract_node("raise (ZeroDivisionError, None) #@")
message = Message("raising-bad-type", node=node, args="tuple")
with self.assertAddsMessages(message):
self.checker.visit_raise(node)
def test_bad_exception_context_function(self):
node = astroid.extract_node(
"""
def function():
pass
try:
pass
except function as exc:
raise Exception from exc #@
"""
)
message = Message("bad-exception-context", node=node)
with self.assertAddsMessages(message):
self.checker.visit_raise(node)