diff options
author | Derek Gustafson <degustaf@gmail.com> | 2016-12-06 15:42:53 +0000 |
---|---|---|
committer | Derek Gustafson <degustaf@gmail.com> | 2016-12-06 16:07:00 +0000 |
commit | 4faacf211922fbb5a02260dad36a0dbc9d6b6ca6 (patch) | |
tree | e99ebc5faa309c10a08f74b34eea54221d3fd985 /pylint/test/unittest_checkers_utils.py | |
parent | 72ea777b1f601aa8d227b8a7d085f5d2d12471d7 (diff) | |
download | pylint-git-4faacf211922fbb5a02260dad36a0dbc9d6b6ca6.tar.gz |
Reduce dependency on unittest
Diffstat (limited to 'pylint/test/unittest_checkers_utils.py')
-rw-r--r-- | pylint/test/unittest_checkers_utils.py | 143 |
1 files changed, 69 insertions, 74 deletions
diff --git a/pylint/test/unittest_checkers_utils.py b/pylint/test/unittest_checkers_utils.py index 95c16e745..c95112330 100644 --- a/pylint/test/unittest_checkers_utils.py +++ b/pylint/test/unittest_checkers_utils.py @@ -6,89 +6,84 @@ """Tests for the pylint.checkers.utils module.""" -import unittest -import warnings - import astroid from pylint.checkers import utils -from pylint import __pkginfo__ import pytest -class UtilsTC(unittest.TestCase): - - def test_is_builtin(self): - assert utils.is_builtin('min') == True - assert utils.is_builtin('__builtins__') == True - assert utils.is_builtin('__path__') == False - assert utils.is_builtin('__file__') == False - assert utils.is_builtin('whatever') == False - assert utils.is_builtin('mybuiltin') == False +def test_is_builtin(): + assert utils.is_builtin('min') is True + assert utils.is_builtin('__builtins__') is True + assert utils.is_builtin('__path__') is False + assert utils.is_builtin('__file__') is False + assert utils.is_builtin('whatever') is False + assert utils.is_builtin('mybuiltin') is False - def testGetArgumentFromCall(self): - node = astroid.extract_node('foo(bar=3)') - assert utils.get_argument_from_call(node, keyword='bar') is not None - with pytest.raises(utils.NoSuchArgumentError): - node = astroid.extract_node('foo(3)') - utils.get_argument_from_call(node, keyword='bar') - with pytest.raises(utils.NoSuchArgumentError): - node = astroid.extract_node('foo(one=a, two=b, three=c)') - utils.get_argument_from_call(node, position=1) - node = astroid.extract_node('foo(a, b, c)') - assert utils.get_argument_from_call(node, position=1) is not None - node = astroid.extract_node('foo(a, not_this_one=1, this_one=2)') - arg = utils.get_argument_from_call(node, position=2, keyword='this_one') - assert 2 == arg.value - node = astroid.extract_node('foo(a)') - with pytest.raises(utils.NoSuchArgumentError): - utils.get_argument_from_call(node, position=1) - with pytest.raises(ValueError): - utils.get_argument_from_call(node, None, None) +def testGetArgumentFromCall(): + node = astroid.extract_node('foo(bar=3)') + assert utils.get_argument_from_call(node, keyword='bar') is not None + with pytest.raises(utils.NoSuchArgumentError): + node = astroid.extract_node('foo(3)') + utils.get_argument_from_call(node, keyword='bar') + with pytest.raises(utils.NoSuchArgumentError): + node = astroid.extract_node('foo(one=a, two=b, three=c)') + utils.get_argument_from_call(node, position=1) + node = astroid.extract_node('foo(a, b, c)') + assert utils.get_argument_from_call(node, position=1) is not None + node = astroid.extract_node('foo(a, not_this_one=1, this_one=2)') + arg = utils.get_argument_from_call(node, position=2, keyword='this_one') + assert 2 == arg.value + node = astroid.extract_node('foo(a)') + with pytest.raises(utils.NoSuchArgumentError): + utils.get_argument_from_call(node, position=1) + with pytest.raises(ValueError): + utils.get_argument_from_call(node, None, None) - name = utils.get_argument_from_call(node, position=0) - assert name.name == 'a' + name = utils.get_argument_from_call(node, position=0) + assert name.name == 'a' - def test_error_of_type(self): - nodes = astroid.extract_node(""" - try: pass - except AttributeError: #@ - pass - try: pass - except Exception: #@ - pass - except: #@ - pass - """) - assert utils.error_of_type(nodes[0], AttributeError) - assert utils.error_of_type(nodes[0], (AttributeError, )) - assert not utils.error_of_type(nodes[0], Exception) - assert utils.error_of_type(nodes[1], Exception) - assert not utils.error_of_type(nodes[2], ImportError) +def test_error_of_type(): + nodes = astroid.extract_node(""" + try: pass + except AttributeError: #@ + pass + try: pass + except Exception: #@ + pass + except: #@ + pass + """) + assert utils.error_of_type(nodes[0], AttributeError) + assert utils.error_of_type(nodes[0], (AttributeError, )) + assert not utils.error_of_type(nodes[0], Exception) + assert utils.error_of_type(nodes[1], Exception) + assert not utils.error_of_type(nodes[2], ImportError) - def test_node_ignores_exception(self): - nodes = astroid.extract_node(""" - try: - 1/0 #@ - except ZeroDivisionError: - pass - try: - 1/0 #@ - except Exception: - pass - try: - 2/0 #@ - except: - pass - try: - 1/0 #@ - except ValueError: - pass - """) - assert utils.node_ignores_exception(nodes[0], ZeroDivisionError) - assert not utils.node_ignores_exception(nodes[1], ZeroDivisionError) - assert not utils.node_ignores_exception(nodes[2], ZeroDivisionError) - assert not utils.node_ignores_exception(nodes[3], ZeroDivisionError) +def test_node_ignores_exception(): + nodes = astroid.extract_node(""" + try: + 1/0 #@ + except ZeroDivisionError: + pass + try: + 1/0 #@ + except Exception: + pass + try: + 2/0 #@ + except: + pass + try: + 1/0 #@ + except ValueError: + pass + """) + assert utils.node_ignores_exception(nodes[0], ZeroDivisionError) + assert not utils.node_ignores_exception(nodes[1], ZeroDivisionError) + assert not utils.node_ignores_exception(nodes[2], ZeroDivisionError) + assert not utils.node_ignores_exception(nodes[3], ZeroDivisionError) if __name__ == '__main__': - unittest.main() + import sys + pytest.main(sys.argv) |