mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Merge pull request #551 from efiop/master
increase test coverage to 90%
This commit is contained in:
@@ -3,7 +3,6 @@ import os
|
||||
import dvc.cloud.base as cloud
|
||||
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
|
||||
class CmdDataBase(CmdBase):
|
||||
@@ -20,11 +19,12 @@ class CmdDataBase(CmdBase):
|
||||
ret = 1
|
||||
return ret
|
||||
|
||||
|
||||
class CmdDataPull(CmdDataBase):
|
||||
def do_run(self, target=None):
|
||||
try:
|
||||
self.project.pull(target=target, jobs=self.args.jobs)
|
||||
except DvcException as exc:
|
||||
except Exception as exc:
|
||||
self.project.logger.error('Failed to pull data from the cloud', exc)
|
||||
return 1
|
||||
return 0
|
||||
@@ -34,7 +34,7 @@ class CmdDataPush(CmdDataBase):
|
||||
def do_run(self, target=None):
|
||||
try:
|
||||
self.project.push(target=target, jobs=self.args.jobs)
|
||||
except DvcException as exc:
|
||||
except Exception as exc:
|
||||
self.project.logger.error('Failed to push data to the cloud', exc)
|
||||
return 1
|
||||
return 0
|
||||
@@ -44,7 +44,7 @@ class CmdDataFetch(CmdDataBase):
|
||||
def do_run(self, target=None):
|
||||
try:
|
||||
self.project.fetch(target=target, jobs=self.args.jobs)
|
||||
except DvcException as exc:
|
||||
except Exception as exc:
|
||||
self.project.logger.error('Failed to fetch data from the cloud', exc)
|
||||
return 1
|
||||
return 0
|
||||
@@ -72,7 +72,7 @@ class CmdDataStatus(CmdDataBase):
|
||||
try:
|
||||
status = self.project.status(target=target, jobs=self.args.jobs)
|
||||
self._show(status)
|
||||
except DvcException as exc:
|
||||
except Exception as exc:
|
||||
self.project.logger.error('Failed to obtain data status', exc)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
|
||||
from dvc.cache import Cache
|
||||
from dvc.system import System
|
||||
from dvc.output import Output
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
@@ -42,3 +43,18 @@ class TestCache(TestDvc):
|
||||
|
||||
self.assertEqual(len(cache), 2)
|
||||
self.assertEqual(cache, expected)
|
||||
|
||||
|
||||
class TestCacheLoadBadDirCache(TestDvc):
|
||||
def _do_test(self, ret):
|
||||
self.assertTrue(isinstance(ret, list))
|
||||
self.assertEqual(len(ret), 0)
|
||||
|
||||
def test(self):
|
||||
fname = 'not-json'
|
||||
self.create(fname, '<clearly>not,json')
|
||||
self._do_test(Output.load_dir_cache(fname))
|
||||
|
||||
fname = 'not-list'
|
||||
self.create(fname, '{"a": "b"}')
|
||||
self._do_test(Output.load_dir_cache(fname))
|
||||
|
||||
@@ -217,3 +217,16 @@ class TestDataCloudLocalCli(TestDvc):
|
||||
self.assertTrue(os.path.isfile(cache_dir))
|
||||
|
||||
self.main(['status'])
|
||||
|
||||
|
||||
class TestDataCloudErrorCLI(TestDvc):
|
||||
def main_fail(self, args):
|
||||
ret = main(args)
|
||||
self.assertNotEqual(ret, 0)
|
||||
|
||||
def test_error(self):
|
||||
f = 'non-existing-file'
|
||||
self.main_fail(['status', f])
|
||||
self.main_fail(['push', f])
|
||||
self.main_fail(['pull', f])
|
||||
self.main_fail(['fetch', f])
|
||||
|
||||
Reference in New Issue
Block a user