Skip to content

Commit

Permalink
[native] Make IntoPy conversion fallible (#639)
Browse files Browse the repository at this point in the history
* Make IntoPy fallible
* Simplify test case so it works on 3.6
  • Loading branch information
zsol authored Feb 7, 2022
1 parent f0cca36 commit fb56fa6
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 237 deletions.
9 changes: 9 additions & 0 deletions libcst/_parser/tests/test_parse_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from textwrap import dedent
from typing import Callable
from unittest.mock import patch

import libcst as cst
from libcst._nodes.base import CSTValidationError
from libcst._parser.entrypoints import is_native
from libcst.testing.utils import data_provider, UnitTest

Expand Down Expand Up @@ -172,3 +174,10 @@ def test_parser_syntax_error_str(
parse_fn()
if not is_native():
self.assertEqual(str(cm.exception), expected)

def test_native_fallible_into_py(self) -> None:
with patch("libcst._nodes.expression.Name._validate") as await_validate:
await_validate.side_effect = CSTValidationError("validate is broken")
with self.assertRaises(Exception) as e:
cst.parse_module("foo")
self.assertIsInstance(e.exception, (SyntaxError, cst.ParserSyntaxError))
Loading

0 comments on commit fb56fa6

Please sign in to comment.