Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvimoharir committed Sep 8, 2021
1 parent b5a3a7b commit 813c8dd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_black.py
Expand Up @@ -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 <string>: 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 <string>: 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()
Expand Down

0 comments on commit 813c8dd

Please sign in to comment.