def test_remove_binary_sucess(caplog): temp_dir = tempfile.mkdtemp() fake_binary_path = os.path.join(temp_dir, "cmk") helpers.execute("touch", [fake_binary_path]) uninstall.remove_binary(temp_dir) with pytest.raises(Exception): helpers.execute("stat", [fake_binary_path]) caplog_tuple = caplog.record_tuples exp_log = "cmk binary from \"{}\" removed successfully.".format(temp_dir) assert caplog_tuple[-1][2] == exp_log
def test_remove_binary_failure(caplog): temp_dir = tempfile.mkdtemp() fake_binary_path = os.path.join(temp_dir, "cmk_wrong_name") helpers.execute("touch", [fake_binary_path]) uninstall.remove_binary(temp_dir) caplog_tuple = caplog.record_tuples exp_log = "Could not found cmk binary in \"{}\"."\ .format(temp_dir) exp_log2 = "Wrong path or file has already been removed." assert caplog_tuple[-2][2] == exp_log assert caplog_tuple[-1][2] == exp_log2