From 58afc0403a1c59ce1ffd1c98f384fbf8c39abda4 Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Tue, 29 Nov 2022 16:57:41 +1300 Subject: [PATCH 1/3] some tidyups cleaning of imports specifying encoding for all file open() calls tidying f-strings --- src/wily/__main__.py | 9 +++++---- src/wily/cache.py | 10 +++++----- src/wily/commands/build.py | 5 +++-- src/wily/commands/diff.py | 3 ++- src/wily/commands/graph.py | 1 - src/wily/commands/rank.py | 7 ++++--- src/wily/commands/report.py | 1 - src/wily/config.py | 2 +- src/wily/state.py | 4 ++-- test/conftest.py | 15 +++++++-------- test/integration/test_all_operators.py | 4 ++-- test/integration/test_archiver.py | 12 ++++++------ test/integration/test_build.py | 14 +++++++------- test/integration/test_complex_commits.py | 16 ++++++++-------- test/integration/test_diff.py | 12 ++++++------ test/integration/test_rank.py | 2 +- test/unit/test_archivers.py | 4 ++-- test/unit/test_build_unit.py | 2 +- test/unit/test_cache.py | 14 +++++++------- test/unit/test_config.py | 10 +++++----- 20 files changed, 74 insertions(+), 73 deletions(-) diff --git a/src/wily/__main__.py b/src/wily/__main__.py index e4fdd8d1..18753034 100644 --- a/src/wily/__main__.py +++ b/src/wily/__main__.py @@ -1,5 +1,6 @@ """Main command line.""" +import sys import traceback from pathlib import Path @@ -406,12 +407,12 @@ def clean(ctx, yes): if not exists(config): logger.info(_("Wily cache does not exist, nothing to remove.")) - exit(0) + sys.exit(0) if not yes: p = input(_("Are you sure you want to delete wily cache? [y/N]")) if p.lower() != "y": - exit(0) + sys.exit(0) from wily.cache import clean @@ -446,7 +447,7 @@ def handle_no_cache(context): ) p = input(_("Do you want to run setup and index your project now? [y/N]")) if p.lower() != "y": - exit(1) + sys.exit(1) else: revisions = input(_("How many previous git revisions do you want to index? : ")) revisions = int(revisions) @@ -461,6 +462,6 @@ def handle_no_cache(context): except Exception as runtime: logger.error(f"Oh no, Wily crashed! See {WILY_LOG_NAME} for information.") logger.info( - f"If you think this crash was unexpected, please raise an issue at https://github.com/tonybaloney/wily/issues and copy the log file into the issue report along with some information on what you were doing." + "If you think this crash was unexpected, please raise an issue at https://github.com/tonybaloney/wily/issues and copy the log file into the issue report along with some information on what you were doing." ) logger.debug(traceback.format_exc()) diff --git a/src/wily/cache.py b/src/wily/cache.py index 6940fcf6..9dfb0af5 100644 --- a/src/wily/cache.py +++ b/src/wily/cache.py @@ -35,7 +35,7 @@ def exists(config): return False index_path = pathlib.Path(config.cache_path) / "index.json" if index_path.exists(): - with open(index_path) as out: + with open(index_path, encoding="utf8") as out: index = json.load(out) if index["version"] != __version__: # TODO: Inspect the versions properly. @@ -54,7 +54,7 @@ def create_index(config): """Create the root index.""" filename = pathlib.Path(config.cache_path) / "index.json" index = {"version": __version__} - with open(filename, "w") as out: + with open(filename, "w", encoding="utf8") as out: out.write(json.dumps(index, indent=2)) @@ -138,7 +138,7 @@ def store(config, archiver, revision, stats): filename = root / (revision.key + ".json") if filename.exists(): raise RuntimeError(f"File {filename} already exists, index may be corrupt.") - with open(filename, "w") as out: + with open(filename, "w", encoding="utf8") as out: out.write(json.dumps(stats, indent=2)) return filename @@ -167,9 +167,9 @@ def store_archiver_index(config, archiver, index): index = sorted(index, key=lambda k: k["date"], reverse=True) filename = root / "index.json" - with open(filename, "w") as out: + with open(filename, "w", encoding="utf8") as out: out.write(json.dumps(index, indent=2)) - logger.debug(f"Created index output") + logger.debug("Created index output") return filename diff --git a/src/wily/commands/build.py b/src/wily/commands/build.py index 5ea30ca4..86cfbd02 100644 --- a/src/wily/commands/build.py +++ b/src/wily/commands/build.py @@ -6,6 +6,7 @@ """ import multiprocessing import os +import sys import pathlib from progress.bar import Bar @@ -70,7 +71,7 @@ def build(config, archiver, operators): revisions = archiver.revisions(config.path, config.max_revisions) except InvalidGitRepositoryError: # TODO: This logic shouldn't really be here (SoC) - logger.info(f"Defaulting back to the filesystem archiver, not a valid git repo") + logger.info("Defaulting back to the filesystem archiver, not a valid git repo") archiver = FilesystemArchiver(config) revisions = archiver.revisions(config.path, config.max_revisions) except Exception as e: @@ -78,7 +79,7 @@ def build(config, archiver, operators): logger.error(f"Failed to setup archiver: '{e.message}'") else: logger.error(f"Failed to setup archiver: '{type(e)} - {e}'") - exit(1) + sys.exit(1) state = State(config, archiver=archiver) # Check for existence of cache, else provision diff --git a/src/wily/commands/diff.py b/src/wily/commands/diff.py index 3c8766d0..085081ac 100644 --- a/src/wily/commands/diff.py +++ b/src/wily/commands/diff.py @@ -5,6 +5,7 @@ """ import multiprocessing import os +import sys from pathlib import Path import radon.cli.harvest @@ -75,7 +76,7 @@ def diff(config, files, metrics, changes_only=True, detail=True, revision=None): logger.error( f"Revision {revision} is not in the cache, make sure you have run wily build." ) - exit(1) + sys.exit(1) logger.info( f"Comparing current with {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}." diff --git a/src/wily/commands/graph.py b/src/wily/commands/graph.py index 09f09223..fa10fe16 100644 --- a/src/wily/commands/graph.py +++ b/src/wily/commands/graph.py @@ -3,7 +3,6 @@ TODO: Add multiple lines for multiple files """ -import pathlib import plotly.graph_objs as go import plotly.offline diff --git a/src/wily/commands/rank.py b/src/wily/commands/rank.py index ed00e490..c090b391 100644 --- a/src/wily/commands/rank.py +++ b/src/wily/commands/rank.py @@ -9,6 +9,7 @@ """ import operator as op import os +import sys from pathlib import Path import radon.cli.harvest @@ -17,7 +18,7 @@ from wily import format_date, format_revision, logger from wily.archivers import resolve_archiver from wily.config import DEFAULT_GRID_STYLE, DEFAULT_PATH -from wily.operators import MetricType, resolve_metric_as_tuple +from wily.operators import resolve_metric_as_tuple from wily.state import State @@ -65,7 +66,7 @@ def rank(config, path, metric, revision_index, limit, threshold, descending): logger.error( f"Revision {revision_index} is not in the cache, make sure you have run wily build." ) - exit(1) + sys.exit(1) logger.info( f"-----------Rank for {metric.description} for {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}.------------" @@ -123,4 +124,4 @@ def rank(config, path, metric, revision_index, limit, threshold, descending): logger.error( f"Total value below the specified threshold: {total} < {threshold}" ) - exit(1) + sys.exit(1) diff --git a/src/wily/commands/report.py b/src/wily/commands/report.py index ddb8a2ec..28fd47a0 100644 --- a/src/wily/commands/report.py +++ b/src/wily/commands/report.py @@ -7,7 +7,6 @@ from pathlib import Path from shutil import copytree from string import Template -from typing import List import tabulate diff --git a/src/wily/config.py b/src/wily/config.py index aa31c20c..2b8fd68a 100644 --- a/src/wily/config.py +++ b/src/wily/config.py @@ -13,7 +13,7 @@ from functools import lru_cache from typing import Any, List -import wily.operators as operators +from wily import operators from wily.archivers import ARCHIVER_GIT logger = logging.getLogger(__name__) diff --git a/src/wily/state.py b/src/wily/state.py index ab2fee82..0605b108 100644 --- a/src/wily/state.py +++ b/src/wily/state.py @@ -7,7 +7,7 @@ from dataclasses import asdict, dataclass from typing import List -import wily.cache as cache +from wily import cache from wily import logger from wily.archivers import Revision, resolve_archiver from wily.operators import get_metric @@ -88,7 +88,7 @@ def get_paths(self, config, archiver, operator): self._data = cache.get( config=config, archiver=archiver, revision=self.revision.key )["operator_data"] - logger.debug(f"Fetching keys") + logger.debug("Fetching keys") return list(self._data[operator].keys()) def store(self, config, archiver, stats): diff --git a/test/conftest.py b/test/conftest.py index 280721ff..54003db3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -2,7 +2,6 @@ import shutil import tempfile from textwrap import dedent -from time import time import pytest from click.testing import CliRunner @@ -19,7 +18,7 @@ def gitdir(tmpdir): testpath = tmppath / "src" / "test.py" (tmppath / "src").mkdir() # Write a test file to the repo - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index @@ -46,7 +45,7 @@ class Class1(object): def method(self): b = 1 + 5 """ - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write(dedent(first_test)) index.add([str(testpath)]) @@ -70,7 +69,7 @@ def method(self): return 'banana' """ - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write(dedent(second_test)) index.add([str(testpath)]) @@ -141,7 +140,7 @@ def ipynbgitdir(tmpdir): testpath = tmppath / "src" / "test.ipynb" (tmppath / "src").mkdir() # Write a test file to the repo - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write('{"cells": [],' + _NB_FOOTER + "}") index = repo.index @@ -178,7 +177,7 @@ def ipynbgitdir(tmpdir): + _NB_FOOTER + "}" ) - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write(dedent(first_test)) index.add([str(testpath)]) @@ -228,7 +227,7 @@ def ipynbgitdir(tmpdir): + "}" ) - with open(testpath, "w") as test_txt: + with open(testpath, "w", encoding="utf8") as test_txt: test_txt.write(dedent(second_test)) index.add([str(testpath)]) @@ -251,7 +250,7 @@ def ipynbbuilddir(ipynbgitdir): ipynb_cells = true """ config_path = tmppath / "wily.cfg" - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) runner = CliRunner() diff --git a/test/integration/test_all_operators.py b/test/integration/test_all_operators.py index 6f5a6e14..3f4cf303 100644 --- a/test/integration/test_all_operators.py +++ b/test/integration/test_all_operators.py @@ -66,7 +66,7 @@ def method(self): print(1) """ - with open(pathlib.Path(gitdir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(gitdir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(complex_test)) result = runner.invoke( @@ -115,7 +115,7 @@ def single_comments(): pass author = Actor("An author", "author@example.com") committer = Actor("A committer", "committer@example.com") - with open(testpath, "w") as test_py: + with open(testpath, "w", encoding="utf8") as test_py: test_py.write(dedent(code_with_metric_named_objects)) with Repo.init(path=tmpdir) as repo: diff --git a/test/integration/test_archiver.py b/test/integration/test_archiver.py index 7c72907b..d62e6e98 100644 --- a/test/integration/test_archiver.py +++ b/test/integration/test_archiver.py @@ -19,13 +19,13 @@ def test_git_end_to_end(tmpdir): committer = Actor("A committer", "committer@example.com") # First commit - with open(tmppath / ".gitignore", "w") as ignore: + with open(tmppath / ".gitignore", "w", encoding="utf8") as ignore: ignore.write(".wily/") index.add([".gitignore"]) commit1 = index.commit("commit1", author=author, committer=committer) # Second commit - with open(tmppath / "test.py", "w") as file1: + with open(tmppath / "test.py", "w", encoding="utf8") as file1: file1.write("print(1)") index.add(["test.py"]) commit2 = index.commit("commit2", author=author, committer=committer) @@ -74,14 +74,14 @@ def test_dirty_git(tmpdir): committer = Actor("A committer", "committer@example.com") # First commit - with open(tmppath / ".gitignore", "w") as ignore: + with open(tmppath / ".gitignore", "w", encoding="utf8") as ignore: ignore.write(".wily/") index.add([".gitignore"]) commit1 = index.commit("commit1", author=author, committer=committer) # Write a test file to the repo - with open(tmppath / "blah.py", "w") as ignore: + with open(tmppath / "blah.py", "w", encoding="utf8") as ignore: ignore.write("*.py[co]\n") index.add(["blah.py"]) repo.close() @@ -104,14 +104,14 @@ def test_detached_head(tmpdir): committer = Actor("A committer", "committer@example.com") # First commit - with open(tmppath / "test.py", "w") as ignore: + with open(tmppath / "test.py", "w", encoding="utf8") as ignore: ignore.write("print('hello world')") index.add(["test.py"]) commit1 = index.commit("commit1", author=author, committer=committer) # Second commit - with open(tmppath / "test.py", "w") as ignore: + with open(tmppath / "test.py", "w", encoding="utf8") as ignore: ignore.write("print('hello world')\nprint(1)") index.add(["test.py"]) diff --git a/test/integration/test_build.py b/test/integration/test_build.py index c3027657..22cd8152 100644 --- a/test/integration/test_build.py +++ b/test/integration/test_build.py @@ -69,7 +69,7 @@ def test_build_crash(tmpdir): tmppath = pathlib.Path(tmpdir) # Write a test file to the repo - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index @@ -100,7 +100,7 @@ def test_build(tmpdir, cache_path): tmppath = pathlib.Path(tmpdir) # Write a test file to the repo - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index @@ -141,11 +141,11 @@ def test_build_with_config(tmpdir, cache_path): operators = raw, maintainability """ config_path = tmppath / "wily.cfg" - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) # Write a test file to the repo - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index @@ -189,7 +189,7 @@ def test_build_twice(tmpdir, cache_path): tmppath = pathlib.Path(tmpdir) # Write a test file to the repo - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index @@ -215,7 +215,7 @@ def test_build_twice(tmpdir, cache_path): assert rev_path.exists() # Write a test file to the repo - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc\nfoo = 1") index.add(["test.py"]) @@ -254,7 +254,7 @@ def test_build_dirty_repo(builddir): Test that build fails cleanly with a dirty repo """ tmppath = pathlib.Path(builddir) - with open(tmppath / "test.py", "w") as test_txt: + with open(tmppath / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc\nfoo = 1") runner = CliRunner() diff --git a/test/integration/test_complex_commits.py b/test/integration/test_complex_commits.py index 4903fe49..5a9028d8 100644 --- a/test/integration/test_complex_commits.py +++ b/test/integration/test_complex_commits.py @@ -26,10 +26,10 @@ def test_skip_files(tmpdir, cache_path): tmppath.mkdir() # Write two test files to the repo - with open(tmppath / "test1.py", "w") as test1_txt: + with open(tmppath / "test1.py", "w", encoding="utf8") as test1_txt: test1_txt.write("import abc") - with open(tmppath / "test2.py", "w") as test2_txt: + with open(tmppath / "test2.py", "w", encoding="utf8") as test2_txt: test2_txt.write("import cde") index = repo.index @@ -41,7 +41,7 @@ def test_skip_files(tmpdir, cache_path): commit = index.commit("commit two files", author=author, committer=committer) # Change the second file and commit that - with open(tmppath / "test2.py", "w") as test2_txt: + with open(tmppath / "test2.py", "w", encoding="utf8") as test2_txt: test2_txt.write("import zzz\nprint(1)") repo.index.add([str(tmppath / "test2.py")]) @@ -50,7 +50,7 @@ def test_skip_files(tmpdir, cache_path): ) # Change the first file and commit that - with open(tmppath / "test1.py", "w") as test2_txt: + with open(tmppath / "test1.py", "w", encoding="utf8") as test2_txt: test2_txt.write("import zzz\nprint(1)") repo.index.add([str(tmppath / "test1.py")]) @@ -77,13 +77,13 @@ def test_skip_files(tmpdir, cache_path): assert rev_path.exists() # Inspect the contents of the index for the existence of both files - with open(index_path) as index_file: + with open(index_path, encoding="utf8") as index_file: index = json.load(index_file) assert len(index) == 3 # Look at the first commit - with open(rev_path) as rev_file: + with open(rev_path, encoding="utf8") as rev_file: data = json.load(rev_file) assert "raw" in data["operator_data"] @@ -94,7 +94,7 @@ def test_skip_files(tmpdir, cache_path): rev2_path = cache_path / "git" / (commit2.name_rev.split(" ")[0] + ".json") assert rev2_path.exists() - with open(rev2_path) as rev2_file: + with open(rev2_path, encoding="utf8") as rev2_file: data2 = json.load(rev2_file) assert "raw" in data2["operator_data"] @@ -105,7 +105,7 @@ def test_skip_files(tmpdir, cache_path): rev3_path = cache_path / "git" / (commit3.name_rev.split(" ")[0] + ".json") assert rev3_path.exists() - with open(rev3_path) as rev3_file: + with open(rev3_path, encoding="utf8") as rev3_file: data3 = json.load(rev3_file) assert "raw" in data3["operator_data"] diff --git a/test/integration/test_diff.py b/test/integration/test_diff.py index 102d31ad..9b21fc35 100644 --- a/test/integration/test_diff.py +++ b/test/integration/test_diff.py @@ -60,7 +60,7 @@ def test_diff_output_bad_path(builddir): def test_diff_output_remove_all(builddir): """Test the diff feature by removing all functions and classes""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write("print(1)") runner = CliRunner() @@ -91,7 +91,7 @@ def method(self): print(1) """ - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(complex_test)) runner = CliRunner() @@ -120,7 +120,7 @@ def method(self): pass """ - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -141,7 +141,7 @@ def test_diff_output_loc(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -160,7 +160,7 @@ def test_diff_output_loc_and_revision(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -189,7 +189,7 @@ def test_diff_output_rank(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w") as test_py: + with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() diff --git a/test/integration/test_rank.py b/test/integration/test_rank.py index fe62e133..376c4699 100644 --- a/test/integration/test_rank.py +++ b/test/integration/test_rank.py @@ -49,7 +49,7 @@ def test_rank_directory_default_invalid_revision(builddir): def test_rank_directory_default_unindexed_revision(builddir): """Test the rank feature with an unindexed revision.""" repo = Repo(builddir) - with open(builddir / "test.py", "w") as test_txt: + with open(builddir / "test.py", "w", encoding="utf8") as test_txt: test_txt.write("import abc") index = repo.index diff --git a/test/unit/test_archivers.py b/test/unit/test_archivers.py index 2e9d7e23..627d4362 100644 --- a/test/unit/test_archivers.py +++ b/test/unit/test_archivers.py @@ -4,7 +4,7 @@ import pytest import wily.archivers -import wily.archivers.git as git +from wily.archivers import git import wily.config @@ -68,7 +68,7 @@ def execute(self, command): def repo(tmpdir): repo = MockRepo() tmppath = pathlib.Path(tmpdir) - with open(tmppath / ".gitignore", "w") as test_txt: + with open(tmppath / ".gitignore", "w", encoding="utf8") as test_txt: test_txt.write(".wily/") repo.path = tmppath repo.git = MockGit() diff --git a/test/unit/test_build_unit.py b/test/unit/test_build_unit.py index 8f4bdee7..2509d631 100644 --- a/test/unit/test_build_unit.py +++ b/test/unit/test_build_unit.py @@ -2,7 +2,7 @@ import pytest -import wily.commands.build as build +from wily.commands import build from wily.archivers import Archiver, BaseArchiver, Revision from wily.config import DEFAULT_CONFIG from wily.operators import BaseOperator, Operator, OperatorLevel diff --git a/test/unit/test_cache.py b/test/unit/test_cache.py index 5a6565e7..e6085503 100644 --- a/test/unit/test_cache.py +++ b/test/unit/test_cache.py @@ -4,7 +4,7 @@ import pytest -import wily.cache as cache +from wily import cache from wily.archivers import Revision from wily.config import ARCHIVER_GIT, DEFAULT_CONFIG @@ -27,7 +27,7 @@ def test_exists_older(tmpdir): tmp_path = pathlib.Path(tmpdir) config.cache_path = tmp_path / ".wily" (tmp_path / ".wily").mkdir() - with open((tmp_path / ".wily" / "index.json"), "w+") as index: + with open((tmp_path / ".wily" / "index.json"), "w+", encoding="utf8") as index: index.write('{"version": "0.1.0"}') assert cache.exists(config) @@ -50,11 +50,11 @@ def test_get_default_metrics_empty(tmpdir): config.cache_path = str(tmppath) tmppath.mkdir() (tmppath / "git").mkdir() - with open(tmppath / "git" / "index.json", "w+") as f: + with open(tmppath / "git" / "index.json", "w+", encoding="utf8") as f: f.write("[]") metrics = cache.get_default_metrics(config) - assert metrics == [] + assert not metrics def test_create_and_delete(tmpdir): @@ -115,7 +115,7 @@ def test_store_basic(tmpdir): deleted_files=[target_path], ) fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS) - with open(fn) as cache_item: + with open(fn, encoding="utf8") as cache_item: result = json.load(cache_item) assert isinstance(result, dict) assert result == _TEST_STATS @@ -171,7 +171,7 @@ def test_store_relative_paths(tmpdir): deleted_files=[target_path], ) fn = cache.store(config, ARCHIVER_GIT, _TEST_REVISION, _TEST_STATS) - with open(fn) as cache_item: + with open(fn, encoding="utf8") as cache_item: result = json.load(cache_item) assert isinstance(result, dict) if sys.platform == "win32": @@ -191,7 +191,7 @@ def test_store_index(tmpdir): config.path = tmpdir _TEST_INDEX = [{"message": "a", "date": 1234}, {"message": "b", "date": 1345}] fn = cache.store_archiver_index(config, ARCHIVER_GIT, _TEST_INDEX) - with open(fn) as cache_item: + with open(fn, encoding="utf8") as cache_item: result = json.load(cache_item) assert isinstance(result, list) assert result[0] == _TEST_INDEX[1] diff --git a/test/unit/test_config.py b/test/unit/test_config.py index 4a5d97a4..555dda0a 100644 --- a/test/unit/test_config.py +++ b/test/unit/test_config.py @@ -12,7 +12,7 @@ def test_config_empty_defaults(tmpdir): config = """ """ config_path = os.path.join(tmpdir, "wily.cfg") - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) cfg = wily.config.load(config_path) @@ -31,7 +31,7 @@ def test_config_archiver(tmpdir): archiver = foo """ config_path = os.path.join(tmpdir, "wily.cfg") - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) cfg = wily.config.load(config_path) @@ -59,7 +59,7 @@ def test_config_operators(tmpdir, raw_operators, expected_operators): operators = {raw_operators} """ config_path = os.path.join(tmpdir, "wily.cfg") - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) cfg = wily.config.load(config_path) @@ -78,7 +78,7 @@ def test_config_max_revisions(tmpdir): max_revisions = 14 """ config_path = os.path.join(tmpdir, "wily.cfg") - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) cfg = wily.config.load(config_path) @@ -97,7 +97,7 @@ def test_config_cache_path(tmpdir): cache_path = .wily/ """ config_path = os.path.join(tmpdir, "wily.cfg") - with open(config_path, "w") as config_f: + with open(config_path, "w", encoding="utf8") as config_f: config_f.write(config) cfg = wily.config.load(config_path) From 2dc9080aa8838dc5dc15e3add49f08f100884f5a Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Wed, 30 Nov 2022 09:53:52 +1300 Subject: [PATCH 2/3] ran black to fix automated build fails --- test/integration/test_all_operators.py | 4 +++- test/integration/test_diff.py | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test/integration/test_all_operators.py b/test/integration/test_all_operators.py index 3f4cf303..e1714816 100644 --- a/test/integration/test_all_operators.py +++ b/test/integration/test_all_operators.py @@ -66,7 +66,9 @@ def method(self): print(1) """ - with open(pathlib.Path(gitdir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(gitdir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(complex_test)) result = runner.invoke( diff --git a/test/integration/test_diff.py b/test/integration/test_diff.py index 9b21fc35..65c46d37 100644 --- a/test/integration/test_diff.py +++ b/test/integration/test_diff.py @@ -60,7 +60,9 @@ def test_diff_output_bad_path(builddir): def test_diff_output_remove_all(builddir): """Test the diff feature by removing all functions and classes""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write("print(1)") runner = CliRunner() @@ -91,7 +93,9 @@ def method(self): print(1) """ - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(complex_test)) runner = CliRunner() @@ -120,7 +124,9 @@ def method(self): pass """ - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -141,7 +147,9 @@ def test_diff_output_loc(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -160,7 +168,9 @@ def test_diff_output_loc_and_revision(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() @@ -189,7 +199,9 @@ def test_diff_output_rank(builddir): simple_test = """print("test")""" - with open(pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8") as test_py: + with open( + pathlib.Path(builddir) / "src" / "test.py", "w", encoding="utf8" + ) as test_py: test_py.write(dedent(simple_test)) runner = CliRunner() From 5d8b2b4ca357e2ff3080fb4a5687f2397cddf71d Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Wed, 30 Nov 2022 14:11:15 +1300 Subject: [PATCH 3/3] and fixed isort complaints as well --- src/wily/commands/build.py | 2 +- src/wily/state.py | 3 +-- test/unit/test_archivers.py | 2 +- test/unit/test_build_unit.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wily/commands/build.py b/src/wily/commands/build.py index 86cfbd02..7ff151ee 100644 --- a/src/wily/commands/build.py +++ b/src/wily/commands/build.py @@ -6,8 +6,8 @@ """ import multiprocessing import os -import sys import pathlib +import sys from progress.bar import Bar diff --git a/src/wily/state.py b/src/wily/state.py index 0605b108..9e266a85 100644 --- a/src/wily/state.py +++ b/src/wily/state.py @@ -7,8 +7,7 @@ from dataclasses import asdict, dataclass from typing import List -from wily import cache -from wily import logger +from wily import cache, logger from wily.archivers import Revision, resolve_archiver from wily.operators import get_metric diff --git a/test/unit/test_archivers.py b/test/unit/test_archivers.py index 627d4362..2313c140 100644 --- a/test/unit/test_archivers.py +++ b/test/unit/test_archivers.py @@ -4,8 +4,8 @@ import pytest import wily.archivers -from wily.archivers import git import wily.config +from wily.archivers import git class MockAuthor: diff --git a/test/unit/test_build_unit.py b/test/unit/test_build_unit.py index 2509d631..49e131ef 100644 --- a/test/unit/test_build_unit.py +++ b/test/unit/test_build_unit.py @@ -2,8 +2,8 @@ import pytest -from wily.commands import build from wily.archivers import Archiver, BaseArchiver, Revision +from wily.commands import build from wily.config import DEFAULT_CONFIG from wily.operators import BaseOperator, Operator, OperatorLevel