예제 #1
0
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

    if filter_rgx:
        is_to_run = re.compile(filter_rgx).search
    else:
        is_to_run = lambda x: 1

    if is_to_run('nonexistent'):
        tests.append(LintTestNonExistentModuleTC)

    tests.append(LintBuiltinModuleTest)

    if not filter_rgx:
        # test all features are tested :)
        tests.append(TestTests)

    assert len(tests) < 196, "Please do not add new test cases here."
    return tests
예제 #2
0
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

    if filter_rgx:
        is_to_run = re.compile(filter_rgx).search
    else:
        is_to_run = lambda x: 1

    if is_to_run('nonexistent'):
        tests.append(LintTestNonExistentModuleTC)

    tests.append(LintBuiltinModuleTest)

    if not filter_rgx:
        # test all features are tested :)
        tests.append(TestTests)

    assert len(tests) < 196, "Please do not add new test cases here."
    return tests
예제 #3
0
def gen_tests(filter_rgx):
    if UPDATE:
        callbacks = [cb_test_gen(LintTestUpdate)]
    else:
        callbacks = [cb_test_gen(LintTestUsingModule)]
        if not MODULES_ONLY:
            callbacks.append(cb_test_gen(LintTestUsingFile))
    tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks)

    if UPDATE:
        return tests

    if filter_rgx:
        is_to_run = re.compile(filter_rgx).search
    else:
        is_to_run = lambda x: 1

    if is_to_run('nonexistent'):
        tests.append(LintTestNonExistentModuleTC)

    tests.append(LintBuiltinModuleTest)

    if not filter_rgx:
        # test all features are tested :)
        tests.append(TestTests)

    return tests
예제 #4
0
def tests():
    callbacks = [cb_test_gen(LintTestUsingModule), cb_test_gen(LintTestUsingFile)]

    input_dir = os.path.join(HERE, 'input')
    messages_dir = os.path.join(HERE, 'messages')

    return make_tests(input_dir, messages_dir, None, callbacks)
예제 #5
0
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

    if filter_rgx:
        is_to_run = re.compile(filter_rgx).search
    else:
        is_to_run = lambda x: 1

    assert len(tests) < 196, "Please do not add new test cases here."
    return tests
예제 #6
0
def tests(input_dir, messages_dir):
    callbacks = [cb_test_gen(LintTestUsingFile)]

    input_dir = os.path.join(HERE, input_dir)
    messages_dir = os.path.join(HERE, messages_dir)

    return make_tests(input_dir, messages_dir, None, callbacks)
예제 #7
0
def tests(input_dir, messages_dir):
    callbacks = [cb_test_gen(LintTestUsingFile)]

    input_dir = os.path.join(HERE, input_dir)
    messages_dir = os.path.join(HERE, messages_dir)

    return make_tests(input_dir, messages_dir, None, callbacks)
예제 #8
0
def load_tests(loader, tests, pattern):
    # Have to import this in the function, because the module does
    # initialization on import! ugh.
    from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter

    # Load our plugin.
    linter.load_plugin_modules(['edx_lint.pylint'])

    # Configure the linter that runs the tests.

    # This line prevents pylint from complaining about missing __revision__ in
    # all the test files. But is this removing other required attributes that
    # maybe we do want to check for?
    linter.global_set_option('required-attributes', ())

    here = os.path.dirname(os.path.abspath(__file__))

    tests = make_tests(
        input_dir=os.path.join(here, 'input'),
        msg_dir=os.path.join(here, 'messages'),
        filter_rgx=None,
        callbacks=[cb_test_gen(LintTestUsingFile)],
    )

    cls = testlib.TestSuite
    return cls(unittest.makeSuite(test, suiteClass=cls) for test in tests)
예제 #9
0
def load_tests(unused_loader, tests, unused_pattern):
    """Loads tests for the pylint test loader.

    This function is automatically run by pylint's test runner, and is called
    with three arguments, two of which we don't need.

    """
    # Have to import this in the function, because the module does
    # initialization on import! ugh.
    from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter

    # Load our plugin.
    linter.load_plugin_modules(['edx_lint.pylint'])
    linter.global_set_option('required-attributes', ())

    here = os.path.dirname(os.path.abspath(__file__))

    tests = make_tests(
        input_dir=os.path.join(here, 'input'),
        msg_dir=os.path.join(here, 'messages'),
        filter_rgx=None,
        callbacks=[cb_test_gen(LintTestUsingFile)],
    )

    cls = unittest.TestSuite
    return cls(unittest.makeSuite(test, suiteClass=cls) for test in tests)
