148
148
"""A cut-down version of pytree_idempotency.py."""
150
150
def test_all_project_files(self):
151
if sys.platform.startswith("win"):
152
# XXX something with newlines goes wrong on Windows.
151
154
for filepath in support.all_project_files():
152
print "Parsing %s..." % filepath
153
tree = driver.parse_file(filepath, debug=True)
154
if diff(filepath, tree):
155
with open(filepath, "rb") as fp:
156
encoding = tokenize.detect_encoding(fp.readline)[0]
157
self.assertTrue(encoding is not None,
158
"can't detect encoding for %s" % filepath)
159
with io.open(filepath, "r", encoding=encoding) as fp:
161
tree = driver.parse_string(source)
163
if diff(filepath, new, encoding):
155
164
self.fail("Idempotency failed: %s" % filepath)
166
def test_extended_unpacking(self):
167
driver.parse_string("a, *b, c = x\n")
168
driver.parse_string("[*a, b] = x\n")
169
driver.parse_string("(z, *y, w) = m\n")
170
driver.parse_string("for *z, m in d: pass\n")
158
172
class TestLiterals(GrammarTest):
174
def validate(self, s):
175
driver.parse_string(support.dedent(s) + "\n\n")
160
177
def test_multiline_bytes_literals(self):
162
179
md5test(b"\xaa" * 80,
205
def diff(fn, result, encoding):
206
f = io.open("@", "w", encoding=encoding)
195
return os.system("diff -u %s @" % fn)
212
return os.system("diff -u %r @" % fn)
200
if __name__ == "__main__":
202
support.run_all_tests(__main__)