Ejemplo n.º 1
0
    def test_legacy_names_equivalent(self):
        """
        'pep8' tool was renamed to pycodestyle, 'pep257' tool was renamed to pydocstyle

        This test is to ensure that, for backwards compatibility until it is removed in prospector 2.0,
        that the old names and the new names are equivalent in profiles
        """
        profile_old = ProspectorProfile.load("renaming_oldname",
                                             self._profile_path,
                                             allow_shorthand=False)
        profile_new = ProspectorProfile.load("renaming_newname",
                                             self._profile_path,
                                             allow_shorthand=False)

        # do they serialise to the same thing?
        for tool in ("pycodestyle", "pydocstyle"):
            old_dict = profile_old.as_dict()[tool]
            new_dict = profile_new.as_dict()[tool]
            self.assertListEqual(sorted(old_dict["disable"]),
                                 sorted(new_dict["disable"]))
            self.assertListEqual(sorted(old_dict["enable"]),
                                 sorted(new_dict["enable"]))
        self.assertDictEqual(profile_old.as_dict(), profile_new.as_dict())

        # do they have the same settings for everything?
        for prof in (profile_old, profile_new):
            self.assertTrue(prof.is_tool_enabled("pycodestyle"))
            self.assertTrue(prof.is_tool_enabled("pydocstyle"))
            self.assertEqual(prof.pycodestyle["options"]["max-line-length"],
                             120)
Ejemplo n.º 2
0
 def test_simple_inheritance(self):
     profile = ProspectorProfile.load("inherittest3",
                                      self._profile_path,
                                      allow_shorthand=False)
     disable = profile.pylint["disable"]
     disable.sort()
     self.assertEqual(["I0002", "I0003", "raw-checker-failed"], disable)
Ejemplo n.º 3
0
 def test_empty_disable_list(self):
     """
     This test verifies that a profile can still be loaded if it contains
     an empty 'pylint.disable' list
     """
     profile = ProspectorProfile.load('empty_disable_list', self._profile_path, allow_shorthand=False)
     self.assertEqual([], profile.pylint['disable'])
Ejemplo n.º 4
0
 def test_empty_disable_list(self):
     """
     This test verifies that a profile can still be loaded if it contains
     an empty 'pylint.disable' list
     """
     profile = ProspectorProfile.load("empty_disable_list", self._profile_path, allow_shorthand=False)
     self.assertEqual([], profile.pylint["disable"])
Ejemplo n.º 5
0
 def test_simple_inheritance(self):
     profile = ProspectorProfile.load('inherittest3',
                                      self._profile_path,
                                      allow_shorthand=False)
     disable = profile.pylint['disable']
     disable.sort()
     self.assertEqual(['I0002', 'I0003', 'raw-checker-failed'], disable)
Ejemplo n.º 6
0
 def test_empty_profile(self):
     """
     Verifies that a completely empty profile can still be parsed and have
     default values
     """
     profile = ProspectorProfile.load("empty_profile", self._profile_path, allow_shorthand=False)
     self.assertEqual([], profile.pylint["disable"])
Ejemplo n.º 7
0
 def test_empty_profile(self):
     """
     Verifies that a completely empty profile can still be parsed and have
     default values
     """
     profile = ProspectorProfile.load('empty_profile', self._profile_path, allow_shorthand=False)
     self.assertEqual([], profile.pylint['disable'])
Ejemplo n.º 8
0
 def test_strictness_equivalence(self):
     profile = self._load("strictness_equivalence")
     medium_strictness = ProspectorProfile.load("strictness_medium",
                                                self._profile_path)
     self.assertListEqual(
         sorted(profile.pylint["disable"]),
         sorted(medium_strictness.pylint["disable"]),
     )
Ejemplo n.º 9
0
 def test_shorthand_inheritance(self):
     profile = self._load('shorthand_inheritance')
     high_strictness = ProspectorProfile.load('strictness_high', self._profile_path,
                                              # don't implicitly add things
                                              allow_shorthand=False,
                                              # but do include the profiles that the start.yaml will
                                              forced_inherits=['doc_warnings', 'no_member_warnings']
     )
     self.assertDictEqual(profile.pylint, high_strictness.pylint)
     self.assertDictEqual(profile.pep8, high_strictness.pep8)
     self.assertDictEqual(profile.pyflakes, high_strictness.pyflakes)
