diff --git a/dvc/command/status.py b/dvc/command/status.py index 7a37c5a63..c67395602 100644 --- a/dvc/command/status.py +++ b/dvc/command/status.py @@ -39,7 +39,7 @@ class CmdDataStatus(CmdDataBase): for key, value in status.items(): if isinstance(value, str): - ui.write("{}{}{}".format(ind, self._normalize(value), key)) + ui.write(f"{ind}{self._normalize(value)}{key}") elif value: ui.write(f"{ind}{key}:") self._show(value, indent + 1) diff --git a/dvc/dependency/repo.py b/dvc/dependency/repo.py index 32f51b890..d7f61a4d5 100644 --- a/dvc/dependency/repo.py +++ b/dvc/dependency/repo.py @@ -41,7 +41,7 @@ class RepoDependency(Dependency): return False def __str__(self): - return "{} ({})".format(self.def_path, self.def_repo[self.PARAM_URL]) + return f"{self.def_path} ({self.def_repo[self.PARAM_URL]})" def workspace_status(self): current = self.get_obj(locked=True).hash_info diff --git a/dvc/dvcfile.py b/dvc/dvcfile.py index 5c4392082..6e769ce90 100644 --- a/dvc/dvcfile.py +++ b/dvc/dvcfile.py @@ -200,9 +200,7 @@ class SingleStageFile(FileMixin): assert not isinstance(stage, PipelineStage) if self.verify: check_dvcfile_path(self.repo, self.path) - logger.debug( - "Saving information to '{file}'.".format(file=relpath(self.path)) - ) + logger.debug(f"Saving information to '{relpath(self.path)}'.") dump_yaml(self.path, serialize.to_single_stage_file(stage)) self.repo.scm.track_file(self.relpath) @@ -300,7 +298,7 @@ class PipelineFile(FileMixin): if not self.exists(): return - with open(self.path, "r", encoding="utf-8") as f: + with open(self.path, encoding="utf-8") as f: d = parse_yaml_for_update(f.read(), self.path) self.validate(d, self.path) diff --git a/dvc/ignore.py b/dvc/ignore.py index d18e3114a..141a482fa 100644 --- a/dvc/ignore.py +++ b/dvc/ignore.py @@ -57,7 +57,7 @@ class DvcIgnorePatterns(DvcIgnore): dirname = os.path.normpath(os.path.dirname(path)) with fs.open(path, encoding="utf-8") as fobj: path_spec_lines = [ - PatternInfo(line, "{}:{}:{}".format(name, line_no + 1, line)) + PatternInfo(line, f"{name}:{line_no + 1}:{line}") for line_no, line in enumerate( map(str.strip, fobj.readlines()) ) @@ -166,7 +166,7 @@ class DvcIgnoreFilter: ".hg/", ".git/", ".git", - "{}/".format(Repo.DVC_DIR), + f"{Repo.DVC_DIR}/", ] self.fs = fs diff --git a/dvc/info.py b/dvc/info.py index 87e7b74e7..ec2420d7f 100644 --- a/dvc/info.py +++ b/dvc/info.py @@ -42,9 +42,7 @@ def get_dvc_info(): # later decides to enable shared cache mode with # `dvc config cache.shared group`. if os.path.exists(repo.odb.local.cache_dir): - info.append( - "Cache types: {}".format(_get_linktype_support_info(repo)) - ) + info.append(f"Cache types: {_get_linktype_support_info(repo)}") fs_type = get_fs_type(repo.odb.local.cache_dir) info.append(f"Cache directory: {fs_type}") else: @@ -56,7 +54,7 @@ def get_dvc_info(): root_directory = repo.root_dir fs_root = get_fs_type(os.path.abspath(root_directory)) info.append(f"Workspace directory: {fs_root}") - info.append("Repo: {}".format(_get_dvc_repo_info(repo))) + info.append(f"Repo: {_get_dvc_repo_info(repo)}") except NotDvcRepoError: pass except SCMError: diff --git a/dvc/logger.py b/dvc/logger.py index 0d5f19273..cd32069ef 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -62,7 +62,7 @@ def addLoggingLevel(levelName, levelNum, methodName=None): class LoggingException(Exception): def __init__(self, record): - msg = "failed to log {}".format(str(record)) + msg = f"failed to log {str(record)}" super().__init__(msg) diff --git a/dvc/objects/db/base.py b/dvc/objects/db/base.py index 7c2b92657..9bbfea0c6 100644 --- a/dvc/objects/db/base.py +++ b/dvc/objects/db/base.py @@ -396,9 +396,7 @@ class ObjectDB: """Return list of the specified hashes which exist in this fs. Hashes will be queried individually. """ - logger.debug( - "Querying {} hashes via object_exists".format(len(hashes)) - ) + logger.debug(f"Querying {len(hashes)} hashes via object_exists") with Tqdm( desc="Querying " + ("cache in " + name if name else "remote cache"), @@ -493,7 +491,7 @@ class ObjectDB: hashes - remote_hashes, jobs, name ) - logger.debug("Querying '{}' hashes via traverse".format(len(hashes))) + logger.debug(f"Querying '{len(hashes)}' hashes via traverse") remote_hashes = set( self.list_hashes_traverse(remote_size, remote_hashes, jobs, name) ) diff --git a/dvc/objects/db/local.py b/dvc/objects/db/local.py index 4af4366fc..753924241 100644 --- a/dvc/objects/db/local.py +++ b/dvc/objects/db/local.py @@ -112,7 +112,7 @@ class LocalObjectDB(ObjectDB): # would get only the part of file. So, at first, the file should be # copied with the temporary name, and then original file should be # replaced by new. - copyfile(path, tmp, name="Unprotecting '{}'".format(relpath(path))) + copyfile(path, tmp, name=f"Unprotecting '{relpath(path)}'") remove(path) os.rename(tmp, path) diff --git a/dvc/path_info.py b/dvc/path_info.py index 512faa4dd..0ed5437e2 100644 --- a/dvc/path_info.py +++ b/dvc/path_info.py @@ -52,7 +52,7 @@ class PathInfo(pathlib.PurePath, _BasePath): return relpath(path) def __repr__(self): - return "{}: '{}'".format(type(self).__name__, self) + return f"{type(self).__name__}: '{self}'" # This permits passing it to file utils directly in Python 3.6+ def __fspath__(self): @@ -174,7 +174,7 @@ class URLInfo(_BasePath): return self.url def __repr__(self): - return "{}: '{}'".format(type(self).__name__, self) + return f"{type(self).__name__}: '{self}'" def __eq__(self, other): if isinstance(other, (str, bytes)): diff --git a/dvc/remote/base.py b/dvc/remote/base.py index fff64b32e..94b70bead 100644 --- a/dvc/remote/base.py +++ b/dvc/remote/base.py @@ -138,7 +138,7 @@ class Remote: indexed_hashes = set(self.index.intersection(hashes)) hashes -= indexed_hashes indexed_hashes = list(indexed_hashes) - logger.debug("Matched '{}' indexed hashes".format(len(indexed_hashes))) + logger.debug(f"Matched '{len(indexed_hashes)}' indexed hashes") if not hashes: return indexed_hashes diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 8377403e5..5a560c14c 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -585,7 +585,7 @@ class Experiments: logger.debug( "Reproducing experiment revs '%s'", - ", ".join((rev[:7] for rev in to_run)), + ", ".join(rev[:7] for rev in to_run), ) executors = self._init_executors(to_run) diff --git a/dvc/repo/plots/template.py b/dvc/repo/plots/template.py index 17435860b..187e5b7f0 100644 --- a/dvc/repo/plots/template.py +++ b/dvc/repo/plots/template.py @@ -84,7 +84,7 @@ class Template: @classmethod def _anchor_str(cls, name): - return '"{}"'.format(cls.anchor(name)) + return f'"{cls.anchor(name)}"' @classmethod def _fill_metadata(cls, content, props): diff --git a/dvc/rwlock.py b/dvc/rwlock.py index 4ec2127bf..29d7d90ca 100644 --- a/dvc/rwlock.py +++ b/dvc/rwlock.py @@ -28,9 +28,7 @@ class RWLockFileCorruptedError(DvcException): class RWLockFileFormatError(DvcException): def __init__(self, path): - super().__init__( - "RWLock-file '{}' format error.".format(relpath(path)) - ) + super().__init__(f"RWLock-file '{relpath(path)}' format error.") @contextmanager diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 6136a4e86..8be455a54 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -163,7 +163,7 @@ class Git(Base): if self.is_ignored(path): return - msg = "Adding '{}' to '{}'.".format(relpath(path), relpath(gitignore)) + msg = f"Adding '{relpath(path)}' to '{relpath(gitignore)}'." logger.debug(msg) self._add_entry_to_gitignore(entry, gitignore) diff --git a/dvc/scm/git/stash.py b/dvc/scm/git/stash.py index af2516810..05213a596 100644 --- a/dvc/scm/git/stash.py +++ b/dvc/scm/git/stash.py @@ -46,7 +46,7 @@ class Stash: def pop(self): logger.debug("Popping from stash '%s'", self.ref) - ref = "{0}@{{0}}".format(self.ref) + ref = f"{self.ref}@{{0}}" rev = self.scm.resolve_rev(ref) try: self.apply(rev) diff --git a/dvc/stage/run.py b/dvc/stage/run.py index 972a92877..4b77cdde9 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -116,7 +116,7 @@ def _get_monitor_tasks(stage, checkpoint_func, proc): result.append(CheckpointTask(stage, checkpoint_func, proc)) - live = first((o for o in stage.outs if (o.live and o.live["html"]))) + live = first(o for o in stage.outs if (o.live and o.live["html"])) if live: from .monitor import LiveTask diff --git a/dvc/stage/serialize.py b/dvc/stage/serialize.py index 19f92319f..bc1c22391 100644 --- a/dvc/stage/serialize.py +++ b/dvc/stage/serialize.py @@ -170,10 +170,10 @@ def to_single_stage_lockfile(stage: "Stage") -> dict: res = OrderedDict([("cmd", stage.cmd)]) params, deps = split_params_deps(stage) - deps, outs = [ + deps, outs = ( [_dumpd(item) for item in sort_by_path(items)] for items in [deps, stage.outs] - ] + ) params = _serialize_params_values(params) if deps: res[PARAM_DEPS] = deps diff --git a/dvc/utils/html.py b/dvc/utils/html.py index b4b56a9a0..3a970174c 100644 --- a/dvc/utils/html.py +++ b/dvc/utils/html.py @@ -82,7 +82,7 @@ def write( ): page_html = None if template_path: - with open(template_path, "r") as fobj: + with open(template_path) as fobj: page_html = fobj.read() document = HTML(page_html) diff --git a/fastentrypoints.py b/fastentrypoints.py index fb4a8646e..527f68624 100644 --- a/fastentrypoints.py +++ b/fastentrypoints.py @@ -81,8 +81,7 @@ def get_args(cls, dist, header=None): # noqa: D205,D400 ) # pylint: disable=E1101,protected-access args = cls._get_script_args(type_, name, header, script_text) - for res in args: - yield res + yield from args # pylint: disable=E1101 diff --git a/setup.py b/setup.py index e86ea4b09..92db2e522 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ class build_py(_build_py): self.mkpath(path) with open(os.path.join(path, "version.py"), "w") as fobj: fobj.write("# AUTOGENERATED at build time by setup.py\n") - fobj.write('__version__ = "{}"\n'.format(version)) + fobj.write(f'__version__ = "{version}"\n') def run(self): self.execute(self.pin_version, ()) @@ -123,7 +123,7 @@ setup( name="dvc", version=version, description="Git for data scientists - manage your code and data together", - long_description=open("README.rst", "r", encoding="UTF-8").read(), + long_description=open("README.rst", encoding="UTF-8").read(), author="Dmitry Petrov", author_email="dmitry@dvc.org", download_url="https://github.com/iterative/dvc", diff --git a/tests/func/experiments/test_remote.py b/tests/func/experiments/test_remote.py index cd2d338f6..177476853 100644 --- a/tests/func/experiments/test_remote.py +++ b/tests/func/experiments/test_remote.py @@ -9,7 +9,7 @@ from dvc.repo.experiments.utils import exp_refs_by_rev @pytest.fixture def git_upstream(tmp_dir, erepo_dir): - url = "file://{}".format(erepo_dir.resolve().as_posix()) + url = f"file://{erepo_dir.resolve().as_posix()}" tmp_dir.scm.gitpython.repo.create_remote("upstream", url) erepo_dir.remote = "upstream" erepo_dir.url = url @@ -18,7 +18,7 @@ def git_upstream(tmp_dir, erepo_dir): @pytest.fixture def git_downstream(tmp_dir, erepo_dir): - url = "file://{}".format(tmp_dir.resolve().as_posix()) + url = f"file://{tmp_dir.resolve().as_posix()}" erepo_dir.scm.gitpython.repo.create_remote("upstream", url) erepo_dir.remote = "upstream" erepo_dir.url = url diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 0b6164563..f8d15d7ce 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -5,10 +5,10 @@ import shutil import stat import textwrap import time +from unittest.mock import call, patch import colorama import pytest -from mock import call, patch import dvc as dvc_module from dvc.dvcfile import DVC_FILE_SUFFIX diff --git a/tests/func/test_analytics.py b/tests/func/test_analytics.py index f0e9c71f4..8c3cfa98b 100644 --- a/tests/func/test_analytics.py +++ b/tests/func/test_analytics.py @@ -1,6 +1,5 @@ import os - -import mock +from unittest import mock from dvc.analytics import _scm_in_use from dvc.main import main diff --git a/tests/func/test_check_ignore.py b/tests/func/test_check_ignore.py index b1e2d674c..d7dc1810f 100644 --- a/tests/func/test_check_ignore.py +++ b/tests/func/test_check_ignore.py @@ -22,8 +22,8 @@ def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog, capsys): @pytest.mark.parametrize( "file,ret,output", [ - ("file", 0, "{}:1:f*\tfile\n".format(DvcIgnore.DVCIGNORE_FILE)), - ("foo", 0, "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE)), + ("file", 0, f"{DvcIgnore.DVCIGNORE_FILE}:1:f*\tfile\n"), + ("foo", 0, f"{DvcIgnore.DVCIGNORE_FILE}:2:!foo\tfoo\n"), ( os.path.join("dir", "foobar"), 0, @@ -129,8 +129,8 @@ def test_check_ignore_details_all(tmp_dir, dvc, capsys): assert main(["check-ignore", "-d", "-a", "foo"]) == 0 out, _ = capsys.readouterr() - assert "{}:1:f*\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in out - assert "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in out + assert f"{DvcIgnore.DVCIGNORE_FILE}:1:f*\tfoo\n" in out + assert f"{DvcIgnore.DVCIGNORE_FILE}:2:!foo\tfoo\n" in out @pytest.mark.parametrize( diff --git a/tests/func/test_checkout.py b/tests/func/test_checkout.py index 3501d43ea..d1702b3e3 100644 --- a/tests/func/test_checkout.py +++ b/tests/func/test_checkout.py @@ -5,9 +5,9 @@ import os import shutil import stat import textwrap +from unittest.mock import patch import pytest -from mock import patch from dvc.dvcfile import DVC_FILE_SUFFIX, PIPELINE_FILE, Dvcfile from dvc.exceptions import ( diff --git a/tests/func/test_external_repo.py b/tests/func/test_external_repo.py index ab7189c09..73f359268 100644 --- a/tests/func/test_external_repo.py +++ b/tests/func/test_external_repo.py @@ -1,6 +1,5 @@ import os - -from mock import ANY, patch +from unittest.mock import ANY, patch from dvc.external_repo import CLONES, external_repo from dvc.fs.local import LocalFileSystem diff --git a/tests/func/test_get.py b/tests/func/test_get.py index 892408327..36a1d6dc1 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -266,7 +266,7 @@ def test_get_pipeline_tracked_outs( dvc.scm.commit("add pipeline stage") with git_dir.chdir(): - Repo.get("file:///{}".format(os.fspath(tmp_dir)), "bar", out="baz") + Repo.get(f"file:///{os.fspath(tmp_dir)}", "bar", out="baz") assert (git_dir / "baz").read_text() == "foo" diff --git a/tests/func/test_ignore.py b/tests/func/test_ignore.py index c0f8d8e75..10bd0d312 100644 --- a/tests/func/test_ignore.py +++ b/tests/func/test_ignore.py @@ -21,7 +21,7 @@ def _to_pattern_info_list(str_list: List): @pytest.mark.parametrize("filename", ["ignored", "ั‚ะตัั‚"]) def test_ignore(tmp_dir, dvc, filename): tmp_dir.gen({"dir": {filename: filename, "other": "text2"}}) - tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "dir/{}".format(filename)) + tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, f"dir/{filename}") dvc._reset() @@ -342,17 +342,17 @@ def test_pattern_trie_fs(tmp_dir, dvc): first_pattern = merge_patterns( *base_pattern, _to_pattern_info_list(["a", "b", "c"]), - os.fspath(tmp_dir / "top" / "first") + os.fspath(tmp_dir / "top" / "first"), ) second_pattern = merge_patterns( *first_pattern, _to_pattern_info_list(["d", "e", "f"]), - os.fspath(tmp_dir / "top" / "first" / "middle" / "second") + os.fspath(tmp_dir / "top" / "first" / "middle" / "second"), ) other_pattern = merge_patterns( *base_pattern, _to_pattern_info_list(["1", "2", "3"]), - os.fspath(tmp_dir / "other") + os.fspath(tmp_dir / "other"), ) assert DvcIgnorePatterns(*base_pattern) == ignore_pattern_top diff --git a/tests/func/test_import.py b/tests/func/test_import.py index 372af19ac..c8c765510 100644 --- a/tests/func/test_import.py +++ b/tests/func/test_import.py @@ -1,9 +1,9 @@ import filecmp import os +from unittest.mock import patch import pytest from funcy import first -from mock import patch import dvc.data_cloud as cloud from dvc.config import NoRemoteError @@ -407,9 +407,7 @@ def test_import_pipeline_tracked_outs( dvc.scm.commit("add pipeline stage") with erepo_dir.chdir(): - erepo_dir.dvc.imp( - "file:///{}".format(os.fspath(tmp_dir)), "bar", out="baz" - ) + erepo_dir.dvc.imp(f"file:///{os.fspath(tmp_dir)}", "bar", out="baz") assert (erepo_dir / "baz").read_text() == "foo" diff --git a/tests/func/test_remote.py b/tests/func/test_remote.py index 2e9fc083e..10dce018d 100644 --- a/tests/func/test_remote.py +++ b/tests/func/test_remote.py @@ -1,10 +1,10 @@ import errno import os import stat +from unittest.mock import patch import configobj import pytest -from mock import patch from dvc.config import Config from dvc.exceptions import DownloadError, RemoteCacheRequiredError, UploadError diff --git a/tests/func/test_repro.py b/tests/func/test_repro.py index 73dd2f35c..948505a92 100644 --- a/tests/func/test_repro.py +++ b/tests/func/test_repro.py @@ -3,9 +3,9 @@ import os import re import shutil from pathlib import Path +from unittest.mock import patch import pytest -from mock import patch from dvc.dvcfile import DVC_FILE, Dvcfile from dvc.exceptions import ( diff --git a/tests/func/test_run_single_stage.py b/tests/func/test_run_single_stage.py index a13fd825f..146d0a020 100644 --- a/tests/func/test_run_single_stage.py +++ b/tests/func/test_run_single_stage.py @@ -4,8 +4,8 @@ import os import textwrap import uuid from pathlib import Path +from unittest import mock -import mock import pytest from dvc.dependency.base import DependencyIsStageFileError diff --git a/tests/func/test_status.py b/tests/func/test_status.py index 655c179c6..c2902dedf 100644 --- a/tests/func/test_status.py +++ b/tests/func/test_status.py @@ -67,9 +67,7 @@ def test_status_before_and_after_dvc_init(tmp_dir, dvc, git_dir): (status,) = dvc.status(["file.dvc"])["file.dvc"] assert status == { - "changed deps": { - "file ({})".format(os.fspath(git_dir)): "update available" - } + "changed deps": {f"file ({os.fspath(git_dir)})": "update available"} } diff --git a/tests/func/test_update.py b/tests/func/test_update.py index 0055f3cf9..29a1c6011 100644 --- a/tests/func/test_update.py +++ b/tests/func/test_update.py @@ -144,7 +144,7 @@ def test_update_before_and_after_dvc_init(tmp_dir, dvc, git_dir): "file.dvc": [ { "changed deps": { - "file ({})".format(os.fspath(git_dir)): "update available" + f"file ({os.fspath(git_dir)})": "update available" } } ] diff --git a/tests/unit/command/test_diff.py b/tests/unit/command/test_diff.py index 70877c33d..2251291f6 100644 --- a/tests/unit/command/test_diff.py +++ b/tests/unit/command/test_diff.py @@ -1,7 +1,7 @@ import collections import os +from unittest import mock -import mock import pytest from dvc.cli import parse_args diff --git a/tests/unit/output/test_local.py b/tests/unit/output/test_local.py index 39f551e40..a071eaf01 100644 --- a/tests/unit/output/test_local.py +++ b/tests/unit/output/test_local.py @@ -1,6 +1,5 @@ import os - -from mock import patch +from unittest.mock import patch from dvc.hash_info import HashInfo from dvc.output import Output diff --git a/tests/unit/remote/ssh/test_ssh.py b/tests/unit/remote/ssh/test_ssh.py index bd2570187..72e9d5692 100644 --- a/tests/unit/remote/ssh/test_ssh.py +++ b/tests/unit/remote/ssh/test_ssh.py @@ -1,9 +1,9 @@ import getpass import os import sys +from unittest.mock import mock_open, patch import pytest -from mock import mock_open, patch from dvc.fs.ssh import SSHFileSystem from dvc.system import System diff --git a/tests/unit/remote/test_base.py b/tests/unit/remote/test_base.py index 3a9a44c84..2781bb247 100644 --- a/tests/unit/remote/test_base.py +++ b/tests/unit/remote/test_base.py @@ -1,6 +1,6 @@ import math +from unittest import mock -import mock import pytest from dvc.fs.base import BaseFileSystem, RemoteCmdError diff --git a/tests/unit/remote/test_slow_link_detection.py b/tests/unit/remote/test_slow_link_detection.py index 49343a882..979b5b936 100644 --- a/tests/unit/remote/test_slow_link_detection.py +++ b/tests/unit/remote/test_slow_link_detection.py @@ -1,4 +1,5 @@ -import mock +from unittest import mock + import pytest import dvc.remote.slow_link_detection diff --git a/tests/unit/repo/test_reproduce.py b/tests/unit/repo/test_reproduce.py index 488eeffbe..af2d49187 100644 --- a/tests/unit/repo/test_reproduce.py +++ b/tests/unit/repo/test_reproduce.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock @mock.patch("dvc.repo.reproduce._reproduce_stage", returns=[]) diff --git a/tests/unit/scm/test_git.py b/tests/unit/scm/test_git.py index 1c3b09daa..b3662fed6 100644 --- a/tests/unit/scm/test_git.py +++ b/tests/unit/scm/test_git.py @@ -238,7 +238,7 @@ def test_push_refspec(tmp_dir, scm, make_tmp_dir, use_url): } ) remote_dir = make_tmp_dir("git-remote", scm=True) - url = "file://{}".format(remote_dir.resolve().as_posix()) + url = f"file://{remote_dir.resolve().as_posix()}" scm.gitpython.repo.create_remote("origin", url) with pytest.raises(SCMError): @@ -261,7 +261,7 @@ def test_push_refspec(tmp_dir, scm, make_tmp_dir, use_url): def test_fetch_refspecs(tmp_dir, scm, make_tmp_dir): remote_dir = make_tmp_dir("git-remote", scm=True) - url = "file://{}".format(remote_dir.resolve().as_posix()) + url = f"file://{remote_dir.resolve().as_posix()}" remote_dir.scm_gen({"file": "0"}, commit="init") init_rev = remote_dir.scm.get_rev() @@ -428,7 +428,7 @@ def test_resolve_rev(tmp_dir, scm, make_tmp_dir, git): pytest.skip() remote_dir = make_tmp_dir("git-remote", scm=True) - url = "file://{}".format(remote_dir.resolve().as_posix()) + url = f"file://{remote_dir.resolve().as_posix()}" scm.gitpython.repo.create_remote("origin", url) scm.gitpython.repo.create_remote("upstream", url) diff --git a/tests/unit/stage/test_stage.py b/tests/unit/stage/test_stage.py index 0ad380ff6..bf251af2f 100644 --- a/tests/unit/stage/test_stage.py +++ b/tests/unit/stage/test_stage.py @@ -2,8 +2,8 @@ import os import signal import subprocess import threading +from unittest import mock -import mock import pytest from dvc.dependency.repo import RepoDependency diff --git a/tests/unit/test_daemon.py b/tests/unit/test_daemon.py index d45fe96eb..d56797203 100644 --- a/tests/unit/test_daemon.py +++ b/tests/unit/test_daemon.py @@ -1,8 +1,6 @@ import inspect import os -from unittest import TestCase - -import mock +from unittest import TestCase, mock from dvc import daemon diff --git a/tests/unit/test_ignore.py b/tests/unit/test_ignore.py index 8ec2cb453..5a114c78e 100644 --- a/tests/unit/test_ignore.py +++ b/tests/unit/test_ignore.py @@ -1,7 +1,7 @@ import os +from unittest.mock import MagicMock, mock_open, patch import pytest -from mock import MagicMock, mock_open, patch from dvc.ignore import DvcIgnorePatterns diff --git a/tests/unit/test_metrics.py b/tests/unit/test_metrics.py index c5a6a3783..1ab9b4504 100644 --- a/tests/unit/test_metrics.py +++ b/tests/unit/test_metrics.py @@ -21,7 +21,7 @@ def test_metrics_order(tmp_dir, dvc): ) with (tmp_dir / "sub").chdir(): dvc.stage.add( - metrics=[str(tmp_dir / "p1.json"), str("p3.json")], + metrics=[str(tmp_dir / "p1.json"), "p3.json"], cmd="cmd2", name="stage2", ) diff --git a/tests/unit/test_progress.py b/tests/unit/test_progress.py index 30dd7e662..f8fd13fa3 100644 --- a/tests/unit/test_progress.py +++ b/tests/unit/test_progress.py @@ -1,7 +1,6 @@ import logging import sys - -import mock +from unittest import mock from dvc.progress import Tqdm from dvc.utils import env2bool diff --git a/tests/unit/test_prompt.py b/tests/unit/test_prompt.py index 68ccb8877..1a29a08d7 100644 --- a/tests/unit/test_prompt.py +++ b/tests/unit/test_prompt.py @@ -1,6 +1,4 @@ -from unittest import TestCase - -import mock +from unittest import TestCase, mock from dvc.prompt import confirm diff --git a/tests/unit/test_updater.py b/tests/unit/test_updater.py index c066c239a..854f408a4 100644 --- a/tests/unit/test_updater.py +++ b/tests/unit/test_updater.py @@ -2,8 +2,8 @@ import json import logging import os import time +from unittest import mock -import mock import pytest from dvc import __version__ diff --git a/tests/unit/test_version.py b/tests/unit/test_version.py index 5cd4f8ca5..f41eca099 100644 --- a/tests/unit/test_version.py +++ b/tests/unit/test_version.py @@ -1,6 +1,5 @@ import subprocess - -import mock +from unittest import mock import dvc.version diff --git a/tests/unit/utils/test_fs.py b/tests/unit/utils/test_fs.py index 3a15e7a30..23eb644d5 100644 --- a/tests/unit/utils/test_fs.py +++ b/tests/unit/utils/test_fs.py @@ -1,9 +1,9 @@ import filecmp import os from unittest import TestCase +from unittest.mock import patch import pytest -from mock import patch import dvc from dvc.fs.local import LocalFileSystem