1- # TODO: RUSTPYTHON
2- try :
3- nonlocal_ex = """\
4- def f():
5- x = 1
6- def g():
7- nonlocal x
8- x = 2
9- y = 7
10- def h():
11- nonlocal x, y
12- """
13- import ast
14- import unittest
15- ast1 = ast .parse (nonlocal_ex )
16- code2 = ast .unparse (ast1 )
17- except AttributeError :
18- raise unittest .SkipTest ('TODO: RUSTPYTHON; type_comment attribute not implemented. FunctionDef, AsyncFunctionDef, For, AsyncFor, With and AsyncWith should have attribute' )
19-
201"""Tests for ast.unparse."""
212
223import unittest
@@ -178,6 +159,7 @@ def check_src_dont_roundtrip(self, code1, code2=None):
178159class UnparseTestCase (ASTTestCase ):
179160 # Tests for specific bugs found in earlier versions of unparse
180161
162+ @unittest .expectedFailure # TODO: RUSTPYTHON; f'{a!ÿ}' - SyntaxError: invalid syntax: f-string: invalid conversion character
181163 def test_fstrings (self ):
182164 self .check_ast_roundtrip ("f'a'" )
183165 self .check_ast_roundtrip ("f'{{}}'" )
@@ -199,13 +181,15 @@ def test_fstrings(self):
199181 "{j!s:{a}b}{k!s:a{b}c}{l!a:{b}c{d}}{x+y=}'"
200182 )
201183
184+ @unittest .expectedFailure # TODO: RUSTPYTHON; f"{f'{y!ÿ}' * 3!ÿ}" - SyntaxError: invalid syntax: f-string: invalid conversion character
202185 def test_fstrings_special_chars (self ):
203186 # See issue 25180
204187 self .check_ast_roundtrip (r"""f'{f"{0}"*3}'""" )
205188 self .check_ast_roundtrip (r"""f'{f"{y}"*3}'""" )
206189 self .check_ast_roundtrip ("""f''""" )
207190 self .check_ast_roundtrip ('''f"""'end' "quote\\ """"''' )
208191
192+ @unittest .expectedFailure # TODO: RUSTPYTHON; f"""{"'"!ÿ}""" - SyntaxError: invalid syntax: f-string: invalid conversion character
209193 def test_fstrings_complicated (self ):
210194 # See issue 28002
211195 self .check_ast_roundtrip ("""f'''{"'"}'''""" )
@@ -216,6 +200,7 @@ def test_fstrings_complicated(self):
216200 self .check_ast_roundtrip ('''f"a\\ r\\ nb"''' )
217201 self .check_ast_roundtrip ('''f"\\ u2028{'x'}"''' )
218202
203+ @unittest .expectedFailure # TODO: RUSTPYTHON; SyntaxError: invalid syntax: f-string: invalid conversion character
219204 def test_fstrings_pep701 (self ):
220205 self .check_ast_roundtrip ('f" something { my_dict["key"] } something else "' )
221206 self .check_ast_roundtrip ('f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"' )
@@ -232,9 +217,11 @@ def test_shifts(self):
232217 self .check_ast_roundtrip ("45 << 2" )
233218 self .check_ast_roundtrip ("13 >> 7" )
234219
220+ @unittest .expectedFailure # TODO: RUSTPYTHON; type_comment attribute not implemented. FunctionDef should have attribute
235221 def test_for_else (self ):
236222 self .check_ast_roundtrip (for_else )
237223
224+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'FunctionDef' object has no attribute 'type_comment'
238225 def test_while_else (self ):
239226 self .check_ast_roundtrip (while_else )
240227
@@ -254,6 +241,7 @@ def test_huge_float(self):
254241 self .check_ast_roundtrip ("1e1000j" )
255242 self .check_ast_roundtrip ("-1e1000j" )
256243
244+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.kind == "u": - AttributeError: 'Constant' object has no attribute 'kind'
257245 def test_nan (self ):
258246 self .assertASTEqual (
259247 ast .parse (ast .unparse (ast .Constant (value = float ('nan' )))),
@@ -270,13 +258,15 @@ def test_imaginary_literals(self):
270258 self .check_ast_roundtrip ("0j" )
271259 self .check_ast_roundtrip ("-0j" )
272260
261+ @unittest .expectedFailure # TODO: RUSTPYTHON; for field in node._fields: - AttributeError: 'NoneType' object has no attribute '_fields'
273262 def test_lambda_parentheses (self ):
274263 self .check_ast_roundtrip ("(lambda: int)()" )
275264
276265 def test_chained_comparisons (self ):
277266 self .check_ast_roundtrip ("1 < 4 <= 5" )
278267 self .check_ast_roundtrip ("a is b is c is not d" )
279268
269+ @unittest .expectedFailure # TODO: RUSTPYTHON; type_comment attribute not implemented. FunctionDef should have attribute
280270 def test_function_arguments (self ):
281271 self .check_ast_roundtrip ("def f(): pass" )
282272 self .check_ast_roundtrip ("def f(a): pass" )
@@ -294,6 +284,7 @@ def test_function_arguments(self):
294284 def test_relative_import (self ):
295285 self .check_ast_roundtrip (relative_import )
296286
287+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'FunctionDef' object has no attribute 'type_comment'
297288 def test_nonlocal (self ):
298289 self .check_ast_roundtrip (nonlocal_ex )
299290
@@ -303,6 +294,7 @@ def test_raise_from(self):
303294 def test_bytes (self ):
304295 self .check_ast_roundtrip ("b'123'" )
305296
297+ @unittest .expectedFailure # TODO: RUSTPYTHON; type_comment attribute not implemented. FunctionDef should have attribute
306298 def test_annotations (self ):
307299 self .check_ast_roundtrip ("def f(a : int): pass" )
308300 self .check_ast_roundtrip ("def f(a: int = 5): pass" )
@@ -325,6 +317,7 @@ def test_set_comprehension(self):
325317 def test_dict_comprehension (self ):
326318 self .check_ast_roundtrip ("{x: x*x for x in range(10)}" )
327319
320+ @unittest .expectedFailure # TODO: RUSTPYTHON; for e in node.bases: - TypeError: 'NoneType' object is not iterable
328321 def test_class_decorators (self ):
329322 self .check_ast_roundtrip (class_decorator )
330323
@@ -347,12 +340,15 @@ def test_starred_assignment(self):
347340 self .check_ast_roundtrip ("a, *b[0], c = seq" )
348341 self .check_ast_roundtrip ("a, *(b, c) = seq" )
349342
343+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'With' object has no attribute 'type_comment'
350344 def test_with_simple (self ):
351345 self .check_ast_roundtrip (with_simple )
352346
347+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'With' object has no attribute 'type_comment'
353348 def test_with_as (self ):
354349 self .check_ast_roundtrip (with_as )
355350
351+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'With' object has no attribute 'type_comment'
356352 def test_with_two_items (self ):
357353 self .check_ast_roundtrip (with_two_items )
358354
@@ -401,6 +397,7 @@ def test_invalid_fstring_value(self):
401397 )
402398 )
403399
400+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.kind == "u": - AttributeError: 'Constant' object has no attribute 'kind'
404401 def test_fstring_backslash (self ):
405402 # valid since Python 3.12
406403 self .assertEqual (ast .unparse (
@@ -414,6 +411,7 @@ def test_fstring_backslash(self):
414411 def test_invalid_yield_from (self ):
415412 self .check_invalid (ast .YieldFrom (value = None ))
416413
414+ @unittest .expectedFailure # TODO: RUSTPYTHON; self.write("." * (node.level or 0)) - AttributeError: 'ImportFrom' object has no attribute 'level'
417415 def test_import_from_level_none (self ):
418416 tree = ast .ImportFrom (module = 'mod' , names = [ast .alias (name = 'x' )])
419417 self .assertEqual (ast .unparse (tree ), "from mod import x" )
@@ -440,12 +438,14 @@ def test_docstrings(self):
440438 # check as Module docstrings for easy testing
441439 self .check_ast_roundtrip (f"'''{ docstring } '''" )
442440
441+ @unittest .expectedFailure # TODO: RUSTPYTHON; _feature_version=feature_version, optimize=optimize) - TypeError: expected some sort of mod, but got <_ast.Constant object at 0x55810cf9a2a0>
443442 def test_constant_tuples (self ):
444443 self .check_src_roundtrip (ast .Constant (value = (1 ,), kind = None ), "(1,)" )
445444 self .check_src_roundtrip (
446445 ast .Constant (value = (1 , 2 , 3 ), kind = None ), "(1, 2, 3)"
447446 )
448447
448+ @unittest .expectedFailure # TODO: RUSTPYTHON; _feature_version=feature_version, optimize=optimize) - ValueError: mode must be "exec", "eval", "ipython", or "single"
449449 def test_function_type (self ):
450450 for function_type in (
451451 "() -> int" ,
@@ -454,6 +454,7 @@ def test_function_type(self):
454454 ):
455455 self .check_ast_roundtrip (function_type , mode = "func_type" )
456456
457+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'FunctionDef' object has no attribute 'type_comment'
457458 def test_type_comments (self ):
458459 for statement in (
459460 "a = 5 # type:" ,
@@ -470,6 +471,7 @@ def test_type_comments(self):
470471 ):
471472 self .check_ast_roundtrip (statement , type_comments = True )
472473
474+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'FunctionDef' object has no attribute 'type_comment'
473475 def test_type_ignore (self ):
474476 for statement in (
475477 "a = 5 # type: ignore" ,
@@ -519,6 +521,7 @@ def test_simple_expressions_parens(self):
519521 self .check_src_roundtrip ("call((yield x))" )
520522 self .check_src_roundtrip ("return x + (yield x)" )
521523
524+ @unittest .skip ('TODO: RUSTPYTHON; self.write("." * (node.level or 0)) - AttributeError: "ImportFrom" object has no attribute "level"' )
522525 def test_class_bases_and_keywords (self ):
523526 self .check_src_roundtrip ("class X:\n pass" )
524527 self .check_src_roundtrip ("class X(A):\n pass" )
@@ -531,7 +534,7 @@ def test_class_bases_and_keywords(self):
531534 self .check_src_roundtrip ("class X(*args):\n pass" )
532535 self .check_src_roundtrip ("class X(*args, **kwargs):\n pass" )
533536
534- @unittest .expectedFailure # TODO: RUSTPYTHON; f"{f'{x!ÿ}\n '!ÿ}\n"
537+ @unittest .expectedFailure # TODO: RUSTPYTHON; AssertionError: 'f\'\'\'-{f"""*{f"+{f\'.{x}.\'}+"}*"""}-\'\'\'' != 'f\'\'\'-{f"""*{f"+{f\'.{x!ÿ}.\ '!ÿ}+"!ÿ}*"""!ÿ}-\'\'\''
535538 def test_fstrings (self ):
536539 self .check_src_roundtrip ('''f\' \' \' -{f"""*{f"+{f'.{x}.'}+"}*"""}-\' \' \' ''' )
537540 self .check_src_roundtrip ('''f\' -{f\' \' \' *{f"""+{f".{f'{x}'}."}+"""}*\' \' \' }-\' ''' )
@@ -541,6 +544,7 @@ def test_fstrings(self):
541544 self .check_src_roundtrip ('''f"{'\\ n'}\\ n"''' )
542545 self .check_src_roundtrip ('''f"{f'{x}\\ n'}\\ n"''' )
543546
547+ @unittest .expectedFailure # TODO: RUSTPYTHON; for e in node.bases: - TypeError: 'NoneType' object is not iterable
544548 def test_docstrings (self ):
545549 docstrings = (
546550 '"""simple doc string"""' ,
@@ -565,6 +569,7 @@ def test_docstrings(self):
565569 for docstring in docstrings :
566570 self .check_src_roundtrip (f"{ prefix } { docstring } " )
567571
572+ @unittest .expectedFailure # TODO: RUSTPYTHON; for e in node.bases: - TypeError: 'NoneType' object is not iterable
568573 def test_docstrings_negative_cases (self ):
569574 # Test some cases that involve strings in the children of the
570575 # first node but aren't docstrings to make sure we don't have
@@ -608,6 +613,7 @@ def test_slices(self):
608613 self .check_src_roundtrip ("a[1:2, *a]" )
609614 self .check_src_roundtrip ("a[*a, 1:2]" )
610615
616+ @unittest .expectedFailure # TODO: RUSTPYTHON; for field in node._fields: - AttributeError: 'NoneType' object has no attribute '_fields'
611617 def test_lambda_parameters (self ):
612618 self .check_src_roundtrip ("lambda: something" )
613619 self .check_src_roundtrip ("four = lambda: 2 + 2" )
@@ -618,6 +624,7 @@ def test_lambda_parameters(self):
618624 self .check_src_roundtrip ("lambda x, y, /, z, q, *, u: None" )
619625 self .check_src_roundtrip ("lambda x, *y, **z: None" )
620626
627+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'For' object has no attribute 'type_comment'
621628 def test_star_expr_assign_target (self ):
622629 for source_type , source in [
623630 ("single assignment" , "{target} = foo" ),
@@ -657,6 +664,7 @@ def test_star_expr_assign_target_multiple(self):
657664 self .check_src_roundtrip ("[a, b] = [c, d] = [e, f] = g" )
658665 self .check_src_roundtrip ("a, b = [c, d] = e, f = g" )
659666
667+ @unittest .expectedFailure # TODO: RUSTPYTHON; f"""'''{1!ÿ}\"""" - SyntaxError: invalid syntax: f-string: invalid conversion character
660668 def test_multiquote_joined_string (self ):
661669 self .check_ast_roundtrip ("f\" '''{1}\\ \" \\ \" \\ \" \" " )
662670 self .check_ast_roundtrip ("""f"'''{1}""\\ "" """ )
@@ -671,7 +679,7 @@ def test_multiquote_joined_string(self):
671679 self .check_ast_roundtrip ("""f'''""\" ''\\ '{"\\ n\\ "'"}''' """ )
672680 self .check_ast_roundtrip ("""f'''""\" ''\\ '{""\" \\ n\\ "'''""\" '''\\ n'''}''' """ )
673681
674- @unittest .expectedFailure # TODO: RUSTPYTHON; AssertionError: SyntaxWarning not triggered
682+ @unittest .expectedFailure # TODO: RUSTPYTHON; f'{x!ÿ:\\ }' - SyntaxError: invalid syntax: f-string: invalid conversion character
675683 def test_backslash_in_format_spec (self ):
676684 import re
677685 msg = re .escape ("invalid escape sequence '\\ '" )
@@ -687,6 +695,7 @@ def test_backslash_in_format_spec(self):
687695
688696 self .check_ast_roundtrip ("""f"{x:\\ \\ \\ \\ }" """ )
689697
698+ @unittest .expectedFailure # TODO: RUSTPYTHON; f"{x!ÿ:\'}" - SyntaxError: invalid syntax: f-string: invalid conversion character
690699 def test_quote_in_format_spec (self ):
691700 self .check_ast_roundtrip ("""f"{x:'}" """ )
692701 self .check_ast_roundtrip ("""f"{x:\\ '}" """ )
@@ -696,6 +705,7 @@ def test_quote_in_format_spec(self):
696705 self .check_ast_roundtrip ("""f'\\ '{x:\\ "}' """ )
697706 self .check_ast_roundtrip ("""f'\\ '{x:\\ \\ "}' """ )
698707
708+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.default_value: - AttributeError: 'TypeVar' object has no attribute 'default_value'
699709 def test_type_params (self ):
700710 self .check_ast_roundtrip ("type A = int" )
701711 self .check_ast_roundtrip ("type A[T] = int" )
@@ -719,12 +729,14 @@ def test_class(self):
719729 ast .fix_missing_locations (node )
720730 self .assertEqual (ast .unparse (node ), "class X:\n pass" )
721731
732+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.bound: - AttributeError: 'TypeVar' object has no attribute 'bound'
722733 def test_class_with_type_params (self ):
723734 node = ast .ClassDef (name = "X" , bases = [], keywords = [], body = [ast .Pass ()], decorator_list = [],
724735 type_params = [ast .TypeVar ("T" )])
725736 ast .fix_missing_locations (node )
726737 self .assertEqual (ast .unparse (node ), "class X[T]:\n pass" )
727738
739+ @unittest .expectedFailure # TODO: RUSTPYTHON; comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'FunctionDef' object has no attribute 'type_comment'
728740 def test_function (self ):
729741 node = ast .FunctionDef (
730742 name = "f" ,
@@ -736,6 +748,7 @@ def test_function(self):
736748 ast .fix_missing_locations (node )
737749 self .assertEqual (ast .unparse (node ), "def f():\n pass" )
738750
751+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.default_value: - if node.bound: - AttributeError: 'TypeVar' object has no attribute 'bound'
739752 def test_function_with_type_params (self ):
740753 node = ast .FunctionDef (
741754 name = "f" ,
@@ -748,6 +761,7 @@ def test_function_with_type_params(self):
748761 ast .fix_missing_locations (node )
749762 self .assertEqual (ast .unparse (node ), "def f[T]():\n pass" )
750763
764+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.default_value: - AttributeError: 'TypeVar' object has no attribute 'default_value'
751765 def test_function_with_type_params_and_bound (self ):
752766 node = ast .FunctionDef (
753767 name = "f" ,
@@ -760,6 +774,7 @@ def test_function_with_type_params_and_bound(self):
760774 ast .fix_missing_locations (node )
761775 self .assertEqual (ast .unparse (node ), "def f[T: int]():\n pass" )
762776
777+ @unittest .expectedFailure # TODO: RUSTPYTHON; for deco in node.decorator_list: - AttributeError: 'FunctionDef' object has no attribute 'decorator_list'
763778 def test_function_with_type_params_and_default (self ):
764779 node = ast .FunctionDef (
765780 name = "f" ,
@@ -774,6 +789,7 @@ def test_function_with_type_params_and_default(self):
774789 ast .fix_missing_locations (node )
775790 self .assertEqual (ast .unparse (node ), "def f[T = 1, *Ts = *1, **P = 1]():\n pass" )
776791
792+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.bound: - comment = self._type_ignores.get(node.lineno) or node.type_comment - AttributeError: 'AsyncFunctionDef' object has no attribute 'type_comment'
777793 def test_async_function (self ):
778794 node = ast .AsyncFunctionDef (
779795 name = "f" ,
@@ -785,6 +801,7 @@ def test_async_function(self):
785801 ast .fix_missing_locations (node )
786802 self .assertEqual (ast .unparse (node ), "async def f():\n pass" )
787803
804+ @unittest .expectedFailure # TODO: RUSTPYTHON; if node.bound: - AttributeError: 'TypeVar' object has no attribute 'bound'
788805 def test_async_function_with_type_params (self ):
789806 node = ast .AsyncFunctionDef (
790807 name = "f" ,
@@ -797,6 +814,7 @@ def test_async_function_with_type_params(self):
797814 ast .fix_missing_locations (node )
798815 self .assertEqual (ast .unparse (node ), "async def f[T]():\n pass" )
799816
817+ @unittest .expectedFailure # TODO: RUSTPYTHON; AttributeError: 'AsyncFunctionDef' object has no attribute 'decorator_list'
800818 def test_async_function_with_type_params_and_default (self ):
801819 node = ast .AsyncFunctionDef (
802820 name = "f" ,
@@ -811,7 +829,7 @@ def test_async_function_with_type_params_and_default(self):
811829 ast .fix_missing_locations (node )
812830 self .assertEqual (ast .unparse (node ), "async def f[T = 1, *Ts = *1, **P = 1]():\n pass" )
813831
814-
832+ @ unittest . expectedFailure # TODO: RUSTPYTHON; type_comment attribute not implemented. FunctionDef, AsyncFunctionDef, For, AsyncFor, With and AsyncWith should have attribute
815833class DirectoryTestCase (ASTTestCase ):
816834 """Test roundtrip behaviour on all files in Lib and Lib/test."""
817835
0 commit comments