Ejemplo n.º 10
0
 def test_pep8_shorthand_with_newname(self):
     """
     'pep8' is still a valid entry in the profile but in the future, only as a shorthand ("pep8: full")
     however for now, it also has to be able to configure pycodestyle
     """
     profile = ProspectorProfile.load("pep8_shorthand_pycodestyle",
                                      self._profile_path,
                                      allow_shorthand=True)
     self.assertTrue("full_pep8" in profile.inherit_order)
     self.assertTrue(profile.is_tool_enabled("pycodestyle"))
     self.assertEqual(profile.pycodestyle["options"]["max-line-length"],
                      120)
Ejemplo n.º 11
0
 def test_shorthand_inheritance(self):
     profile = self._load('shorthand_inheritance')
     high_strictness = ProspectorProfile.load(
         'strictness_high',
         self._profile_path,
         # don't implicitly add things
         allow_shorthand=False,
         # but do include the profiles that the start.yaml will
         forced_inherits=['doc_warnings', 'no_member_warnings'])
     self.assertDictEqual(profile.pylint, high_strictness.pylint)
     self.assertDictEqual(profile.pep8, high_strictness.pep8)
     self.assertDictEqual(profile.pyflakes, high_strictness.pyflakes)
Ejemplo n.º 12
0
 def test_shorthand_inheritance(self):
     profile = self._load("shorthand_inheritance")
     high_strictness = ProspectorProfile.load(
         "strictness_high",
         self._profile_path,
         # don't implicitly add things
         allow_shorthand=False,
         # but do include the profiles that the start.yaml will
         forced_inherits=["doc_warnings", "no_member_warnings"],
     )
     self.assertDictEqual(profile.pylint, high_strictness.pylint)
     self.assertDictEqual(profile.pycodestyle, high_strictness.pycodestyle)
     self.assertDictEqual(profile.pyflakes, high_strictness.pyflakes)
Ejemplo n.º 13
0
    def test_old_inherits_from_new(self):
        profile = ProspectorProfile.load("child_oldname.yaml",
                                         self._profile_path,
                                         allow_shorthand=False)

        assert profile.is_tool_enabled("pydocstyle")
        assert profile.is_tool_enabled("pycodestyle")
        assert "D401" in profile.pydocstyle["enable"]
        assert "D401" not in profile.pydocstyle["disable"]

        assert "E266" not in profile.pycodestyle["disable"]

        assert 120 == profile.pycodestyle["options"]["max-line-length"]
Ejemplo n.º 14
0
 def test_formatter_types(self):
     summary = {'started': datetime.datetime(2014, 1, 1),
                'completed': datetime.datetime(2014, 1, 1),
                'message_count': 0,
                'time_taken': '0',
                'libraries': [],
                'strictness': 'veryhigh',
                'profiles': '',
                'tools': []}
     profile = ProspectorProfile(name='horse',
                                 profile_dict={},
                                 inherit_order=['horse'])
     for formatter_name, formatter in FORMATTERS.items():
         formatter_instance = formatter(summary, [], profile)
         self.assertIsInstance(formatter_instance.render(True, True, False),
                               six.string_types)
Ejemplo n.º 15
0
    def test_new_inherits_from_old(self):
        """
        Ensure that `pep8` can inherit from a `pycodecstyle` block and vice versa
        """
        profile = ProspectorProfile.load("child_newname.yaml",
                                         self._profile_path,
                                         allow_shorthand=False)

        assert profile.is_tool_enabled("pydocstyle")
        assert profile.is_tool_enabled("pycodestyle")
        assert "D401" not in profile.pydocstyle["disable"]
        assert "D401" in profile.pydocstyle["enable"]

        assert "E266" not in profile.pycodestyle["disable"]

        assert 140 == profile.pycodestyle["options"]["max-line-length"]
Ejemplo n.º 16
0
 def test_formatter_types(self):
     summary = {
         "started": datetime.datetime(2014, 1, 1),
         "completed": datetime.datetime(2014, 1, 1),
         "message_count": 0,
         "time_taken": "0",
         "libraries": [],
         "strictness": "veryhigh",
         "profiles": "",
         "tools": [],
     }
     profile = ProspectorProfile(name="horse",
                                 profile_dict={},
                                 inherit_order=["horse"])
     for formatter_name, formatter in FORMATTERS.items():
         formatter_instance = formatter(summary, [], profile)
         self.assertIsInstance(formatter_instance.render(True, True, False),
                               six.string_types)
Ejemplo n.º 17
0
 def test_ignores(self):
     profile = ProspectorProfile.load("ignores", self._profile_path)
     self.assertEqual(["^tests/", "/migrations/"].sort(), profile.ignore_patterns.sort())
Ejemplo n.º 18
0
 def test_ignores(self):
     profile = ProspectorProfile.load('ignores', self._profile_path)
     self.assertEqual(['^tests/', '/migrations/'].sort(), profile.ignore_patterns.sort())
