def isort(check): # sorting headers -the imports """ Run isort on all the files in app and tests directory """ exit_code = 0 config = from_path(os.getcwd()).copy() config["check"] = check file_names = iter_source_code(["app", "tests", "manage.py"], config, []) for file_name in file_names: sort_attempt = sort_imports(file_name, **config) if sort_attempt: if sort_attempt.incorrectly_sorted: exit_code = 1 raise sys.exit(exit_code)
def test_iter_source_code(tmpdir): tmp_file = tmpdir.join("file.py") tmp_file.write("import os, sys\n") assert tuple(main.iter_source_code((tmp_file,), DEFAULT_CONFIG, [])) == (tmp_file,)