From ca3704997bb32454569494fb0ed74ca913d9af58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Jul 2023 20:11:15 +0545 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#9632) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/asottile/pyupgrade: v3.3.1 → v3.9.0](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.9.0) - https://github.com/charliermarsh/ruff-pre-commit → https://github.com/astral-sh/ruff-pre-commit - [github.com/astral-sh/ruff-pre-commit: v0.0.261 → v0.0.277](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.261...v0.0.277) - [github.com/codespell-project/codespell: v2.2.4 → v2.2.5](https://github.com/codespell-project/codespell/compare/v2.2.4...v2.2.5) * fix ruff complaints --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Saugat Pachhai (सौगात) --- .pre-commit-config.yaml | 10 +++++----- dvc/cli/__init__.py | 2 +- dvc/cli/utils.py | 4 +--- dvc/commands/data.py | 4 +--- dvc/commands/remote.py | 4 +--- dvc/config_schema.py | 2 +- dvc/daemon.py | 4 +++- dvc/dvcfile.py | 4 +--- dvc/exceptions.py | 14 +++----------- dvc/logger.py | 2 +- dvc/output.py | 6 ++---- dvc/repo/__init__.py | 2 +- dvc/repo/experiments/utils.py | 2 +- dvc/repo/get.py | 2 +- dvc/rwlock.py | 6 ++---- dvc/stage/__init__.py | 5 +---- dvc/stage/run.py | 2 +- dvc/testing/benchmarks/fixtures.py | 2 +- dvc/testing/fixtures.py | 8 +++++--- dvc/ui/__init__.py | 2 +- dvc/ui/pager.py | 3 ++- dvc/utils/__init__.py | 2 +- pyproject.toml | 4 ++-- tests/func/api/test_show.py | 4 ++-- tests/func/experiments/executor/test_ssh.py | 4 ++-- tests/func/experiments/test_experiments.py | 10 ---------- tests/func/experiments/test_show.py | 4 ++-- tests/func/repro/test_repro.py | 4 +--- tests/integration/plots/test_plots.py | 2 +- tests/unit/repo/experiments/queue/test_celery.py | 12 +++++++----- tests/unit/repo/experiments/test_utils.py | 2 +- tests/unit/stage/test_cache.py | 4 ++-- tests/unit/stage/test_stage.py | 6 +++--- 33 files changed, 60 insertions(+), 88 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65ccf6b60e..bd0518508a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,25 +29,25 @@ repos: - id: beautysh args: ["-i", "2"] - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.9.0 hooks: - id: pyupgrade args: - --py38-plus - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.261' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 'v0.0.278' hooks: - id: ruff - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.2.5 hooks: - id: codespell additional_dependencies: ["tomli"] diff --git a/dvc/cli/__init__.py b/dvc/cli/__init__.py index 7114d9921b..74e457dc6f 100644 --- a/dvc/cli/__init__.py +++ b/dvc/cli/__init__.py @@ -192,7 +192,7 @@ def main(argv=None): # noqa: C901, PLR0912, PLR0915 from dvc import PKG, __version__ - pyv = " ".join([python_implementation(), python_version()]) + pyv = f"{python_implementation()} {python_version()}" pkg = f" ({PKG})" if PKG else "" logger.debug("v%s%s, %s on %s", __version__, pkg, pyv, platform()) logger.debug("command: %s", " ".join(argv or sys.argv)) diff --git a/dvc/cli/utils.py b/dvc/cli/utils.py index 15d9671dac..6b794d7b27 100644 --- a/dvc/cli/utils.py +++ b/dvc/cli/utils.py @@ -16,9 +16,7 @@ def append_doc_link(help_message, path): if not path: return help_message doc_base = "https://man.dvc.org/" - return "{message}\nDocumentation: {link}".format( - message=help_message, link=format_link(doc_base + path) - ) + return f"{help_message}\nDocumentation: {format_link(doc_base + path)}" def hide_subparsers_from_help(subparsers): diff --git a/dvc/commands/data.py b/dvc/commands/data.py index 0fce8d5df3..eb1da14d20 100644 --- a/dvc/commands/data.py +++ b/dvc/commands/data.py @@ -90,9 +90,7 @@ def _show_status(cls, status: "DataStatus") -> int: # noqa: C901 ui.write(f" ({hint})") if isinstance(stage_status, dict): - items = [ - ": ".join([state, file]) for file, state in stage_status.items() - ] + items = [f"{state}: {file}" for file, state in stage_status.items()] else: items = stage_status diff --git a/dvc/commands/remote.py b/dvc/commands/remote.py index 600117f09d..03dc430f27 100644 --- a/dvc/commands/remote.py +++ b/dvc/commands/remote.py @@ -127,9 +127,7 @@ def run(self): all_config = self.config.load_config_to_level(None) if self.args.new in all_config.get("remote", {}): raise ConfigError( - "Rename failed. Remote name '{}' already exists.".format( - {self.args.new} - ) + f"Rename failed. Remote name {self.args.new!r} already exists." ) with self.config.edit(self.args.level) as conf: diff --git a/dvc/config_schema.py b/dvc/config_schema.py index 6197250fec..cb3e9cdbe7 100644 --- a/dvc/config_schema.py +++ b/dvc/config_schema.py @@ -75,7 +75,7 @@ def validate(data): class RelPath(str): - pass + __slots__ = () class FeatureSchema(Schema): diff --git a/dvc/daemon.py b/dvc/daemon.py index 494b5eda95..7e57fadea7 100644 --- a/dvc/daemon.py +++ b/dvc/daemon.py @@ -28,7 +28,9 @@ def _popen(cmd, **kwargs) -> Popen: os.path.abspath(os.path.dirname(__file__)), "__main__.py" ) prefix += [main_entrypoint] - return Popen(prefix + cmd, close_fds=True, shell=False, **kwargs) # nosec B603 + return Popen( + prefix + cmd, close_fds=True, shell=False, **kwargs # nosec B603 # noqa: S603 + ) def _spawn_windows(cmd, env): diff --git a/dvc/dvcfile.py b/dvc/dvcfile.py index fa46694a25..67ee60794e 100644 --- a/dvc/dvcfile.py +++ b/dvc/dvcfile.py @@ -97,9 +97,7 @@ def __init__(self, repo, path, verify=True, **kwargs): self.verify = verify def __repr__(self): - return "{}: {}".format( - self.__class__.__name__, relpath(self.path, self.repo.root_dir) - ) + return f"{self.__class__.__name__}: {relpath(self.path, self.repo.root_dir)}" def __hash__(self): return hash(self.path) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 618eeaef49..e4d91dcee2 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -63,9 +63,7 @@ def __init__(self, output, repo=None): self.output = output self.repo = repo super().__init__( - "Unable to find DVC file with output '{path}'".format( - path=relpath(self.output) - ) + f"Unable to find DVC file with output {relpath(self.output)!r}" ) @@ -80,11 +78,7 @@ class StagePathAsOutputError(DvcException): def __init__(self, stage, output): assert isinstance(output, str) - super().__init__( - "{stage} is within an output '{output}' of another stage".format( - stage=stage, output=output - ) - ) + super().__init__(f"{stage} is within an output {output!r} of another stage") class CircularDependencyError(DvcException): @@ -156,9 +150,7 @@ def __init__(self, stages): class ConfirmRemoveError(DvcException): def __init__(self, path): super().__init__( - "unable to remove '{}' without a confirmation. Use `-f` to force.".format( - path - ) + f"unable to remove {path!r} without a confirmation. Use `-f` to force." ) diff --git a/dvc/logger.py b/dvc/logger.py index 6c173e3a05..2ab0b93117 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -56,7 +56,7 @@ def log_to_root(message, *args, **kwargs): class LoggingException(Exception): def __init__(self, record): - msg = f"failed to log {str(record)}" + msg = f"failed to log {record!s}" super().__init__(msg) diff --git a/dvc/output.py b/dvc/output.py index 0cbb521154..cad9428ac4 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -471,9 +471,7 @@ def _parse_path(self, fs, fs_path): return fs.path.abspath(fs.path.normpath(fs_path)) def __repr__(self): - return "{class_name}: '{def_path}'".format( - class_name=type(self).__name__, def_path=self.def_path - ) + return f"{type(self).__name__}: {self.def_path!r}" def __str__(self): if self.fs.protocol != "local": @@ -693,7 +691,7 @@ def ignore_remove(self) -> None: def save(self) -> None: if self.use_cache and not self.is_in_repo: raise DvcException( - f"Saving cached external output {str(self)} is not supported " + f"Saving cached external output {self!s} is not supported " "since DVC 3.0. See " f"{format_link('https://dvc.org/doc/user-guide/upgrade')} " "for more info." diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 66de6e52f2..c857a13c7c 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -482,7 +482,7 @@ def used_objs( # noqa: PLR0913 used_run_cache=None, revs=None, num=1, - push: bool = False, + push: bool = False, # noqa: F811 ): """Get the stages related to the given target and collect the `info` of its outputs. diff --git a/dvc/repo/experiments/utils.py b/dvc/repo/experiments/utils.py index d1095521cf..79c2f6d4bd 100644 --- a/dvc/repo/experiments/utils.py +++ b/dvc/repo/experiments/utils.py @@ -234,7 +234,7 @@ def fix_exp_head(scm: Union["Git", "NoSCM"], ref: Optional[str]) -> Optional[str if ref: name, tail = Git.split_ref_pattern(ref) if name == "HEAD" and scm.get_ref(EXEC_BASELINE): - return "".join((EXEC_BASELINE, tail)) + return f"{EXEC_BASELINE}{tail}" return ref diff --git a/dvc/repo/get.py b/dvc/repo/get.py index cddb25dd7e..6f31064ab0 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -27,7 +27,7 @@ def get(url, path, out=None, rev=None, jobs=None, force=False): out = resolve_output(path, out, force=force) if is_valid_filename(out): - raise GetDVCFileError() + raise GetDVCFileError with Repo.open( url=url, diff --git a/dvc/rwlock.py b/dvc/rwlock.py index ca4abe898b..c59acd9cbd 100644 --- a/dvc/rwlock.py +++ b/dvc/rwlock.py @@ -31,15 +31,13 @@ class RWLockFileCorruptedError(DvcException): def __init__(self, path): super().__init__( - "Unable to read RWLock-file '{}'. JSON structure is corrupted".format( - relpath(path) - ) + f"Unable to read RWLock-file {relpath(path)!r}. JSON structure is corrupted" ) class RWLockFileFormatError(DvcException): def __init__(self, path): - super().__init__(f"RWLock-file '{relpath(path)}' format error.") + super().__init__(f"RWLock-file {relpath(path)!r} format error.") @contextmanager diff --git a/dvc/stage/__init__.py b/dvc/stage/__init__.py index 24e1bf6a2a..795b869c15 100644 --- a/dvc/stage/__init__.py +++ b/dvc/stage/__init__.py @@ -426,10 +426,7 @@ def reproduce(self, interactive=False, **kwargs) -> Optional["Stage"]: logger.info("Stage '%s' didn't change, skipping", self.addressing) return None - msg = "Going to reproduce {stage}. Are you sure you want to continue?".format( - stage=self - ) - + msg = f"Going to reproduce {self}. Are you sure you want to continue?" if interactive and not prompt.confirm(msg): raise DvcException("reproduction aborted by the user") diff --git a/dvc/stage/run.py b/dvc/stage/run.py index aca0fbc271..733d334ea5 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -80,7 +80,7 @@ def _run(executable, cmd, **kwargs): exec_cmd = _make_cmd(executable, cmd) try: - p = subprocess.Popen(exec_cmd, **kwargs) # nosec B603 + p = subprocess.Popen(exec_cmd, **kwargs) # nosec B603 # noqa: S603 if main_thread: old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) diff --git a/dvc/testing/benchmarks/fixtures.py b/dvc/testing/benchmarks/fixtures.py index 462a01abce..0122f86257 100644 --- a/dvc/testing/benchmarks/fixtures.py +++ b/dvc/testing/benchmarks/fixtures.py @@ -90,7 +90,7 @@ def make_dvc_bin( dvc_bin = bench_config.dvc_bin def _dvc_bin(*args): - return check_output([dvc_bin, *args], text=True) # nosec B603 + return check_output([dvc_bin, *args], text=True) # nosec B603 # noqa: S603 _dvc_bin.version = parse_tuple(_dvc_bin("--version")) # type: ignore[attr-defined] return _dvc_bin diff --git a/dvc/testing/fixtures.py b/dvc/testing/fixtures.py index 0624033484..0161cfd653 100644 --- a/dvc/testing/fixtures.py +++ b/dvc/testing/fixtures.py @@ -233,8 +233,8 @@ def docker_services( pytest.skip("disabled for Windows on CI") try: - subprocess.check_output( # nosec B607, B602 - "docker ps", stderr=subprocess.STDOUT, shell=True + subprocess.check_output( # nosec B607, B602, + "docker ps", stderr=subprocess.STDOUT, shell=True # noqa: S602, S607 ) except subprocess.CalledProcessError as err: out = (err.output or b"").decode("utf-8") @@ -242,7 +242,9 @@ def docker_services( try: cmd = "docker-compose version" - subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # nosec + subprocess.check_output( + cmd, stderr=subprocess.STDOUT, shell=True # nosec B602 # noqa: S602 + ) except subprocess.CalledProcessError as err: out = (err.output or b"").decode("utf-8") pytest.skip(f"docker-compose is not installed: {out}") diff --git a/dvc/ui/__init__.py b/dvc/ui/__init__.py index add18faf67..07f64a88a4 100644 --- a/dvc/ui/__init__.py +++ b/dvc/ui/__init__.py @@ -147,7 +147,7 @@ def write_json( # noqa: PLR0913 return self.write(json.text, stderr=stderr) return self.rich_print(json, stderr=stderr, soft_wrap=True) - def rich_print( + def rich_print( # noqa: PLR0913 self, *objects: Any, sep: str = " ", diff --git a/dvc/ui/pager.py b/dvc/ui/pager.py index 03c8cf4499..6aa00de78a 100644 --- a/dvc/ui/pager.py +++ b/dvc/ui/pager.py @@ -59,7 +59,8 @@ def find_pager(): if not pager: pager = os.getenv(PAGER_ENV) if not pager: - if os.system(f"({DEFAULT_PAGER}) 2>{os.devnull}") != 0: # nosec B605 + ret = os.system(f"({DEFAULT_PAGER}) 2>{os.devnull}") # nosec B605 # noqa: S605 + if ret != 0: logger.warning( "Unable to find `less` in the PATH. Check out %s for more info.", format_link("https://man.dvc.org/pipeline/show"), diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 5f939ff434..94c41b8e58 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -319,7 +319,7 @@ def resolve_paths(repo, out, always_local=False): def format_link(link): - return "<{blue}{link}{nc}>".format( + return "<{blue}{link}{nc}>".format( # noqa: UP032 blue=colorama.Fore.CYAN, link=link, nc=colorama.Fore.RESET ) diff --git a/pyproject.toml b/pyproject.toml index 0f4f4c7cea..8cf12ffd93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -268,8 +268,8 @@ ignored-argument-names = "_.*|args|kwargs" [tool.ruff] # external flake8 codes that should be preserved external = ["B301", "C901", "E302", "W601"] -ignore = ["N818", "S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR2004", "PLW2901", "RUF005"] -select = ["F", "E", "W", "C90", "N", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PT", "Q", "RET501", "RET504", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "RUF"] +ignore = ["N818", "S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR2004", "PLW2901", "RUF005", "RUF012"] +select = ["F", "E", "W", "C90", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10", "EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET501", "RET504", "SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "FLY", "RUF"] show-source = true [tool.ruff.flake8-pytest-style] diff --git a/tests/func/api/test_show.py b/tests/func/api/test_show.py index 1e926e6782..f181b4ff5e 100644 --- a/tests/func/api/test_show.py +++ b/tests/func/api/test_show.py @@ -187,7 +187,7 @@ def test_params_show_stages(params_repo): def test_params_show_stage_addressing(tmp_dir, dvc): - for subdir in {"subdir1", "subdir2"}: + for subdir in ("subdir1", "subdir2"): subdir = tmp_dir / subdir subdir.mkdir() with subdir.chdir(): @@ -195,7 +195,7 @@ def test_params_show_stage_addressing(tmp_dir, dvc): dvc.run(name="stage-0", cmd="echo stage-0", params=["foo"]) - for s in {"subdir1", "subdir2"}: + for s in ("subdir1", "subdir2"): dvcyaml = os.path.join(s, "dvc.yaml") assert api.params_show(stages=f"{dvcyaml}:stage-0") == {"foo": 1} diff --git a/tests/func/experiments/executor/test_ssh.py b/tests/func/experiments/executor/test_ssh.py index 79b734128e..7714d19125 100644 --- a/tests/func/experiments/executor/test_ssh.py +++ b/tests/func/experiments/executor/test_ssh.py @@ -119,7 +119,7 @@ def test_reproduce(tmp_dir, scm, dvc, cloud, exp_stage, mocker): rev, fs_factory=partial(_ssh_factory, cloud), ) - assert mock_execute.called_once() + mock_execute.assert_called_once() _name, args, _kwargs = mock_execute.mock_calls[0] assert f"dvc exp exec-run --infofile {infofile}" in args[0] @@ -148,7 +148,7 @@ def test_run_machine(tmp_dir, scm, dvc, cloud, exp_stage, mocker): tmp_dir.gen("params.yaml", "foo: 2") dvc.experiments.run(exp_stage.addressing, machine="foo") - assert mock_repro.called_once() + mock_repro.assert_called_once() _name, _args, kwargs = mock_repro.mock_calls[0] info = kwargs["info"] url = urlparse(info.git_url) diff --git a/tests/func/experiments/test_experiments.py b/tests/func/experiments/test_experiments.py index 3931a0e6ca..65e1cfc056 100644 --- a/tests/func/experiments/test_experiments.py +++ b/tests/func/experiments/test_experiments.py @@ -488,16 +488,6 @@ def test_run_celery(tmp_dir, scm, dvc, exp_stage, mocker): assert expected == metrics -def test_run_metrics(tmp_dir, scm, dvc, exp_stage, mocker): - from dvc.cli import main - - mocker.patch.object(dvc.experiments, "run", return_value={"abc123": "abc123"}) - show_mock = mocker.patch.object(dvc.metrics, "show", return_value={}) - - main(["exp", "run", "-m"]) - assert show_mock.called_once() - - def test_checkout_targets_deps(tmp_dir, scm, dvc, exp_stage): from dvc.utils.fs import remove diff --git a/tests/func/experiments/test_show.py b/tests/func/experiments/test_show.py index 04ca5d3e92..4a3ffbf34c 100644 --- a/tests/func/experiments/test_show.py +++ b/tests/func/experiments/test_show.py @@ -452,7 +452,7 @@ def _get_rev_isotimestamp(rev): assert "metrics.yaml:foo,params.yaml:foo,copy.py" in cap.out assert f",workspace,baseline,,,3,3,{data_hash}" in cap.out assert ( - ",master,baseline,{},,1,1,{}".format( + ",master,baseline,{},,1,1,{}".format( # noqa: UP032 _get_rev_isotimestamp(baseline_rev), data_hash ) in cap.out @@ -682,7 +682,7 @@ def _get_rev_isotimestamp(rev): assert f",master,baseline,{_get_rev_isotimestamp(scores_rev)},,1,,1" in cap.out assert ( - ",{},baseline,{},,,1,1".format( + ",{},baseline,{},,,1,1".format( # noqa: UP032 metrics_rev[:7], _get_rev_isotimestamp(metrics_rev) ) in cap.out diff --git a/tests/func/repro/test_repro.py b/tests/func/repro/test_repro.py index 64047dc786..ee4563a3b6 100644 --- a/tests/func/repro/test_repro.py +++ b/tests/func/repro/test_repro.py @@ -848,9 +848,7 @@ def test_repro_dry_no_exec(tmp_dir, dvc): idir, "-o", odir, - 'python -c \'import shutil; shutil.copytree("{}", "{}")\''.format( - idir, odir - ), + f'python -c \'import shutil; shutil.copytree("{idir}", "{odir}")\'', ] ) assert ret == 0 diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index cdd778f402..3c4f79df4e 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -377,7 +377,7 @@ def test_repo_with_removed_plots(tmp_dir, capsys, repo_with_plots): remove("confusion.json") remove("image.png") - for s in {"show", "diff"}: + for s in ("show", "diff"): _, json_result, split_json_result = call(capsys, subcommand=s) errors = [ { diff --git a/tests/unit/repo/experiments/queue/test_celery.py b/tests/unit/repo/experiments/queue/test_celery.py index 42c0ad4908..2a137d5d42 100644 --- a/tests/unit/repo/experiments/queue/test_celery.py +++ b/tests/unit/repo/experiments/queue/test_celery.py @@ -71,7 +71,7 @@ def test_post_run_after_kill(test_queue): except ProcessLookupError: time.sleep(0.1) if time.time() > timeout: - raise TimeoutError() + raise TimeoutError assert result_foo.get(timeout=10) == "foo" @@ -132,9 +132,11 @@ def kill_function(rev): ) with pytest.raises(CannotKillTasksError, match="Task 'foobar' is initializing,"): test_queue.kill(["bar", "foo", "foobar"], force=force) - assert kill_mock.called_once_with(mock_entry_foo.stash_rev) - assert kill_mock.called_once_with(mock_entry_bar.stash_rev) - assert kill_mock.called_once_with(mock_entry_foobar.stash_rev) + assert kill_mock.call_args_list == [ + mocker.call(mock_entry_bar.stash_rev), + mocker.call(mock_entry_foo.stash_rev), + mocker.call(mock_entry_foobar.stash_rev), + ] mark_mocker.assert_called_once_with("bar", None) @@ -157,7 +159,7 @@ def test_celery_queue_kill_invalid(test_queue, mocker, force): with pytest.raises(UnresolvedExpNamesError): test_queue.kill(["bar", "foo", "foobar"], force=force) - assert kill_mock.called_once_with( + kill_mock.assert_called_once_with( {mock_entry_foo: "foo", mock_entry_bar: "bar"}, force ) diff --git a/tests/unit/repo/experiments/test_utils.py b/tests/unit/repo/experiments/test_utils.py index 7b2c6c1826..0cc802c6e9 100644 --- a/tests/unit/repo/experiments/test_utils.py +++ b/tests/unit/repo/experiments/test_utils.py @@ -8,7 +8,7 @@ def commit_exp_ref(tmp_dir, scm, file="foo", contents="foo", name="foo"): tmp_dir.scm_gen(file, contents, commit="init") rev = scm.get_rev() - ref = "/".join([EXPS_NAMESPACE, "ab", "c123", name]) + ref = f"{EXPS_NAMESPACE}/ab/c123/{name}" scm.gitpython.set_ref(ref, rev) return ref, rev diff --git a/tests/unit/stage/test_cache.py b/tests/unit/stage/test_cache.py index bd6d930424..ae00680cd5 100644 --- a/tests/unit/stage/test_cache.py +++ b/tests/unit/stage/test_cache.py @@ -212,7 +212,7 @@ def test_unhashable(tmp_dir, dvc, mocker, kwargs): stage = create_stage(Stage, path="stage.dvc", repo=dvc, **kwargs) get_stage_hash = mocker.patch("dvc.stage.cache._get_stage_hash") assert cache.save(stage) is None - assert get_stage_hash.not_called + get_stage_hash.assert_not_called() with pytest.raises(RunCacheNotFoundError): cache.restore(stage) - assert get_stage_hash.not_called + get_stage_hash.assert_not_called() diff --git a/tests/unit/stage/test_stage.py b/tests/unit/stage/test_stage.py index 5468461aec..60cad2ae90 100644 --- a/tests/unit/stage/test_stage.py +++ b/tests/unit/stage/test_stage.py @@ -69,7 +69,7 @@ def test_stage_update(dvc, mocker): is_repo_import.return_value = True with dvc.lock: stage.update() - assert reproduce.called_once_with() + reproduce.assert_called_once_with(no_download=None, jobs=None) is_repo_import.return_value = False with pytest.raises(StageUpdateError): @@ -92,8 +92,8 @@ def test_stage_run_ignore_sigint(dvc, mocker): dvc.run(cmd="path", name="train") - assert popen.called_once() - assert communicate.called_once_with() + popen.assert_called_once() + communicate.assert_called_once_with() signal_mock.assert_any_call(signal.SIGINT, signal.SIG_IGN) assert signal.getsignal(signal.SIGINT) == signal.default_int_handler