Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_regr.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Copyright (c) 2006-2011, 2013-2014 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2012 FELD Boris <lothiraldan@gmail.com>
  3. # Copyright (c) 2014 Google, Inc.
  4. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  5. # Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
  6. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  7. # Copyright (c) 2016-2017 Derek Gustafson <degustaf@gmail.com>
  8. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  9. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  10. """non regression tests for pylint, which requires a too specific configuration
  11. to be incorporated in the automatic functional test framework
  12. """
  13. import sys
  14. import os
  15. from os.path import abspath, dirname, join
  16. import pytest
  17. import astroid
  18. import pylint.testutils as testutils
  19. from pylint import epylint
  20. REGR_DATA = join(dirname(abspath(__file__)), 'regrtest_data')
  21. sys.path.insert(1, REGR_DATA)
  22. try:
  23. PYPY_VERSION_INFO = sys.pypy_version_info
  24. except AttributeError:
  25. PYPY_VERSION_INFO = None
  26. @pytest.fixture(scope="module")
  27. def reporter(reporter):
  28. return testutils.TestReporter
  29. @pytest.fixture(scope="module")
  30. def disable(disable):
  31. return ['I']
  32. @pytest.fixture
  33. def finalize_linter(linter):
  34. """call reporter.finalize() to cleanup
  35. pending messages if a test finished badly
  36. """
  37. yield linter
  38. linter.reporter.finalize()
  39. def Equals(expected):
  40. return lambda got: got == expected
  41. @pytest.mark.parametrize("file_name, check", [
  42. ("package.__init__", Equals("")),
  43. ("precedence_test", Equals("")),
  44. ("import_package_subpackage_module", Equals("")),
  45. ("pylint.checkers.__init__", lambda x: '__path__' not in x),
  46. (join(REGR_DATA, "classdoc_usage.py"), Equals("")),
  47. (join(REGR_DATA, "module_global.py"), Equals("")),
  48. (join(REGR_DATA, "decimal_inference.py"), Equals("")),
  49. (join(REGR_DATA, 'absimp', 'string.py'), Equals("")),
  50. (join(REGR_DATA, 'bad_package'),
  51. lambda x: "Unused import missing" in x),
  52. ])
  53. def test_package(finalize_linter, file_name, check):
  54. finalize_linter.check(file_name)
  55. got = finalize_linter.reporter.finalize().strip()
  56. assert check(got)
  57. @pytest.mark.parametrize("file_name", [
  58. join(REGR_DATA, 'import_assign.py'),
  59. join(REGR_DATA, 'special_attr_scope_lookup_crash.py'),
  60. join(REGR_DATA, 'try_finally_disable_msg_crash'),
  61. ])
  62. def test_crash(finalize_linter, file_name):
  63. finalize_linter.check(file_name)
  64. @pytest.mark.parametrize("fname", [x for x in os.listdir(REGR_DATA)
  65. if x.endswith('_crash.py')])
  66. def test_descriptor_crash(fname, finalize_linter):
  67. finalize_linter.check(join(REGR_DATA, fname))
  68. finalize_linter.reporter.finalize().strip()
  69. @pytest.fixture
  70. def modify_path():
  71. cwd = os.getcwd()
  72. sys.path.insert(0, '')
  73. yield
  74. sys.path.pop(0)
  75. os.chdir(cwd)
  76. @pytest.mark.usefixture("modify_path")
  77. def test_check_package___init__(finalize_linter):
  78. filename = 'package.__init__'
  79. finalize_linter.check(filename)
  80. checked = list(finalize_linter.stats['by_module'].keys())
  81. assert checked == [filename]
  82. os.chdir(join(REGR_DATA, 'package'))
  83. finalize_linter.check('__init__')
  84. checked = list(finalize_linter.stats['by_module'].keys())
  85. assert checked == ['__init__']
  86. @pytest.mark.skipif(PYPY_VERSION_INFO and PYPY_VERSION_INFO < (4, 0),
  87. reason="On older PyPy versions, sys.executable was set to a value "
  88. "that is not supported by the implementation of this function. "
  89. "( https://bitbucket.org/pypy/pypy/commits/19e305e27e67 )")
  90. def test_epylint_does_not_block_on_huge_files():
  91. path = join(REGR_DATA, 'huge.py')
  92. out, err = epylint.py_run(path, return_std=True)
  93. assert hasattr(out, 'read')
  94. assert hasattr(err, 'read')
  95. output = out.read(10)
  96. assert isinstance(output, str)
  97. def test_pylint_config_attr():
  98. mod = astroid.MANAGER.ast_from_module_name('pylint.lint')
  99. pylinter = mod['PyLinter']
  100. expect = ['OptionsManagerMixIn', 'object', 'MessagesHandlerMixIn',
  101. 'ReportsHandlerMixIn', 'BaseTokenChecker', 'BaseChecker',
  102. 'OptionsProviderMixIn']
  103. assert [c.name for c in pylinter.ancestors()] == expect
  104. assert list(astroid.Instance(pylinter).getattr('config'))
  105. inferred = list(astroid.Instance(pylinter).igetattr('config'))
  106. assert len(inferred) == 1
  107. assert inferred[0].root().name == 'optparse'
  108. assert inferred[0].name == 'Values'