diff options
Diffstat (limited to 'pylint/test/unittest_checkers_utils.py')
| -rw-r--r-- | pylint/test/unittest_checkers_utils.py | 192 |
1 files changed, 192 insertions, 0 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 |
