mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
imp: refactor import message (#1501)
* imp: refactor import message * import: reword error message Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
dc23feb9ec
commit
52ffae81c4
+3
-1
@@ -17,6 +17,8 @@ class CmdImport(CmdBase):
|
||||
|
||||
self.project.imp(self.args.url, out)
|
||||
except DvcException:
|
||||
logger.error('failed to import {}'.format(self.args.url))
|
||||
logger.error('failed to import {}. You could also try downloading '
|
||||
'it manually and adding it with `dvc add` command.'
|
||||
.format(self.args.url))
|
||||
return 1
|
||||
return 0
|
||||
|
||||
+33
-1
@@ -1,10 +1,17 @@
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from dvc import logger
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.main import main
|
||||
|
||||
from mock import patch
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
|
||||
class TestCmdImport(TestDvc):
|
||||
def test(self):
|
||||
@@ -33,3 +40,28 @@ class TestDefaultOutput(TestDvc):
|
||||
self.assertEqual(ret, 0)
|
||||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename).read(), 'content')
|
||||
|
||||
|
||||
class TestFailedImportMessage(TestDvc):
|
||||
color_patch = patch.object(logger, 'colorize', new=lambda x, color='': x)
|
||||
|
||||
def test(self):
|
||||
self.color_patch.start()
|
||||
self._test()
|
||||
self.color_patch.stop()
|
||||
|
||||
@patch('dvc.command.imp.urlparse')
|
||||
def _test(self, imp_urlparse_patch):
|
||||
logger.logger.handlers[1].stream = StringIO()
|
||||
page_address = 'http://somesite.com/file_name'
|
||||
|
||||
def dvc_exception(*args, **kwargs):
|
||||
raise DvcException('message')
|
||||
|
||||
imp_urlparse_patch.side_effect = dvc_exception
|
||||
main(['import', page_address])
|
||||
self.assertIn('Error: failed to import '
|
||||
'http://somesite.com/file_name. You could also try '
|
||||
'downloading it manually and adding it with `dvc add` '
|
||||
'command.',
|
||||
logger.logger.handlers[1].stream.getvalue())
|
||||
|
||||
Reference in New Issue
Block a user