예제 #10
0
파일: test_func.py 프로젝트: PyCQA/pylint
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

    if filter_rgx:
        is_to_run = re.compile(filter_rgx).search
    else:
        is_to_run = lambda x: 1

    assert len(tests) < 196, "Please do not add new test cases here."
    return tests
예제 #11
0
파일: test.py 프로젝트: geerk/django_linter
def suite():
    input_dir = os.path.join(os.path.dirname(__file__), 'input')
    msg_dir = os.path.join(os.path.dirname(__file__), 'messages')
    linter.load_plugin_modules(['django_linter'])
    linter.set_option('disable', 'R0901,C0111')
    return unittest.TestSuite([
        unittest.makeSuite(test, suiteClass=unittest.TestSuite)
        for test in make_tests(
            input_dir, msg_dir, None, [cb_test_gen(LintTestUsingFile)])])
def MakeFunctionalTests():
  class PluginFunctionalTest(testutils.LintTestUsingFile):
    """Functional test which registers the lint_autotest plugin."""

    def setUp(self):
      """Save the state of the pylint plugins, then monkey patch them."""
      # While developer desktop environments will probably fail the "import
      # common" import, the test machines won't. By mocking out the
      # _IGNORE_MODULES list to use a different module name, the test will pass
      # regardless of whether the environment has a "common" module to import.
      self.context = mock.patch.object(
          lint_autotest, '_IGNORE_MODULES',
          ('lint_autotest_integration_test_example_module',))

      self.context.__enter__()

      classes = (
          base.DocStringChecker,
          imports.ImportsChecker,
          variables.VariablesChecker
      )
      # note: copy.copy doesn't work on DictProxy objects. Converting the
      # DictProxy to a dictionary works.
      self.old_state = {cls: dict(cls.__dict__) for cls in classes}
      lint_autotest.register(testutils.linter)

    def tearDown(self):
      """Reset the damage done by lint_autotest.register(...)"""
      self.context.__exit__(None, None, None)
      for cls, old_dict in self.old_state.items():
        # .__dict__ is not writeable. Copy over k,v pairs.
        for k, v in old_dict.items():
          # Some attributes are not writeable. Only fix the ones that changed.
          if cls.__dict__[k] is not v:
            setattr(cls, k, v)

      super(PluginFunctionalTest, self).tearDown()

  callbacks = [testutils.cb_test_gen(PluginFunctionalTest)]
  tests = testutils.make_tests(INPUT_DIR, MESSAGE_DIR, None, callbacks)
  for i, test in enumerate(tests):
    globals()['FunctionalTest%d' % i] = test
예제 #13
0
def load_tests(loader, tests, pattern):
    # Have to import this in the function, because the module does
    # initialization on import! ugh.
    from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter

    # Load our plugin, and disable messages we don't want noising up our tests.
    linter.load_plugin_modules(['edx_lint.pylint'])
    linter.disable("missing-module-attribute")

    here = os.path.dirname(os.path.abspath(__file__))

    tests = make_tests(
        input_dir=os.path.join(here, 'input'),
        msg_dir=os.path.join(here, 'messages'),
        filter_rgx=None,
        callbacks=[cb_test_gen(LintTestUsingFile)],
    )

    cls = testlib.TestSuite
    return cls(unittest.makeSuite(test, suiteClass=cls) for test in tests)
예제 #14
0
def tests(input_dir, messages_dir):
    callbacks = [cb_test_gen(LintTestUsingFile)]

    input_dir = os.path.join(HERE, input_dir)
    messages_dir = os.path.join(HERE, messages_dir)

    # first tests which pass for all Django versions
    tests = make_tests(input_dir, messages_dir, None, callbacks)

    # now skip some tests test for specific versions - for example,
    # _meta access should not work for django<1.8 but should run and
    # pass for django 1.4 - skip the tests which will be checking
    # a piece of functionality in pylint-django that should only
    # in higher versions.
    specific_tests = []
    for test_name, version_range in SKIP_TESTS_FOR_DJANGO_VERSION:
        if not version_range:
            specific_tests.append(test_name)
    filter_rgx = '(%s)' % '|'.join(specific_tests)

    tests += make_tests(os.path.join(input_dir, 'versions'), messages_dir, filter_rgx, callbacks)
    return tests
