Repository: RustPython/RustPython
File: Lib/test/test_ast/test_ast.py (Python)

Code before:
            kwd_patterns=[],
        ),
        ast.MatchClass(
            name_carter, patterns=[ast.MatchStar()], kwd_attrs=[], kwd_patterns=[]
        ),
        ast.MatchClass(
            name_carter, patterns=[], kwd_attrs=[], kwd_patterns=[ast.MatchStar()]
        ),
        ast.MatchClass(
            constant_true,  # invalid name
            patterns=[],
            kwd_attrs=["True"],
            kwd_patterns=[pattern_1],
        ),
        ast.MatchSequence([ast.MatchStar("True")]),
        ast.MatchAs(name="False"),
        ast.MatchOr([]),
        ast.MatchOr([pattern_1]),
        ast.MatchOr([pattern_1, pattern_x, ast.MatchSingleton("xxx")]),
        ast.MatchAs(name="_"),
        ast.MatchStar(name="x"),
        ast.MatchSequence([ast.MatchStar("_")]),
        ast.MatchMapping([], [], rest="_"),
    ]

    @unittest.expectedFailure # TODO: RUSTPYTHON; thread 'main' panicked
    def test_match_validation_pattern(self):
        name_x = ast.Name("x", ast.Load())
        for pattern in self._MATCH_PATTERNS:
            with self.subTest(ast.dump(pattern, indent=4)):
                node = ast.Match(
                    subject=name_x,
                    cases=[ast.match_case(pattern=pattern, body=[ast.Pass()])],
                )
                node = ast.fix_missing_locations(node)
                module = ast.Module([node], [])
                with self.assertRaises(ValueError):
                    compile(module, "<test>", "exec")


class ConstantTests(unittest.TestCase):
    """Tests on the ast.Constant node type."""

    def compile_constant(self, value):
        tree = ast.parse("x = 123")

        node = tree.body[0].value
        new_node = ast.Constant(value=value)
        ast.copy_location(new_node, node)
        tree.body[0].value = new_node


Review comment (bug):
If thread 'main' panicked, this test cannot be `expectedFailure`. Please update the reason or delete it.

Code after:
            kwd_patterns=[],
        ),
        ast.MatchClass(
            name_carter, patterns=[ast.MatchStar()], kwd_attrs=[], kwd_patterns=[]
        ),
        ast.MatchClass(
            name_carter, patterns=[], kwd_attrs=[], kwd_patterns=[ast.MatchStar()]
        ),
        ast.MatchClass(
            constant_true,  # invalid name
            patterns=[],
            kwd_attrs=["True"],
            kwd_patterns=[pattern_1],
        ),
        ast.MatchSequence([ast.MatchStar("True")]),
        ast.MatchAs(name="False"),
        ast.MatchOr([]),
        ast.MatchOr([pattern_1]),
        ast.MatchOr([pattern_1, pattern_x, ast.MatchSingleton("xxx")]),
        ast.MatchAs(name="_"),
        ast.MatchStar(name="x"),
        ast.MatchSequence([ast.MatchStar("_")]),
        ast.MatchMapping([], [], rest="_"),
    ]

    @unittest.expectedFailure # TODO: RUSTPYTHON
    def test_match_validation_pattern(self):
        name_x = ast.Name("x", ast.Load())
        for pattern in self._MATCH_PATTERNS:
            with self.subTest(ast.dump(pattern, indent=4)):
                node = ast.Match(
                    subject=name_x,
                    cases=[ast.match_case(pattern=pattern, body=[ast.Pass()])],
                )
                node = ast.fix_missing_locations(node)
                module = ast.Module([node], [])
                with self.assertRaises(ValueError):
                    compile(module, "<test>", "exec")


class ConstantTests(unittest.TestCase):
    """Tests on the ast.Constant node type."""

    def compile_constant(self, value):
        tree = ast.parse("x = 123")

        node = tree.body[0].value
        new_node = ast.Constant(value=value)
        ast.copy_location(new_node, node)
        tree.body[0].value = new_node