Exemple #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
Exemple #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
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)
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
Exemple #5
0
def suite():
    return testlib.TestSuite(
        [
            unittest.makeSuite(test, suiteClass=testlib.TestSuite)
            for test in make_tests(INPUT_DIR, MESSAGES_DIR, FILTER_RGX, CALLBACKS)
        ]
    )
Exemple #6
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)
Exemple #7
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)
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)
Exemple #9
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)
Exemple #10
0
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)])])
Exemple #11
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
Exemple #12
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
Exemple #13
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
Exemple #14
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
Exemple #15
0
def gen_tests(filter_rgx):
    tests = make_tests(INPUT_DIR, MSG_DIR, filter_rgx, callbacks)

    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
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
Exemple #17
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)
Exemple #18
0
def suite():
    return testlib.TestSuite([
        unittest.makeSuite(test, suiteClass=testlib.TestSuite)
        for test in make_tests(INPUT_DIR, MESSAGES_DIR, FILTER_RGX, CALLBACKS)
    ])