Skip to content

Commit

Permalink
Port logging-related test fixes from #67
Browse files Browse the repository at this point in the history
  • Loading branch information
florisla committed Apr 17, 2019
1 parent 7fbc722 commit f55823b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,27 @@ def test_dirty_work_dir(tmpdir, vcs):
tmpdir.join("dirty").write("i'm dirty")

check_call([vcs, "add", "dirty"])
vcs_name = "Mercurial" if vcs == "hg" else "Git"
vcs_output = "b'A dirty'" if vcs == "hg" else "b'A dirty'"

with pytest.raises(WorkingDirectoryIsDirtyException):
with mock.patch("bumpversion.cli.logger") as parser_logger:
with mock.patch("bumpversion.vcs.logger") as vcs_logger:
main(['patch', '--current-version', '1', '--new-version', '2', 'file7'])
with LogCapture() as log_capture:
main(['patch', '--current-version', '1', '--new-version', '2', 'file7'])

actual_log = "\n".join(
_mock_calls_to_string(parser_logger) +
_mock_calls_to_string(vcs_logger)
log_capture.check_present(
(
'bumpversion.cli',
'WARNING',
"{} working directory is not clean:\n"
"{}\n"
"\n"
"Use --allow-dirty to override this if you know what you're doing.".format(
vcs_name,
vcs_output
)
)
)

assert 'working directory is not clean' in actual_log
assert "Use --allow-dirty to override this if you know what you're doing." in actual_log


def test_force_dirty_work_dir(tmpdir, vcs):
tmpdir.chdir()
Expand Down Expand Up @@ -1240,22 +1247,15 @@ def test_listing(tmpdir, vcs):
check_call([vcs, "add", "please_list_me.txt"])
check_call([vcs, "commit", "-m", "initial commit"])

with mock.patch("bumpversion.cli.logger_list") as logger:
with LogCapture() as log_capture:
main(['--list', 'patch'])

expected_log = dedent("""
info|current_version=0.5.5|
info|commit=False|
info|tag=False|
info|new_version=0.5.6|
""").strip()

if vcs == "hg":
expected_log = expected_log.replace("Git", "Mercurial")

actual_log = "\n".join(_mock_calls_to_string(logger)[3:])

assert actual_log == expected_log
log_capture.check(
('bumpversion.list', 'INFO', 'current_version=0.5.5'),
('bumpversion.list', 'INFO', 'commit=False'),
('bumpversion.list', 'INFO', 'tag=False'),
('bumpversion.list', 'INFO', 'new_version=0.5.6'),
)


def test_no_list_no_stdout(tmpdir, vcs):
Expand Down

0 comments on commit f55823b

Please sign in to comment.