def run_prospector(base_dir, clear_ignore_patterns=False): """Run prospector and apply white/blacklists to the results""" orig_expand_default = optparse.HelpFormatter.expand_default sys.argv = ['fakename'] sys.argv.extend(PROSPECTOR_OPTIONS) # add/set REPO_BASE_DIR as positional path sys.argv.append(base_dir) config = ProspectorConfig() # prospector will sometimes wrongly autodetect django config.libraries = [] prospector = Prospector(config) # Set defaults for prospector: config.profile.doc_warnings = False config.profile.test_warnings = False config.profile.autodetect = True config.profile.member_warnings = False if clear_ignore_patterns: config.profile.ignore_patterns = [r'.^'] config.ignores = [] else: append_pattern = r'(^|/)\..+' config.profile.ignore_patterns.append(append_pattern) config.ignores.append(re.compile(append_pattern)) # Enable pylint Python3 compatibility tests: config.profile.pylint['options']['enable'] = 'python3' log.debug("prospector argv = %s" % sys.argv) log.debug("prospector profile from config = %s" % vars(config.profile)) prospector.execute() log.debug("prospector profile form prospector = %s" % vars(prospector.config.profile)) blacklist = map(re.compile, PROSPECTOR_BLACKLIST) whitelist = map(re.compile, PROSPECTOR_WHITELIST) failures = [] for msg in prospector.get_messages(): # example msg.as_dict(): # {'source': 'pylint', 'message': 'Missing function docstring', 'code': 'missing-docstring', # 'location': {'function': 'TestHeaders.test_check_header.lgpl', 'path': u'headers.py', # 'line': 122, 'character': 8, 'module': 'headers'}} log.debug("prospector message %s" % msg.as_dict()) if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in blacklist]): continue if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in whitelist]): failures.append(msg.as_dict()) # There is some ugly monkeypatch code in pylint # (or logilab if no recent enough pylint is installed) # Make sure the original is restored # (before any errors are reported; no need to put this in setUp/tearDown) optparse.HelpFormatter.expand_default = orig_expand_default return failures
def test_prospector(self): """Run prospector.run.main, but apply white/blacklists to the results""" orig_expand_default = optparse.HelpFormatter.expand_default if not HAS_PROSPECTOR: if sys.version_info < (2, 7): log.info('No protector tests are ran on py26 or older.') else: log.info('No protector tests are ran, install prospector manually first') # This is fatal on jenkins/... if 'JENKINS_URL' in os.environ: self.assertTrue(False, 'prospector must be installed in jenkins environment') return sys.argv = ['fakename'] sys.argv.extend(self.PROSPECTOR_OPTIONS) # add/set REPO_BASE_DIR as positional path sys.argv.append(self.setup.REPO_BASE_DIR) config = ProspectorConfig() # prospector will sometimes wrongly autodetect django config.libraries = [] prospector = Prospector(config) prospector.execute() blacklist = map(re.compile, self.PROSPECTOR_BLACKLIST) whitelist = map(re.compile, self.PROSPECTOR_WHITELIST) failures = [] for msg in prospector.get_messages(): # example msg.as_dict(): # {'source': 'pylint', 'message': 'Missing function docstring', 'code': 'missing-docstring', # 'location': {'function': 'TestHeaders.test_check_header.lgpl', 'path': u'headers.py', # 'line': 122, 'character': 8, 'module': 'headers'}} log.debug("prospector message %s" % msg.as_dict()) if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in blacklist]): continue if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in whitelist]): failures.append(msg.as_dict()) # There is some ugly monkeypatch code in pylint # (or logilab if no recent enough pylint is installed) # Make sure the original is restored # (before any errors are reported; no need to put this in setUp/tearDown) optparse.HelpFormatter.expand_default = orig_expand_default self.assertFalse(failures, "prospector failures: %s" % pprint.pformat(failures))
def test_prospector(self): """Run prospector.run.main, but apply white/blacklists to the results""" orig_expand_default = optparse.HelpFormatter.expand_default if not HAS_PROTECTOR: if sys.version_info < (2, 7): log.info('No protector tests are ran on py26 or older.') else: log.info('No protector tests are ran, install prospector manually first') # This is fatal on jenkins/... if 'JENKINS_URL' in os.environ: self.assertTrue(False, 'prospector must be installed in jenkins environment') return sys.argv = ['fakename'] sys.argv.extend(self.PROSPECTOR_OPTIONS) # add/set REPO_BASE_DIR as positional path sys.argv.append(self.setup.REPO_BASE_DIR) config = ProspectorConfig() # prospector will sometimes wrongly autodetect django config.libraries = [] prospector = Prospector(config) prospector.execute() blacklist = map(re.compile, self.PROSPECTOR_BLACKLIST) whitelist = map(re.compile, self.PROSPECTOR_WHITELIST) failures = [] for msg in prospector.get_messages(): # example msg.as_dict(): # {'source': 'pylint', 'message': 'Missing function docstring', 'code': 'missing-docstring', # 'location': {'function': 'TestHeaders.test_check_header.lgpl', 'path': u'headers.py', # 'line': 122, 'character': 8, 'module': 'headers'}} log.debug("prospector message %s" % msg.as_dict()) if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in blacklist]): continue if any([bool(reg.search(msg.code) or reg.search(msg.message)) for reg in whitelist]): failures.append(msg.as_dict()) # There is some ugly monkeypatch code in pylint # (or logilab if no recent enough pylint is installed) # Make sure the original is restored # (before any errors are reported; no need to put this in setUp/tearDown) optparse.HelpFormatter.expand_default = orig_expand_default self.assertFalse(failures, "prospector failures: %s" % pprint.pformat(failures))
def test_prospector(self): """Run prospector tests""" PROSPECTOR_OPTIONS = [ '--strictness', 'medium', '--max-line-length', '120', '--absolute-paths', ] sys.argv = ['fakename'] sys.argv.extend(PROSPECTOR_OPTIONS) sys.argv.append(REPO_BASE_DIR) config = ProspectorConfig() config.libraries = [] prospector = Prospector(config) prospector.execute() failures = [msg.as_dict() for msg in prospector.get_messages()] self.assertFalse(failures, "prospector failures: %s" % pprint.pformat(failures))
def run_prospector(base_dir, clear_ignore_patterns=False): """Run prospector and apply white/blacklists to the results""" orig_expand_default = optparse.HelpFormatter.expand_default log.info("Using prosector version %s", prospector_version) sys.argv = ['fakename'] sys.argv.extend(PROSPECTOR_OPTIONS) if PROSPECTOR_USE_LIBS: sys.argv.extend(["--uses", ",".join(PROSPECTOR_USE_LIBS)]) # add/set REPO_BASE_DIR as positional path sys.argv.append(base_dir) log.debug("prospector commandline %s" % sys.argv) config = ProspectorConfig() # prospector will sometimes wrongly autodetect django config.libraries = [] prospector = Prospector(config) # Set defaults for prospector: config.profile.doc_warnings = False config.profile.test_warnings = False config.profile.autodetect = True config.profile.member_warnings = False if clear_ignore_patterns: config.profile.ignore_patterns = [r'.^'] config.ignores = [] else: append_pattern = r'(^|/)\..+' config.profile.ignore_patterns.append(append_pattern) config.ignores.append(re.compile(append_pattern)) # Enable pylint Python3 compatibility tests: config.profile.pylint['options']['enable'] = 'python3' log.debug("prospector argv = %s" % sys.argv) log.debug("prospector profile from config = %s" % vars(config.profile)) prospector.execute() log.debug("prospector profile form prospector = %s" % vars(prospector.config.profile)) # map yields a generator object in Python 3, but since we want to iterate over the whitelist/blacklist # multiple times, we need to make sure it's a list (since you can only iterate once over a generator) blacklist = list(map(re.compile, PROSPECTOR_BLACKLIST)) whitelist = list(map(re.compile, PROSPECTOR_WHITELIST)) failures = [] for msg in prospector.get_messages(): # example msg.as_dict(): # {'source': 'pylint', 'message': 'Missing function docstring', 'code': 'missing-docstring', # 'location': {'function': 'TestHeaders.test_check_header.lgpl', 'path': u'headers.py', # 'line': 122, 'character': 8, 'module': 'headers'}} log.debug("prospector message %s" % msg.as_dict()) if any([ bool(reg.search(msg.code) or reg.search(msg.message)) for reg in blacklist ]): continue if any([ bool(reg.search(msg.code) or reg.search(msg.message)) for reg in whitelist ]): failures.append(msg.as_dict()) # There is some ugly monkeypatch code in pylint # (or logilab if no recent enough pylint is installed) # Make sure the original is restored # (before any errors are reported; no need to put this in setUp/tearDown) optparse.HelpFormatter.expand_default = orig_expand_default return failures