2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2015-2018 Claudiu Popa <pcmanticore@gmail.com>
|
2016-07-22 21:22:28 +00:00
|
|
|
# Copyright (c) 2015 Rene Zhang <rz99@cornell.edu>
|
|
|
|
# Copyright (c) 2015 Steven Myint <hg@stevenmyint.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2015 Pavel Roskin <proski@gnu.org>
|
|
|
|
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
|
|
|
|
# Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2018 Brian Shaginaw <brian.shaginaw@warbyparker.com>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
|
2015-01-02 14:15:31 +00:00
|
|
|
"""Tests for pylint.checkers.exceptions."""
|
2016-06-29 16:32:16 +00:00
|
|
|
import astroid
|
|
|
|
|
2015-01-02 14:15:31 +00:00
|
|
|
from pylint.checkers import exceptions
|
|
|
|
from pylint.testutils import CheckerTestCase, Message
|
|
|
|
|
|
|
|
|
2016-12-06 15:42:53 +00:00
|
|
|
class TestExceptionsChecker(CheckerTestCase):
|
2015-01-02 14:15:31 +00:00
|
|
|
"""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):
|
2018-09-16 15:33:50 +00:00
|
|
|
node = astroid.extract_node("raise (ZeroDivisionError, None) #@")
|
|
|
|
message = Message("raising-bad-type", node=node, args="tuple")
|
2015-01-02 14:15:31 +00:00
|
|
|
with self.assertAddsMessages(message):
|
|
|
|
self.checker.visit_raise(node)
|
|
|
|
|
2018-01-12 18:33:16 +00:00
|
|
|
def test_bad_exception_context_function(self):
|
2018-09-16 15:33:50 +00:00
|
|
|
node = astroid.extract_node(
|
|
|
|
"""
|
2018-01-12 18:33:16 +00:00
|
|
|
def function():
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except function as exc:
|
|
|
|
raise Exception from exc #@
|
2018-09-16 15:33:50 +00:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
message = Message("bad-exception-context", node=node)
|
2018-01-12 18:33:16 +00:00
|
|
|
with self.assertAddsMessages(message):
|
|
|
|
self.checker.visit_raise(node)
|