Skip to content

Commit

Permalink
Suppress tests output
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpetrov committed Feb 19, 2019
1 parent c1cdf77 commit fecaa5a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
cmd = (
"nosetests -v --processes=-1 --process-timeout=500 --cover-inclusive "
"--cover-erase --cover-package=dvc --with-coverage --with-flaky "
"--logging-clear-handlers "
"{scope} ".format(scope=scope)
)
check_call(cmd, shell=True)
20 changes: 11 additions & 9 deletions tests/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from dvc.state import State
from mock import patch
from tests.utils.logger import MockLoggerHandlers

import dvc.logger as logger
from dvc.utils.compat import str
Expand Down Expand Up @@ -637,15 +638,16 @@ def _test(self):
with open(stage_file_path, "w") as stage_file:
yaml.dump(content, stage_file)

logger.logger.handlers[0].stream = StringIO()
self.main(["status", "-c"])
self.assertIn(
"Warning: Output 'bar'(Stage: 'bar.dvc') is "
"missing version info. Cache for it will not be "
"collected. Use dvc repro to get your pipeline up to "
"date.",
logger.logger.handlers[0].stream.getvalue(),
)
with MockLoggerHandlers(logger.logger):
logger.logger.handlers[0].stream = StringIO()
self.main(["status", "-c"])
self.assertIn(
"Warning: Output 'bar'(Stage: 'bar.dvc') is "
"missing version info. Cache for it will not be "
"collected. Use dvc repro to get your pipeline up to "
"date.",
logger.logger.handlers[0].stream.getvalue(),
)

def test(self):
self.color_patch.start()
Expand Down
33 changes: 18 additions & 15 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from mock import patch, mock_open, call
from tests.basic_env import TestDvc
from tests.utils.httpd import StaticFileServer
from tests.utils.logger import MockLoggerHandlers


from dvc.utils.compat import StringIO

Expand Down Expand Up @@ -53,21 +55,22 @@ def test(self):

@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(),
)
with MockLoggerHandlers(logger.logger):
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(),
)


class TestInterruptedDownload(TestDvc):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class TestLogger(TestCase):
color_patch = patch.object(logger, "colorize", new=lambda x, color="": x)

def setUp(self):
logger.logger.handlers = [
logger.logging.StreamHandler(),
logger.logging.StreamHandler(),
]
logger.logger.handlers[0].stream = StringIO()
logger.logger.handlers[1].stream = StringIO()
logger.set_default_level()
Expand Down
20 changes: 20 additions & 0 deletions tests/utils/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging


class MockLoggerHandlers(object):
def __init__(self, l, num=2):
self._logger = l
self._handlers = l.handlers
self._num = num

def __enter__(self):
self._logger.handlers = [
logging.FileHandler("tmp{}.log".format(i))
for i in range(self._num)
]
return self

def __exit__(self, exc_type=None, exc_val=None, exc_tb=None):
for h in self._logger.handlers:
h.close()
self._logger.handlers = self._handlers

0 comments on commit fecaa5a

Please sign in to comment.