Ejemplo n.º 19
0
 def test_disable_tool(self):
     profile = ProspectorProfile.load('pylint_disabled', self._profile_path)
     self.assertFalse(profile.is_tool_enabled('pylint'))
     self.assertTrue(profile.is_tool_enabled('pep8') is None)
Ejemplo n.º 20
0
    def _get_profile(self, path, config):
        # Use the specified profiles
        profile_provided = False
        if len(config.profiles) > 0:
            profile_provided = True
        cmdline_implicit = []

        # if there is a '.prospector.ya?ml' or a '.prospector/prospector.ya?ml' or equivalent landscape config
        # file then we'll include that
        profile_name = None
        if not profile_provided:
            for possible_profile in AUTO_LOADED_PROFILES:
                prospector_yaml = os.path.join(path, possible_profile)
                if os.path.exists(prospector_yaml) and os.path.isfile(
                        prospector_yaml):
                    profile_provided = True
                    profile_name = possible_profile
                    break

        strictness = None

        if profile_provided:
            if profile_name is None:
                profile_name = config.profiles[0]
                extra_profiles = config.profiles[1:]
            else:
                extra_profiles = config.profiles

            strictness = 'from profile'
        else:
            # Use the preconfigured prospector profiles
            profile_name = 'default'
            extra_profiles = []

        if config.doc_warnings is not None and config.doc_warnings:
            cmdline_implicit.append('doc_warnings')
        if config.test_warnings is not None and config.test_warnings:
            cmdline_implicit.append('test_warnings')
        if config.no_style_warnings is not None and config.no_style_warnings:
            cmdline_implicit.append('no_pep8')
        if config.full_pep8 is not None and config.full_pep8:
            cmdline_implicit.append('full_pep8')
        if config.member_warnings is not None and config.member_warnings:
            cmdline_implicit.append('member_warnings')

        # Use the strictness profile only if no profile has been given
        if config.strictness is not None and config.strictness:
            cmdline_implicit.append('strictness_%s' % config.strictness)
            strictness = config.strictness

        # the profile path is
        #   * anything provided as an argument
        #   * a directory called .prospector in the check path
        #   * the check path
        #   * prospector provided profiles
        profile_path = config.profile_path

        prospector_dir = os.path.join(path, '.prospector')
        if os.path.exists(prospector_dir) and os.path.isdir(prospector_dir):
            profile_path.append(prospector_dir)

        profile_path.append(path)
        profile_path.append(BUILTIN_PROFILE_PATH)

        try:
            forced_inherits = cmdline_implicit + extra_profiles
            profile = ProspectorProfile.load(profile_name,
                                             profile_path,
                                             forced_inherits=forced_inherits)
        except CannotParseProfile as cpe:
            sys.stderr.write(
                "Failed to run:\nCould not parse profile %s as it is not valid YAML\n%s\n"
                % (cpe.filepath, cpe.get_parse_message()))
            sys.exit(1)
        except ProfileNotFound as nfe:
            sys.stderr.write(
                "Failed to run:\nCould not find profile %s. Search path: %s\n"
                % (nfe.name, ':'.join(nfe.profile_path)))
            sys.exit(1)
        else:
            return profile, strictness
Ejemplo n.º 21
0
    def _get_profile(self, path, config):
        # Use the specified profiles
        profile_provided = False
        if len(config.profiles) > 0:
            profile_provided = True
        cmdline_implicit = []

        # if there is a '.prospector.ya?ml' or a '.prospector/prospector.ya?ml' or equivalent landscape config
        # file then we'll include that
        profile_name = None
        if not profile_provided:
            for possible_profile in AUTO_LOADED_PROFILES:
                prospector_yaml = os.path.join(path, possible_profile)
                if os.path.exists(prospector_yaml) and os.path.isfile(prospector_yaml):
                    profile_provided = True
                    profile_name = possible_profile
                    break

        strictness = None

        if profile_provided:
            if profile_name is None:
                profile_name = config.profiles[0]
                extra_profiles = config.profiles[1:]
            else:
                extra_profiles = config.profiles

            strictness = 'from profile'
        else:
            # Use the preconfigured prospector profiles
            profile_name = 'default'
            extra_profiles = []

        if config.doc_warnings is not None and config.doc_warnings:
            cmdline_implicit.append('doc_warnings')
        if config.test_warnings is not None and config.test_warnings:
            cmdline_implicit.append('test_warnings')
        if config.no_style_warnings is not None and config.no_style_warnings:
            cmdline_implicit.append('no_pep8')
        if config.full_pep8 is not None and config.full_pep8:
            cmdline_implicit.append('full_pep8')
        if config.member_warnings is not None and config.member_warnings:
            cmdline_implicit.append('member_warnings')

        # Use the strictness profile only if no profile has been given
        if config.strictness is not None and config.strictness:
            cmdline_implicit.append('strictness_%s' % config.strictness)
            strictness = config.strictness

        # the profile path is
        #   * anything provided as an argument
        #   * a directory called .prospector in the check path
        #   * the check path
        #   * prospector provided profiles
        profile_path = config.profile_path

        prospector_dir = os.path.join(path, '.prospector')
        if os.path.exists(prospector_dir) and os.path.isdir(prospector_dir):
            profile_path.append(prospector_dir)

        profile_path.append(path)
        profile_path.append(BUILTIN_PROFILE_PATH)

        try:
            forced_inherits = cmdline_implicit + extra_profiles
            profile = ProspectorProfile.load(profile_name, profile_path, forced_inherits=forced_inherits)
        except CannotParseProfile as cpe:
            sys.stderr.write("Failed to run:\nCould not parse profile %s as it is not valid YAML\n%s\n" %
                             (cpe.filepath, cpe.get_parse_message()))
            sys.exit(1)
        except ProfileNotFound as nfe:
            sys.stderr.write("Failed to run:\nCould not find profile %s. Search path: %s\n" %
                             (nfe.name, ':'.join(nfe.profile_path)))
            sys.exit(1)
        else:
            return profile, strictness
