Beispiel #1
0
 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))
Beispiel #2
0
 def _validate(self) -> None:
     if SIMPLE_WHITESPACE_RE.fullmatch(self.value) is None:
         raise CSTValidationError(
             f"Got non-whitespace value for whitespace node: {repr(self.value)}"
         )
Beispiel #3
0
 def _validate(self) -> None:
     if COMMENT_RE.fullmatch(self.value) is None:
         raise CSTValidationError(
             f"Got non-comment value for comment node: {repr(self.value)}")
Beispiel #4
0
 def _validate(self) -> None:
     value = self.value
     if value and NEWLINE_RE.fullmatch(value) is None:
         raise CSTValidationError(
             f"Got an invalid value for newline node: {repr(value)}")
Beispiel #5
0
 def _validate(self) -> None:
     if self.value not in ["!=", "<>"]:
         raise CSTValidationError("Invalid value for NotEqual node.")
Beispiel #6
0
 def _validate(self) -> None:
     if self.whitespace_between.empty:
         raise CSTValidationError(
             "Must have at least one space between not and in.")