From 813c8ddded61e668efda2dd32a41909f3ea0ed83 Mon Sep 17 00:00:00 2001 From: tanvimoharir Date: Wed, 8 Sep 2021 14:09:35 +0530 Subject: [PATCH] Adding tests --- tests/test_black.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_black.py b/tests/test_black.py index 998ecfcbdeb..21cd96a3412 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -2198,6 +2198,26 @@ def test_code_option_parent_config(self) -> None: call_args[0].lower() == str(pyproject_path).lower() ), "Incorrect config loaded." + def test_code_with_unexpected_eof_error(self) -> None: + """ + Test that Unexpected EOF error is raised with invalid code + """ + code = "print(" + args = ["--check", "--code", code] + error_msg = "error: cannot format : Cannot parse: 2:0: Unexpected EOF\n" + result = CliRunner().invoke(black.main, args) + self.compare_results(result, error_msg, 123) + + def test_invalid_input_parsing_error(self) -> None: + """ + Test with invalid code which throws parsing error + """ + code = "print([)" + args = ["--check", "--code", code] + error_msg = f"error: cannot format : Cannot parse: 1:7: {code}\n" + result = CliRunner().invoke(black.main, args) + self.compare_results(result, error_msg, 123) + with open(black.__file__, "r", encoding="utf-8") as _bf: black_source_lines = _bf.readlines()