Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change error to info #151

Merged
merged 3 commits into from
Jan 5, 2019
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
2 changes: 1 addition & 1 deletion moban/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def get_data(self, file_name):
# If data file doesn't exist:
# 1. Alert the user of their (potential) mistake
# 2. Attempt to use environment vars as data
reporter.report_error_message(str(exception))
reporter.report_info_message(str(exception))
reporter.report_using_env_vars()
data = os.environ
return data
Expand Down
12 changes: 10 additions & 2 deletions moban/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def report_error_message(message):
print(crayons.white("Error: ", bold=True) + crayons.red(message))


def report_warning_message(message):
print(crayons.white("Warning: ", bold=True) + crayons.yellow(message))


def report_info_message(message):
print(crayons.white("Info: ") + crayons.green(message))


def report_up_to_date():
print(crayons.green(MESSAGE_UP_TO_DATE, bold=True))

Expand Down Expand Up @@ -92,12 +100,12 @@ def report_git_clone(repo):


def report_using_env_vars():
print(crayons.yellow(MESSAGE_USING_ENV_VARS, bold=True))
report_warning_message(MESSAGE_USING_ENV_VARS)


def report_template_not_in_moban_file(template):
message = MESSAGE_TEMPLATE_NOT_IN_MOBAN_FILE.format(template)
print(crayons.yellow(message, bold=True))
report_warning_message(message)


def _format_single(message, count):
Expand Down
14 changes: 2 additions & 12 deletions tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ def test_single_command_with_a_few_options(self, fake_template_doer):

main()
call_args = list(fake_template_doer.call_args[0][0])
eq_(
call_args,
[
("abc.jj2", "data.yaml", "xyz.output"),
],
)
eq_(call_args, [("abc.jj2", "data.yaml", "xyz.output")])

@patch("moban.plugins.BaseEngine.render_to_files")
def test_single_command_with_options(self, fake_template_doer):
Expand All @@ -166,12 +161,7 @@ def test_single_command_with_options(self, fake_template_doer):

main()
call_args = list(fake_template_doer.call_args[0][0])
eq_(
call_args,
[
("abc.jj2", "new.yml", "xyz.output"),
],
)
eq_(call_args, [("abc.jj2", "new.yml", "xyz.output")])

@raises(Exception)
def test_single_command_without_output_option(self, fake_template_doer):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def test_no_third_party_engine(
with patch.object(sys, "argv", ["moban"]):
main()

@raises(SystemExit)
@patch("os.path.exists")
@patch("moban.main.handle_moban_file")
@patch("moban.reporter.report_error_message")
def test_double_underscore_main(
self, fake_reporter, fake_moban_file, fake_file
):
fake_file.return_value = True
fake_moban_file.side_effect = exceptions.DirectoryNotFound
from moban.__main__ import main

with patch.object(sys, "argv", ["moban"]):
main()


class TestExitCodes:
def setUp(self):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def test_error_message():
eq_(fake_stdout.getvalue(), "Error: something wrong\n")


def test_info_message():
patcher = patch("sys.stdout", new_callable=StringIO)
fake_stdout = patcher.start()
reporter.report_info_message("for your information")
patcher.stop()
eq_(fake_stdout.getvalue(), "Info: for your information\n")


def test_warning_message():
patcher = patch("sys.stdout", new_callable=StringIO)
fake_stdout = patcher.start()
reporter.report_warning_message("Maybe you wanna know")
patcher.stop()
eq_(fake_stdout.getvalue(), "Warning: Maybe you wanna know\n")


def test_report_templating():
patcher = patch("sys.stdout", new_callable=StringIO)
fake_stdout = patcher.start()
Expand All @@ -56,3 +72,14 @@ def test_format_single():
message = "1 files"
ret = reporter._format_single(message, 1)
eq_(ret, "1 file")


def test_report_template_not_in_moban_file():
patcher = patch("sys.stdout", new_callable=StringIO)
fake_stdout = patcher.start()
reporter.report_template_not_in_moban_file("test.jj2")
patcher.stop()
eq_(
fake_stdout.getvalue(),
"Warning: test.jj2 is not defined in your moban file!\n",
)
7 changes: 7 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from moban.utils import (
mkdir_p,
open_json,
get_repo_name,
write_file_out,
file_permissions,
Expand Down Expand Up @@ -169,3 +170,9 @@ def test_get_repo_name():
actual = [get_repo_name(repo) for repo in repos]
expected = ["repo", "repo"]
eq_(expected, actual)


def test_open_json():
content = open_json(os.path.join("tests", "fixtures"), "child.json")
expected = {"key": "hello world", "pass": "ox"}
eq_(expected, content)