diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-09-04 01:54:51 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-09-04 01:54:51 +0300 |
commit | a4e62fb0938f1fb737d0c4e7e36ec218e00e3972 (patch) | |
tree | 17e5609c2bc8c344a1d39b6a4bfda1dc43b96357 | |
parent | 20e9b6581038b21b13e6db6349a881027526ec3b (diff) | |
download | pylint-a4e62fb0938f1fb737d0c4e7e36ec218e00e3972.tar.gz |
Add missing tests.
-rw-r--r-- | pylint/test/functional/misplaced_bare_raise.py | 74 | ||||
-rw-r--r-- | pylint/test/functional/misplaced_bare_raise.txt | 6 |
2 files changed, 80 insertions, 0 deletions
diff --git a/pylint/test/functional/misplaced_bare_raise.py b/pylint/test/functional/misplaced_bare_raise.py new file mode 100644 index 0000000..1defbb4 --- /dev/null +++ b/pylint/test/functional/misplaced_bare_raise.py @@ -0,0 +1,74 @@ +# pylint: disable=missing-docstring, broad-except, unreachable
+# pylint: disable=unused-variable, too-few-public-methods, invalid-name
+
+try:
+ raise
+except Exception:
+ pass
+
+try:
+ pass
+except Exception:
+ raise
+
+try:
+ if 1 == 2:
+ raise
+except Exception:
+ raise
+
+def test():
+ try:
+ raise
+ except Exception:
+ def chest():
+ try:
+ raise
+ except Exception:
+ raise
+ raise
+
+def test1():
+ try:
+ if 1 > 2:
+ def best():
+ raise # [misplaced-bare-raise]
+ except Exception:
+ pass
+ raise # [misplaced-bare-raise]
+raise # [misplaced-bare-raise]
+
+try:
+ pass
+finally:
+ # This might work or might not to, depending if there's
+ # an error raised inside the try block. But relying on this
+ # behaviour can be error prone, so we decided to warn
+ # against it.
+ raise # [misplaced-bare-raise]
+
+
+class A(object):
+ try:
+ raise
+ except Exception:
+ raise
+ raise # [misplaced-bare-raise]
+
+# This works in Python 2, but the intent is nevertheless
+# unclear. It will also not work on Python 3, so it's best
+# not to rely on it.
+exc = None
+try:
+ 1/0
+except ZeroDivisionError as exc:
+ pass
+if exc:
+ raise # [misplaced-bare-raise]
+
+# Don't emit if we're in ``__exit__``.
+class ContextManager(object):
+ def __enter__(self):
+ return self
+ def __exit__(self, *args):
+ raise
diff --git a/pylint/test/functional/misplaced_bare_raise.txt b/pylint/test/functional/misplaced_bare_raise.txt new file mode 100644 index 0000000..75fe783 --- /dev/null +++ b/pylint/test/functional/misplaced_bare_raise.txt @@ -0,0 +1,6 @@ +misplaced-bare-raise:35:test1.best:The raise statement is not inside a try suite
+misplaced-bare-raise:38:test1:The raise statement is not inside a try suite
+misplaced-bare-raise:39::The raise statement is not inside a try suite
+misplaced-bare-raise:48::The raise statement is not inside a try suite
+misplaced-bare-raise:56:A:The raise statement is not inside a try suite
+misplaced-bare-raise:67::The raise statement is not inside a try suite
\ No newline at end of file |