From b8d738220dfeb90c678f7b8b93a581e195707ae8 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Tue, 10 May 2022 11:16:16 +0530 Subject: [PATCH] Revert other tests and test only glob exception. --- dvc/exceptions.py | 6 ------ dvc/utils/__init__.py | 5 +++-- tests/func/test_add.py | 6 ------ tests/func/test_data_cloud.py | 12 ------------ tests/func/test_utils.py | 12 ++++++++++++ 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 26afde585..127d46362 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -349,9 +349,3 @@ class CircularImportError(DvcException): class PrettyDvcException(DvcException): def __pretty_exc__(self, **kwargs): """Print prettier exception message.""" - - -class GlobDoesNotMatchError(DvcException): - def __init__(self, glob): - msg = f"Glob {glob} has no matches." - super().__init__(msg) diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index c0e6ead55..8e1b61bdb 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -476,7 +476,7 @@ def is_exec(mode): def glob_targets(targets, glob=True, recursive=True): - from dvc.exceptions import GlobDoesNotMatchError + from ..exceptions import DvcException if not glob: return targets @@ -490,7 +490,8 @@ def glob_targets(targets, glob=True, recursive=True): ] if not results: - raise GlobDoesNotMatchError(targets) + msg = f"Glob {targets} has no matches." + raise DvcException(msg) return results diff --git a/tests/func/test_add.py b/tests/func/test_add.py index d9f0275e2..dcd2bed64 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -16,7 +16,6 @@ from dvc.data.db import ODBManager from dvc.dvcfile import DVC_FILE_SUFFIX from dvc.exceptions import ( DvcException, - GlobDoesNotMatchError, InvalidArgumentError, OutputDuplicationError, OverlappingOutputPathsError, @@ -293,11 +292,6 @@ def test_add_filtered_files_in_dir( assert stage.outs[0].def_path in expected_def_paths -def test_add_glob_no_result_exception(dvc): - with pytest.raises(GlobDoesNotMatchError): - dvc.add(["invalid*"], glob=True) - - class TestAddExternal(TestAdd): @pytest.fixture def hash_name(self): diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py index 42657cf60..eea0e549b 100644 --- a/tests/func/test_data_cloud.py +++ b/tests/func/test_data_cloud.py @@ -8,7 +8,6 @@ from flaky.flaky_decorator import flaky import dvc as dvc_module from dvc.cli import main from dvc.data.db.local import LocalObjectDB -from dvc.exceptions import GlobDoesNotMatchError from dvc.external_repo import clean_repos from dvc.objects.db import ObjectDB from dvc.stage.exceptions import StageNotFound @@ -571,14 +570,3 @@ def test_target_remote(tmp_dir, dvc, make_remote): "6b18131dc289fd37006705affe961ef8.dir", "b8a9f715dbb64fd5c56e7783c6820a61", } - - -def test_push_pull_glob_no_match( - tmp_dir, - dvc, -): - with pytest.raises(GlobDoesNotMatchError): - dvc.push(targets="b*", glob=True) - - with pytest.raises(GlobDoesNotMatchError): - dvc.pull(targets="b*", glob=True) diff --git a/tests/func/test_utils.py b/tests/func/test_utils.py index 026357afd..7910f4fba 100644 --- a/tests/func/test_utils.py +++ b/tests/func/test_utils.py @@ -1,4 +1,9 @@ +import re + +import pytest + from dvc import utils +from dvc.exceptions import DvcException from dvc.fs.local import LocalFileSystem @@ -42,3 +47,10 @@ def test_boxify(): ) assert expected == utils.boxify("message") + + +def test_glob_no_match(): + with pytest.raises( + DvcException, match=re.escape("Glob ['invalid*'] has no matches.") + ): + utils.glob_targets(["invalid*"], glob=True)