summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2019-03-09 22:39:57 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-03-29 09:37:05 +0100
commiteabaf2eca73c8d3f210e7813bc68e8f3cc74676c (patch)
tree97b32de21405c7a958cf39cd76af68f5c18f239b /pylint/test
parentc14f5a34bbc6b94721ef187f10ec77b3d5784956 (diff)
downloadpylint-git-eabaf2eca73c8d3f210e7813bc68e8f3cc74676c.tar.gz
Fix - Move checker.utils tests into their dedicated unittest
It turns out there is not that much utils unittests.
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/unittest_checkers_utils.py192
-rw-r--r--pylint/test/utils/unittest_utils.py195
2 files changed, 192 insertions, 195 deletions
diff --git a/pylint/test/unittest_checkers_utils.py b/pylint/test/unittest_checkers_utils.py
index 057859c2d..74a3b6259 100644
--- a/pylint/test/unittest_checkers_utils.py
+++ b/pylint/test/unittest_checkers_utils.py
@@ -185,3 +185,195 @@ def test_inherit_from_std_ex_recursive_definition():
"""
)
assert not utils.inherit_from_std_ex(node)
+
+
+class TestGetNodeLastLineno:
+ def test_get_node_last_lineno_simple(self):
+ node = astroid.extract_node(
+ """
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 2
+
+ def test_get_node_last_lineno_if_simple(self):
+ node = astroid.extract_node(
+ """
+ if True:
+ print(1)
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 4
+
+ def test_get_node_last_lineno_if_elseif_else(self):
+ node = astroid.extract_node(
+ """
+ if True:
+ print(1)
+ elif False:
+ print(2)
+ else:
+ print(3)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 7
+
+ def test_get_node_last_lineno_while(self):
+ node = astroid.extract_node(
+ """
+ while True:
+ print(1)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 3
+
+ def test_get_node_last_lineno_while_else(self):
+ node = astroid.extract_node(
+ """
+ while True:
+ print(1)
+ else:
+ print(2)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 5
+
+ def test_get_node_last_lineno_for(self):
+ node = astroid.extract_node(
+ """
+ for x in range(0, 5):
+ print(1)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 3
+
+ def test_get_node_last_lineno_for_else(self):
+ node = astroid.extract_node(
+ """
+ for x in range(0, 5):
+ print(1)
+ else:
+ print(2)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 5
+
+ def test_get_node_last_lineno_try(self):
+ node = astroid.extract_node(
+ """
+ try:
+ print(1)
+ except ValueError:
+ print(2)
+ except Exception:
+ print(3)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 7
+
+ def test_get_node_last_lineno_try_except_else(self):
+ node = astroid.extract_node(
+ """
+ try:
+ print(1)
+ except Exception:
+ print(2)
+ print(3)
+ else:
+ print(4)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 8
+
+ def test_get_node_last_lineno_try_except_finally(self):
+ node = astroid.extract_node(
+ """
+ try:
+ print(1)
+ except Exception:
+ print(2)
+ finally:
+ print(4)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 7
+
+ def test_get_node_last_lineno_try_except_else_finally(self):
+ node = astroid.extract_node(
+ """
+ try:
+ print(1)
+ except Exception:
+ print(2)
+ else:
+ print(3)
+ finally:
+ print(4)
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 9
+
+ def test_get_node_last_lineno_with(self):
+ node = astroid.extract_node(
+ """
+ with x as y:
+ print(1)
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 4
+
+ def test_get_node_last_lineno_method(self):
+ node = astroid.extract_node(
+ """
+ def x(a, b):
+ print(a, b)
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 4
+
+ def test_get_node_last_lineno_decorator(self):
+ node = astroid.extract_node(
+ """
+ @decor()
+ def x(a, b):
+ print(a, b)
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 5
+
+ def test_get_node_last_lineno_class(self):
+ node = astroid.extract_node(
+ """
+ class C(object):
+ CONST = True
+
+ def x(self, b):
+ print(b)
+
+ def y(self):
+ pass
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 10
+
+ def test_get_node_last_lineno_combined(self):
+ node = astroid.extract_node(
+ """
+ class C(object):
+ CONST = True
+
+ def y(self):
+ try:
+ pass
+ except:
+ pass
+ finally:
+ pass
+ """
+ )
+ assert utils.get_node_last_lineno(node) == 11
diff --git a/pylint/test/utils/unittest_utils.py b/pylint/test/utils/unittest_utils.py
index c80cf2c9d..a009391de 100644
--- a/pylint/test/utils/unittest_utils.py
+++ b/pylint/test/utils/unittest_utils.py
@@ -19,9 +19,6 @@
import io
import re
-import astroid
-
-from pylint.checkers.utils import get_node_last_lineno
from pylint.utils import utils
@@ -52,195 +49,3 @@ def test_decoding_stream_known_encoding():
binary_io = io.BytesIO("€".encode("cp1252"))
stream = utils.decoding_stream(binary_io, "cp1252")
assert stream.read() == "€"
-
-
-class TestGetNodeLastLineno:
- def test_get_node_last_lineno_simple(self):
- node = astroid.extract_node(
- """
- pass
- """
- )
- assert get_node_last_lineno(node) == 2
-
- def test_get_node_last_lineno_if_simple(self):
- node = astroid.extract_node(
- """
- if True:
- print(1)
- pass
- """
- )
- assert get_node_last_lineno(node) == 4
-
- def test_get_node_last_lineno_if_elseif_else(self):
- node = astroid.extract_node(
- """
- if True:
- print(1)
- elif False:
- print(2)
- else:
- print(3)
- """
- )
- assert get_node_last_lineno(node) == 7
-
- def test_get_node_last_lineno_while(self):
- node = astroid.extract_node(
- """
- while True:
- print(1)
- """
- )
- assert get_node_last_lineno(node) == 3
-
- def test_get_node_last_lineno_while_else(self):
- node = astroid.extract_node(
- """
- while True:
- print(1)
- else:
- print(2)
- """
- )
- assert get_node_last_lineno(node) == 5
-
- def test_get_node_last_lineno_for(self):
- node = astroid.extract_node(
- """
- for x in range(0, 5):
- print(1)
- """
- )
- assert get_node_last_lineno(node) == 3
-
- def test_get_node_last_lineno_for_else(self):
- node = astroid.extract_node(
- """
- for x in range(0, 5):
- print(1)
- else:
- print(2)
- """
- )
- assert get_node_last_lineno(node) == 5
-
- def test_get_node_last_lineno_try(self):
- node = astroid.extract_node(
- """
- try:
- print(1)
- except ValueError:
- print(2)
- except Exception:
- print(3)
- """
- )
- assert get_node_last_lineno(node) == 7
-
- def test_get_node_last_lineno_try_except_else(self):
- node = astroid.extract_node(
- """
- try:
- print(1)
- except Exception:
- print(2)
- print(3)
- else:
- print(4)
- """
- )
- assert get_node_last_lineno(node) == 8
-
- def test_get_node_last_lineno_try_except_finally(self):
- node = astroid.extract_node(
- """
- try:
- print(1)
- except Exception:
- print(2)
- finally:
- print(4)
- """
- )
- assert get_node_last_lineno(node) == 7
-
- def test_get_node_last_lineno_try_except_else_finally(self):
- node = astroid.extract_node(
- """
- try:
- print(1)
- except Exception:
- print(2)
- else:
- print(3)
- finally:
- print(4)
- """
- )
- assert get_node_last_lineno(node) == 9
-
- def test_get_node_last_lineno_with(self):
- node = astroid.extract_node(
- """
- with x as y:
- print(1)
- pass
- """
- )
- assert get_node_last_lineno(node) == 4
-
- def test_get_node_last_lineno_method(self):
- node = astroid.extract_node(
- """
- def x(a, b):
- print(a, b)
- pass
- """
- )
- assert get_node_last_lineno(node) == 4
-
- def test_get_node_last_lineno_decorator(self):
- node = astroid.extract_node(
- """
- @decor()
- def x(a, b):
- print(a, b)
- pass
- """
- )
- assert get_node_last_lineno(node) == 5
-
- def test_get_node_last_lineno_class(self):
- node = astroid.extract_node(
- """
- class C(object):
- CONST = True
-
- def x(self, b):
- print(b)
-
- def y(self):
- pass
- pass
- """
- )
- assert get_node_last_lineno(node) == 10
-
- def test_get_node_last_lineno_combined(self):
- node = astroid.extract_node(
- """
- class C(object):
- CONST = True
-
- def y(self):
- try:
- pass
- except:
- pass
- finally:
- pass
- """
- )
- assert get_node_last_lineno(node) == 11