Beispiel #1
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'])
 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)
Beispiel #3
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'])
 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'])
 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'])
Beispiel #6
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)
 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)
 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)
Beispiel #9
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']))
Beispiel #10
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'))
Beispiel #11
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)
Beispiel #12
0
 def _load(self, testname):
     profile_path = self._profile_path + [self._example_path(testname)]
     return ProspectorProfile.load('start', profile_path)
Beispiel #13
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)
Beispiel #14
0
 def test_ignores(self):
     profile = ProspectorProfile.load('ignores', self._profile_path)
     self.assertEqual(['^tests/', '/migrations/'].sort(), profile.ignore_patterns.sort())
Beispiel #15
0
 def test_ignores(self):
     profile = ProspectorProfile.load('ignores', self._profile_path)
     self.assertEqual(['^tests/', '/migrations/'].sort(),
                      profile.ignore_patterns.sort())
Beispiel #16
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)
Beispiel #17
0
 def _load(self, testname):
     profile_path = self._profile_path + [self._example_path(testname)]
     return ProspectorProfile.load('start', profile_path)
Beispiel #18
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
Beispiel #19
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']))
Beispiel #20
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'))