Skip to content

Commit

Permalink
Added test_func tests back in.
Browse files Browse the repository at this point in the history
  • Loading branch information
degustaf committed Dec 6, 2016
1 parent 2e692c6 commit 5ff3e04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
53 changes: 29 additions & 24 deletions pylint/test/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,68 @@

"""functional/non regression tests for pylint"""

import unittest
import sys
import re

from os import getcwd
import pytest
from os.path import abspath, dirname, join

from pylint.testutils import (make_tests, LintTestUsingModule, LintTestUsingFile,
LintTestUpdate, cb_test_gen, linter)
from pylint.testutils import get_tests_info, LintTestUsingModule, LintTestUpdate

PY3K = sys.version_info >= (3, 0)
SYS_VERS_STR = '%d%d%d' % sys.version_info[:3]

# Configure paths
INPUT_DIR = join(dirname(abspath(__file__)), 'input')
MSG_DIR = join(dirname(abspath(__file__)), 'messages')

FILTER_RGX = None
UPDATE = False

# Classes

quote = "'" if sys.version_info >= (3, 3) else ''

def gen_tests(filter_rgx):
if UPDATE:
callbacks = [cb_test_gen(LintTestUpdate)]
else:
callbacks = [cb_test_gen(LintTestUsingModule)]
tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks)
if UPDATE:
return tests

def gen_tests(filter_rgx):
if filter_rgx:
is_to_run = re.compile(filter_rgx).search
else:
is_to_run = lambda x: 1
tests = []
for module_file, messages_file in (
get_tests_info(INPUT_DIR, MSG_DIR, 'func_', '')
):
if not is_to_run(module_file) or module_file.endswith(('.pyc', "$py.class")):
continue
base = module_file.replace('func_', '').replace('.py', '')
dependencies = get_tests_info(INPUT_DIR, MSG_DIR, base, '.py')
tests.append((module_file, messages_file, dependencies))

if UPDATE:
return tests

assert len(tests) < 196, "Please do not add new test cases here."
return tests

# Create suite

FILTER_RGX = None
UPDATE = False

def suite():
return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite)
for test in gen_tests(FILTER_RGX)])

@pytest.mark.parametrize("module_file,messages_file,dependencies", gen_tests(FILTER_RGX))
def test_functionality(module_file, messages_file, dependencies):

def load_tests(loader, tests, pattern):
return suite()
LT = LintTestUpdate() if UPDATE else LintTestUsingModule()

LT.module = module_file.replace('.py', '')
LT.output = messages_file
LT.depends = dependencies or None
LT.INPUT_DIR = INPUT_DIR
LT._test_functionality()

if __name__=='__main__':
if __name__ == '__main__':
if '-u' in sys.argv:
UPDATE = True
sys.argv.remove('-u')

if len(sys.argv) > 1:
FILTER_RGX = sys.argv[1]
del sys.argv[1]
unittest.main(defaultTest='suite')
pytest.main(sys.argv)
4 changes: 4 additions & 0 deletions pylint/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ class LintTestUsingModule(unittest.TestCase):
_TEST_TYPE = 'module'
maxDiff = None

def runTest(self):
# This is a hack to make ./test/test_func.py work under pytest.
pass

def shortDescription(self):
values = {'mode' : self._TEST_TYPE,
'input': self.module,
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ setenv =
COVERAGE_FILE = {toxinidir}/.coverage.{envname}

commands =
# python -Wi {envsitepackagesdir}/coverage run -m unittest discover -s {envsitepackagesdir}/pylint/test/ -p {posargs:*test_*}.py
# python -Wi {envsitepackagesdir}/coverage run -m pytest
python -m pytest {envsitepackagesdir}/pylint/test/
python -Wi {envsitepackagesdir}/coverage run -m pytest {envsitepackagesdir}/pylint/test/

; Transform absolute path to relative path
; for compatibility with coveralls.io and fix 'source not available' error.
Expand Down

0 comments on commit 5ff3e04

Please sign in to comment.