예제 #15
0
def tests(input_dir, messages_dir):
    callbacks = [cb_test_gen(LintTestUsingFile)]

    input_dir = os.path.join(HERE, input_dir)
    messages_dir = os.path.join(HERE, messages_dir)

    # first tests which pass for all Django versions
    tests = make_tests(input_dir, messages_dir, None, callbacks)

    # now skip some tests test for specific versions - for example,
    # _meta access should not work for django<1.8 but should run and
    # pass for django 1.4 - skip the tests which will be checking
    # a piece of functionality in pylint-django that should only
    # in higher versions.
    specific_tests = []
    for test_name, version_range in SKIP_TESTS_FOR_DJANGO_VERSION:
        if not version_range:
            specific_tests.append(test_name)
    filter_rgx = '(%s)' % '|'.join(specific_tests)

    tests += make_tests(os.path.join(input_dir, 'versions'), messages_dir,
                        filter_rgx, callbacks)
    return tests
예제 #16
0
from os.path import join, dirname, abspath
import unittest
from pylint.testutils import make_tests, LintTestUsingModule, LintTestUsingFile, cb_test_gen, linter
import sys


INPUT_DIR = join(dirname(abspath(__file__)), 'input')
MESSAGES_DIR = join(dirname(abspath(__file__)), 'messages')
CALLBACKS = [cb_test_gen(LintTestUsingModule), cb_test_gen(LintTestUsingFile)]
FILTER_RGX = None


linter.load_plugin_modules(['pylint_common'])
linter.global_set_option('required-attributes', ())  # remove required __revision__


def suite():
    return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite)
                              for test in make_tests(INPUT_DIR, MESSAGES_DIR,
                                                     FILTER_RGX, CALLBACKS)])

if __name__=='__main__':
    if len(sys.argv) > 1:
        FILTER_RGX = sys.argv[1]
        del sys.argv[1]
    unittest.main(defaultTest='suite')

예제 #17
0
from os.path import join, dirname, abspath
import unittest
from logilab.common import testlib
from pylint.testutils import make_tests, LintTestUsingModule, LintTestUsingFile, cb_test_gen, linter
import sys

INPUT_DIR = join(dirname(abspath(__file__)), 'input')
MESSAGES_DIR = join(dirname(abspath(__file__)), 'messages')
CALLBACKS = [cb_test_gen(LintTestUsingModule), cb_test_gen(LintTestUsingFile)]
FILTER_RGX = None

linter.load_plugin_modules(['pylint_common'])
linter.global_set_option('required-attributes',
                         ())  # remove required __revision__


def suite():
    return testlib.TestSuite([
        unittest.makeSuite(test, suiteClass=testlib.TestSuite)
        for test in make_tests(INPUT_DIR, MESSAGES_DIR, FILTER_RGX, CALLBACKS)
    ])


if __name__ == '__main__':
    if len(sys.argv) > 1:
        FILTER_RGX = sys.argv[1]
        del sys.argv[1]
    testlib.unittest_main(defaultTest='suite')
예제 #18
0
            self.assertEqual(todo, rest)
        else:
            self.assertEqual(todo, ['I0001'])


class LintBuiltinModuleTest(LintTestUsingModule):
    output = join(MSG_DIR, 'builtin_module.txt')
    module = 'sys'

    def test_functionality(self):
        self._test(['sys'])


# Callbacks

base_cb_file = cb_test_gen(LintTestUsingFile)


def cb_file(*args):
    if MODULES_ONLY:
        return None
    else:
        return base_cb_file(*args)


callbacks = [cb_test_gen(LintTestUsingModule), cb_file]

# Gen tests


def gen_tests(filter_rgx):
예제 #19
0
                    'W0403', # implicit relative import
                    'W0410', # __future__ import not first statement
                    ]
            self.assertEqual(todo, rest)
        else:
            self.assertEqual(todo, ['I0001'])

class LintBuiltinModuleTest(LintTestUsingModule):
    output = join(MSG_DIR, 'builtin_module.txt')
    module = 'sys'
    def test_functionality(self):
        self._test(['sys'])

# Callbacks

base_cb_file = cb_test_gen(LintTestUsingFile)

def cb_file(*args):
    if MODULES_ONLY:
        return None
    else:
        return base_cb_file(*args)

callbacks = [cb_test_gen(LintTestUsingModule),
             cb_file]

# Gen tests

def gen_tests(filter_rgx):
    tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks)