mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
output/deps: raise proper exception when file/dir doesn't exist
From discussion on discord https://discordapp.com/channels/485586884165107732/485596304961962003/548083580052701205 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+5
-1
@@ -5,6 +5,7 @@ from schema import Or, Optional
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.utils.compat import str
|
||||
from dvc.remote.base import RemoteBase
|
||||
|
||||
|
||||
class OutputDoesNotExistError(DvcException):
|
||||
@@ -28,7 +29,7 @@ class OutputAlreadyTrackedError(DvcException):
|
||||
class OutputBase(object):
|
||||
IS_DEPENDENCY = False
|
||||
|
||||
REMOTE = None
|
||||
REMOTE = RemoteBase
|
||||
|
||||
PARAM_PATH = "path"
|
||||
PARAM_CACHE = "cache"
|
||||
@@ -152,6 +153,9 @@ class OutputBase(object):
|
||||
return bool(self.status())
|
||||
|
||||
def save(self):
|
||||
if not self.exists:
|
||||
raise self.DoesNotExistError(self)
|
||||
|
||||
self.info = self.remote.save_info(self.path_info)
|
||||
|
||||
def commit(self):
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.dependency.gs import DependencyGS
|
||||
|
||||
from tests.unit.dependency.local import TestDependencyLOCAL
|
||||
|
||||
|
||||
class TestDependencyGS(TestDependencyLOCAL):
|
||||
def _get_cls(self):
|
||||
return DependencyGS
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.dependency.hdfs import DependencyHDFS
|
||||
|
||||
from tests.unit.dependency.local import TestDependencyLOCAL
|
||||
|
||||
|
||||
class TestDependencyHDFS(TestDependencyLOCAL):
|
||||
def _get_cls(self):
|
||||
return DependencyHDFS
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.dependency.http import DependencyHTTP
|
||||
|
||||
from tests.unit.dependency.local import TestDependencyLOCAL
|
||||
|
||||
|
||||
class TestDependencyHTTP(TestDependencyLOCAL):
|
||||
def _get_cls(self):
|
||||
return DependencyHTTP
|
||||
@@ -0,0 +1,21 @@
|
||||
import mock
|
||||
|
||||
from dvc.stage import Stage
|
||||
from dvc.dependency import DependencyLOCAL
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestDependencyLOCAL(TestDvc):
|
||||
def _get_cls(self):
|
||||
return DependencyLOCAL
|
||||
|
||||
def _get_dependency(self):
|
||||
stage = Stage(self.dvc)
|
||||
return self._get_cls()(stage, "path")
|
||||
|
||||
def test_save_missing(self):
|
||||
d = self._get_dependency()
|
||||
with mock.patch.object(d.remote, "exists", return_value=False):
|
||||
with self.assertRaises(d.DoesNotExistError):
|
||||
d.save()
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.dependency.s3 import DependencyS3
|
||||
|
||||
from tests.unit.dependency.local import TestDependencyLOCAL
|
||||
|
||||
|
||||
class TestDependencyS3(TestDependencyLOCAL):
|
||||
def _get_cls(self):
|
||||
return DependencyS3
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.dependency.ssh import DependencySSH
|
||||
|
||||
from tests.unit.dependency.local import TestDependencyLOCAL
|
||||
|
||||
|
||||
class TestDependencySSH(TestDependencyLOCAL):
|
||||
def _get_cls(self):
|
||||
return DependencySSH
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.output.gs import OutputGS
|
||||
|
||||
from tests.unit.output.local import TestOutputLOCAL
|
||||
|
||||
|
||||
class TestOutputGS(TestOutputLOCAL):
|
||||
def _get_cls(self):
|
||||
return OutputGS
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.output.hdfs import OutputHDFS
|
||||
|
||||
from tests.unit.output.local import TestOutputLOCAL
|
||||
|
||||
|
||||
class TestOutputHDFS(TestOutputLOCAL):
|
||||
def _get_cls(self):
|
||||
return OutputHDFS
|
||||
@@ -0,0 +1,21 @@
|
||||
import mock
|
||||
|
||||
from dvc.stage import Stage
|
||||
from dvc.output import OutputLOCAL
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
|
||||
class TestOutputLOCAL(TestDvc):
|
||||
def _get_cls(self):
|
||||
return OutputLOCAL
|
||||
|
||||
def _get_output(self):
|
||||
stage = Stage(self.dvc)
|
||||
return self._get_cls()(stage, "path", cache=False)
|
||||
|
||||
def test_save_missing(self):
|
||||
o = self._get_output()
|
||||
with mock.patch.object(o.remote, "exists", return_value=False):
|
||||
with self.assertRaises(o.DoesNotExistError):
|
||||
o.save()
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.output.s3 import OutputS3
|
||||
|
||||
from tests.unit.output.local import TestOutputLOCAL
|
||||
|
||||
|
||||
class TestOutputS3(TestOutputLOCAL):
|
||||
def _get_cls(self):
|
||||
return OutputS3
|
||||
@@ -0,0 +1,8 @@
|
||||
from dvc.output.ssh import OutputSSH
|
||||
|
||||
from tests.unit.output.local import TestOutputLOCAL
|
||||
|
||||
|
||||
class TestOutputSSH(TestOutputLOCAL):
|
||||
def _get_cls(self):
|
||||
return OutputSSH
|
||||
Reference in New Issue
Block a user