import ast
import re
import sys
if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

import astunparse
from tests.common import AstunparseCommonTestCase

class DumpTestCase(AstunparseCommonTestCase, unittest.TestCase):

    def assertASTEqual(self, dump1, dump2):
        # undo the pretty-printing
        dump1 = re.sub(r"(?<=[\(\[])\n\s+", "", dump1)
        dump1 = re.sub(r"\n\s+", " ", dump1)
        self.assertEqual(dump1, dump2)

    def check_roundtrip(self, code1, filename="internal", mode="exec"):
        ast_ = compile(str(code1), filename, mode, ast.PyCF_ONLY_AST)
        dump1 = astunparse.dump(ast_)
        dump2 = ast.dump(ast_)
        self.assertASTEqual(dump1, dump2)

[((16, 16, 16, 54), 're.sub', 're.sub', ({(16, 23, 16, 42): '"""(?<=[\\\\(\\\\[])\\\\n\\\\s+"""', (16, 44, 16, 46): '""""""', (16, 48, 16, 53): 'dump1'}, {}), "('(?<=[\\\\(\\\\[])\\\\n\\\\s+', '', dump1)", False, 'import re\n'), ((17, 16, 17, 44), 're.sub', 're.sub', ({(17, 23, 17, 31): '"""\\\\n\\\\s+"""', (17, 33, 17, 36): '""" """', (17, 38, 17, 43): 'dump1'}, {}), "('\\\\n\\\\s+', ' ', dump1)", False, 'import re\n'), ((22, 16, 22, 37), 'astunparse.dump', 'astunparse.dump', ({(22, 32, 22, 36): 'ast_'}, {}), '(ast_)', False, 'import astunparse\n'), ((23, 16, 23, 30), 'ast.dump', 'ast.dump', ({(23, 25, 23, 29): 'ast_'}, {}), '(ast_)', False, 'import ast\n')]