|
1 | 1 | import ast |
2 | 2 | import os |
3 | 3 | import string |
4 | | -import sys |
5 | 4 | from collections import Counter, OrderedDict |
6 | 5 | from collections.abc import Iterator |
7 | 6 | from dataclasses import dataclass |
@@ -456,40 +455,14 @@ class User(SQLAlchemyBase): |
456 | 455 | ) |
457 | 456 |
|
458 | 457 |
|
459 | | -@pytest.mark.skipif(sys.version_info < (3, 9), reason='no indent on older versions') |
460 | 458 | def test_ast_expr(): |
461 | | - if sys.version_info >= (3, 13): |
462 | | - # ast.dump omits empty lists from 3.13 onwards |
463 | | - expected = ( |
464 | | - 'Expression(' |
465 | | - '\n body=Call(' |
466 | | - "\n func=Name(id='print', ctx=Load())," |
467 | | - '\n args=[' |
468 | | - '\n Constant(value=1),' |
469 | | - '\n Constant(value=2),' |
470 | | - '\n Call(' |
471 | | - "\n func=Name(id='round', ctx=Load())," |
472 | | - '\n args=[' |
473 | | - '\n Constant(value=3)])]))' |
474 | | - ) |
475 | | - else: |
476 | | - expected = ( |
477 | | - 'Expression(' |
478 | | - '\n body=Call(' |
479 | | - "\n func=Name(id='print', ctx=Load())," |
480 | | - '\n args=[' |
481 | | - '\n Constant(value=1),' |
482 | | - '\n Constant(value=2),' |
483 | | - '\n Call(' |
484 | | - "\n func=Name(id='round', ctx=Load())," |
485 | | - '\n args=[' |
486 | | - '\n Constant(value=3)],' |
487 | | - '\n keywords=[])],' |
488 | | - '\n keywords=[]))' |
489 | | - ) |
490 | | - assert pformat(ast.parse('print(1, 2, round(3))', mode='eval')) == expected |
491 | | - |
492 | | - |
493 | | -@pytest.mark.skipif(sys.version_info < (3, 9), reason='no indent on older versions') |
| 459 | + node = ast.parse('print(1, 2, round(3))', mode='eval') |
| 460 | + v = pformat(node) |
| 461 | + # exactly which fields ast.dump omits changes between python versions, so compare to its own output |
| 462 | + assert v == ast.dump(node, indent=4) |
| 463 | + assert v.startswith('Expression(\n body=Call(\n func=Name(') |
| 464 | + assert '\n Constant(value=3)' in v |
| 465 | + |
| 466 | + |
494 | 467 | def test_ast_module(): |
495 | 468 | assert pformat(ast.parse('print(1, 2, round(3))')).startswith('Module(\n body=[') |
0 commit comments