def teardown_test_environment(self, **kwargs): locations = get_apps_locations(self.test_labels, self.test_all) # run pyflakes tool with captured output old_stdout, pyflakes_output = sys.stdout, StringIO() sys.stdout = pyflakes_output try: for location in locations: if os.path.isdir(location): for dirpath, dirnames, filenames in os.walk(relpath(location)): for filename in filenames: if filename.endswith('.py'): pyflakes.checkPath(os.path.join(dirpath, filename)) else: pyflakes.checkPath(relpath(location)) finally: sys.stdout = old_stdout # save report pyflakes_output.reset() while True: line = pyflakes_output.readline() if not line: break message = re.sub(r': ', r': [E] PYFLAKES:', line) self.output.write(message) self.output.close()
def teardown_test_environment(self, **kwargs): locations = get_apps_locations(self.test_labels, self.test_all) class JenkinsReport(pep8.BaseReport): def error(instance, line_number, offset, text, check): code = super(JenkinsReport, instance).error(line_number, offset, text, check) if not code: return sourceline = instance.line_offset + line_number self.output.write( '%s:%s:%s: %s\n' % (instance.filename, sourceline, offset + 1, text)) pep8style = get_style_guide(parse_argv=False, config_file=self.pep8_rcfile, reporter=JenkinsReport, max_complexity=self.max_complexity, **self.pep8_options) for location in locations: pep8style.input_dir(relpath(location)) self.output.close()
def teardown_test_environment(self, **kwargs): locations = get_apps_locations(self.test_labels, self.test_all) class JenkinsReport(pep8.BaseReport): def error(instance, line_number, offset, text, check): code = super(JenkinsReport, instance).error( line_number, offset, text, check ) if not code: return sourceline = instance.line_offset + line_number self.output.write('%s:%s:%s: %s\n' % ( instance.filename, sourceline, offset + 1, text) ) pep8style = pep8.StyleGuide( parse_argv=False, config_file='.pep8', reporter=JenkinsReport ) for location in locations: pep8style.input_dir(relpath(location)) self.output.close()
def teardown_test_environment(self, **kwargs): for path in self.static_files_iterator(): jslint_output = check_output([ self.intepreter, self.runner, self.implementation, relpath(path) ]) self.output.write(jslint_output)
def teardown_test_environment(self, **kwargs): files = [relpath(path) for path in self.static_files_iterator()] if self.to_file: fmt = 'lint-xml' else: fmt = 'text' csslint_output = check_output([self.intepreter, self.implementation, '--format=%s' % fmt] + files) self.output.write(csslint_output)
def teardown_test_environment(self, **kwargs): files = [relpath(path) for path in self.static_files_iterator()] if self.to_file: fmt = "lint-xml" else: fmt = "text" csslint_output = check_output([self.intepreter, self.implementation, "--format=%s" % fmt] + files) self.output.write(csslint_output)
def teardown_test_environment(self, **kwargs): fmt = 'text' if self.to_file: fmt = 'xml' if self.to_file: self.output.write('<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint>') for path in self.static_files_iterator(): jslint_output = check_output( [self.interpreter, self.runner, self.implementation, relpath(path), fmt]) self.output.write(jslint_output) if self.to_file: self.output.write('</jslint>');
def teardown_test_environment(self, **kwargs): locations = get_apps_locations(self.test_labels, self.test_all) pep8.process_options(self.pep8_options + locations) # run pep8 tool with captured output def report_error(instance, line_number, offset, text, check): code = text[:4] if pep8.ignore_code(code): return sourceline = instance.line_offset + line_number self.output.write('%s:%s:%s: %s\n' % (instance.filename, sourceline, offset+1, text)) pep8.Checker.report_error = report_error for location in locations: pep8.input_dir(relpath(location), runner=pep8.input_file) self.output.close()
def teardown_test_environment(self, **kwargs): fmt = 'text' if self.to_file: fmt = 'xml' if self.to_file: self.output.write( '<?xml version=\"1.0\" encoding=\"utf-8\"?><jslint>') for path in self.static_files_iterator(): jslint_output = check_output([ self.interpreter, self.runner, self.implementation, relpath(path), fmt ]) self.output.write(jslint_output) if self.to_file: self.output.write('</jslint>')
def teardown_test_environment(self, **kwargs): files = [relpath(path) for path in self.static_files_iterator()] if self.to_file: fmt = 'lint-xml' else: fmt = 'text' if files: cmd = [self.interpreter, self.implementation, '--format=%s' % fmt] + files process = subprocess.Popen(cmd, stdout=subprocess.PIPE) output, err = process.communicate() retcode = process.poll() if retcode not in [0, 1]: # normal csslint return codes raise CalledProcessError(retcode, cmd, output=output + '\n' + err) self.output.write(output) elif self.to_file: self.output.write('<csslint></csslint')
def teardown_test_environment(self, **kwargs): # Local imports to avoid intallation errors. import flake8.run # Use pep8 from flake8 to avoid weird errors resulting from # version mismatch. from flake8 import pep8 locations = get_apps_locations( self.test_labels, self.test_all ) paths = flake8.run._get_python_files(locations) flake8.run.pep8style = pep8.StyleGuide( parse_argv=False, config_file=False ) old_stdout, flake8_output = sys.stdout, StringIO() sys.stdout = flake8_output warnings = 0 for path in paths: # We could pass ignore paths and max complexity there, # but I need to figure out first how to do it warnings += flake8.run.check_file(path) sys.stdout = old_stdout flake8_output.seek(0) while True: line = flake8_output.readline() if not line: break # Make sure the path is relative in the report bits = line.split(':') bits[0] = relpath(bits[0]) self.output.write(':'.join(bits)) self.output.close()
def teardown_test_environment(self, **kwargs): # Local import to avoid intallation errors. import flake8.run locations = get_apps_locations( self.test_labels, self.test_all ) paths = flake8.run._get_python_files(locations) flake8.run.pep8style = pep8.StyleGuide( parse_argv=False, config_file=False ) old_stdout, flake8_output = sys.stdout, BytesIO() sys.stdout = flake8_output warnings = 0 for path in paths: # We could pass ignore paths # but I need to figure out first how to do it warnings += flake8.run.check_file( path, complexity=self.max_complexity ) sys.stdout = old_stdout flake8_output.seek(0) while True: line = flake8_output.readline() if not line: break # Make sure the path is relative in the report bits = line.split(':') bits[0] = relpath(bits[0]) self.output.write(':'.join(bits)) self.output.close()
def test_relative_path_is_current_dir(self): self.assertEquals('.', relpath(path='.'))
def test_relative_path_to_home(self): self.assertEquals('~', relpath(path='~'))
def teardown_test_environment(self, **kwargs): for path in self.static_files_iterator(): jslint_output = check_output( [self.intepreter, self.runner, self.implementation, relpath(path)]) self.output.write(jslint_output)