Ejemplo n.º 22
0
 def test_optional_present(self):
     # optional does not mean ignore so verify that values are inherited if present
     profile = ProspectorProfile.load("optional_present",
                                      self._profile_path)
     self.assertFalse(profile.is_tool_enabled("dodgy"))
Ejemplo n.º 23
0
 def _load(self, testname):
     profile_path = self._profile_path + [self._example_path(testname)]
     return ProspectorProfile.load("start", profile_path)
Ejemplo n.º 24
0
 def test_load_plugins(self):
     profile = ProspectorProfile.load('pylint_load_plugins',
                                      self._profile_path)
     self.assertEqual(['first_plugin', 'second_plugin'],
                      profile.pylint['load-plugins'])
Ejemplo n.º 25
0
 def test_ignores(self):
     profile = ProspectorProfile.load('ignores', self._profile_path)
     self.assertEqual(['^tests/', '/migrations/'].sort(),
                      profile.ignore_patterns.sort())
Ejemplo n.º 26
0
 def test_disable_tool_inheritance(self):
     profile = ProspectorProfile.load('pep8_and_pylint_disabled', self._profile_path)
     self.assertFalse(profile.is_tool_enabled('pylint'))
     self.assertFalse(profile.is_tool_enabled('pep8'))
Ejemplo n.º 27
0
 def test_strictness_equivalence(self):
     profile = self._load('strictness_equivalence')
     medium_strictness = ProspectorProfile.load('strictness_medium', self._profile_path)
     self.assertListEqual(sorted(profile.pylint['disable']), sorted(medium_strictness.pylint['disable']))
Ejemplo n.º 28
0
 def test_disable_tool(self):
     profile = ProspectorProfile.load("pylint_disabled", self._profile_path)
     self.assertFalse(profile.is_tool_enabled("pylint"))
     self.assertTrue(profile.is_tool_enabled("pep8") is None)
Ejemplo n.º 29
0
 def test_simple_inheritance(self):
     profile = ProspectorProfile.load('inherittest3', self._profile_path, allow_shorthand=False)
     disable = profile.pylint['disable']
     disable.sort()
     self.assertEqual(['I0002', 'I0003', 'raw-checker-failed'], disable)
Ejemplo n.º 30
0
 def test_load_plugins(self):
     profile = ProspectorProfile.load("pylint_load_plugins", self._profile_path)
     self.assertEqual(["first_plugin", "second_plugin"], profile.pylint["load-plugins"])
Ejemplo n.º 31
0
 def _load(self, testname):
     profile_path = self._profile_path + [self._example_path(testname)]
     return ProspectorProfile.load('start', profile_path)
Ejemplo n.º 32
0
 def test_disable_tool_inheritance(self):
     profile = ProspectorProfile.load("pep8_and_pylint_disabled", self._profile_path)
     self.assertFalse(profile.is_tool_enabled("pylint"))
     self.assertFalse(profile.is_tool_enabled("pep8"))
Ejemplo n.º 33
0
 def test_optional_missing(self):
     # ensure loads without an exception to verify that a missing inherits works fine
     profile = ProspectorProfile.load("optional_missing",
                                      self._profile_path)
     self.assertTrue(profile.is_tool_enabled("dodgy"))