-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unparser for py 3.12 and setup minimal testing
Finally fixes #79
- Loading branch information
1 parent
a79e813
commit ed5faef
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
|
||
import ast | ||
import gast | ||
import sys | ||
|
||
|
||
class UnparserTestCase(unittest.TestCase): | ||
|
||
def __init__(self, *args, **kwargs): | ||
unittest.TestCase.__init__(self, *args, **kwargs) | ||
self.maxDiff = None | ||
|
||
def assertUnparse(self, code): | ||
normalized_code = ast.unparse(ast.parse(code)) | ||
tree = gast.parse(normalized_code) | ||
compile(gast.gast_to_ast(tree), '<test>', 'exec') | ||
unparsed = gast.unparse(tree) | ||
self.assertEqual(normalized_code, unparsed) | ||
|
||
def test_FunctionDef(self): | ||
self.assertUnparse('def foo(x, y): return x, y') | ||
|
||
def test_BinaryOp(self): | ||
self.assertUnparse('1 + 3') | ||
|
||
if sys.version_info >= (3, 12): | ||
|
||
def test_TypeParameter(self): | ||
self.assertUnparse('type x[T] = list[T]') | ||
|
||
|
||
if sys.version_info < (3, 9): | ||
del UnparserTestCase | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |