Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/func/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def test_ls_repo_with_color(tmp_dir, dvc, scm, mocker, monkeypatch, caplog):
cmd = cli_args.func(cli_args)

caplog.clear()
with mocker.patch("sys.stdout.isatty", return_value=True):
with caplog.at_level(logging.INFO, logger="dvc.command.ls"):
assert cmd.run() == 0
mocker.patch("sys.stdout.isatty", return_value=True)
with caplog.at_level(logging.INFO, logger="dvc.command.ls"):
assert cmd.run() == 0

assert caplog.records[-1].msg == "\n".join(
[
Expand Down
20 changes: 9 additions & 11 deletions tests/unit/command/test_imp_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ def test_failed_import_url(mocker, caplog):
assert cli_args.func == CmdImportUrl

cmd = cli_args.func(cli_args)
with mocker.patch.object(
cmd.repo, "imp_url", side_effect=DvcException("error")
):
with caplog.at_level(logging.ERROR, logger="dvc"):
assert cmd.run() == 1
expected_error = (
"failed to import http://somesite.com/file_name. "
"You could also try downloading it manually, and "
"adding it with `dvc add`."
)
assert expected_error in caplog.text
mocker.patch.object(cmd.repo, "imp_url", side_effect=DvcException("error"))
with caplog.at_level(logging.ERROR, logger="dvc"):
assert cmd.run() == 1
expected_error = (
"failed to import http://somesite.com/file_name. "
"You could also try downloading it manually, and "
"adding it with `dvc add`."
)
assert expected_error in caplog.text
58 changes: 29 additions & 29 deletions tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

@pytest.fixture()
def dt(mocker):
with mocker.patch(
mocker.patch(
"time.time", return_value=time.mktime(datetime(2020, 2, 2).timetuple())
):
yield "2020-02-02 00:00:00,000"
)
yield "2020-02-02 00:00:00,000"


class TestColorFormatter:
Expand Down Expand Up @@ -195,32 +195,32 @@ def test_nested_exceptions(self, caplog, dt):
def test_progress_awareness(self, mocker, capsys, caplog):
from dvc.progress import Tqdm

with mocker.patch("sys.stdout.isatty", return_value=True):
with Tqdm(total=100, desc="progress") as pbar:
pbar.update()

# logging an invisible message should not break
# the progress bar output
with caplog.at_level(logging.INFO, logger="dvc"):
debug_record = logging.LogRecord(
name="dvc",
level=logging.DEBUG,
pathname=__name__,
lineno=1,
msg="debug",
args=(),
exc_info=None,
)

formatter.format(debug_record)
captured = capsys.readouterr()
assert captured.out == ""

# when the message is actually visible
with caplog.at_level(logging.INFO, logger="dvc"):
logger.info("some info")
captured = capsys.readouterr()
assert captured.out == ""
mocker.patch("sys.stdout.isatty", return_value=True)
with Tqdm(total=100, desc="progress") as pbar:
pbar.update()

# logging an invisible message should not break
# the progress bar output
with caplog.at_level(logging.INFO, logger="dvc"):
debug_record = logging.LogRecord(
name="dvc",
level=logging.DEBUG,
pathname=__name__,
lineno=1,
msg="debug",
args=(),
exc_info=None,
)

formatter.format(debug_record)
captured = capsys.readouterr()
assert captured.out == ""

# when the message is actually visible
with caplog.at_level(logging.INFO, logger="dvc"):
logger.info("some info")
captured = capsys.readouterr()
assert captured.out == ""


def test_handlers():
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def test_relpath():
],
)
def test_resolve_output(inp, out, is_dir, expected, mocker):
with mocker.patch("os.path.isdir", return_value=is_dir):
result = resolve_output(inp, out)

mocker.patch("os.path.isdir", return_value=is_dir)
result = resolve_output(inp, out)
assert result == expected