def _test_style(filename, ignore): """ Test style for a certain file. """ if isinstance(ignore, (list, tuple)): ignore = ','.join(ignore) orig_dir = os.getcwd() orig_argv = sys.argv os.chdir(ROOT_DIR) sys.argv[1:] = [filename] sys.argv.append('--ignore=' + ignore) nerrors = 1 try: import flake8 # noqa from flake8.main.application import Application app = Application() app.run() nerrors = app.result_count app.exit() except SystemExit as ex: return nerrors finally: os.chdir(orig_dir) sys.argv[:] = orig_argv
def _test_style(filename, ignore): """ Test style for a certain file. """ if isinstance(ignore, (list, tuple)): ignore = ','.join(ignore) orig_dir = os.getcwd() orig_argv = sys.argv os.chdir(ROOT_DIR) sys.argv[1:] = [filename] sys.argv.append('--ignore=' + ignore) try: import flake8 # noqa from flake8.main.application import Application app = Application() app.run() app.exit() except SystemExit as ex: if ex.code in (None, 0): return False else: return True finally: os.chdir(orig_dir) sys.argv[:] = orig_argv
def test_style(rel_path='.'): # Ensure we have flake8 try: import flake8 # noqa from flake8.main.application import Application except ImportError as err: sys.exit('Cannot do style test: ' + str(err)) # Prepare os.chdir(ROOT_DIR) if rel_path in ('', '.'): sys.argv[1:] = ['flexx', 'flexxamples'] else: sys.argv[1:] = ['flexx/' + rel_path] # Do test print('Running flake8 tests ...') app = Application() app.run() # Report nerrors = app.result_count if nerrors: print('Arg! Found %i style errors.' % nerrors) else: print('Hooray, no style errors found!') # Exit (will exit(1) if errors) app.exit()
import sys from flake8.main.application import Application from importlinter.cli import lint_imports, EXIT_STATUS_SUCCESS import pytest if __name__ == "__main__": # Lint code flake8 = Application() flake8.run([ 'assignment', '--max-line-length', '100', ]) if flake8.result_count > 0: print('-- flake8 found code style issues --') flake8.exit() if (exit_code := lint_imports()) != EXIT_STATUS_SUCCESS: print('-- import-linter found invalid packages --') sys.exit(exit_code) # Run tests pytest.main(['-v', '--basetemp', 'processing_results', '-W', 'ignore::DeprecationWarning'])