summaryrefslogtreecommitdiff
path: root/Lib/test/test_symbol.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-30 10:49:27 -0400
committerYury Selivanov <yselivanov@sprymix.com>2015-05-30 10:49:27 -0400
commit802d45b6604b82ee636fdd795cc6a7d9e655855d (patch)
treec9d51cf8a24d9dbe295985d1823dc23efb1aa570 /Lib/test/test_symbol.py
parent5844436adfa48b91ccd328c0bfd6ab1237a1311d (diff)
parente90982111ae1accc2a2ecaae94650a1d16a772ff (diff)
downloadcpython-git-802d45b6604b82ee636fdd795cc6a7d9e655855d.tar.gz
Merge 3.5
Diffstat (limited to 'Lib/test/test_symbol.py')
-rw-r--r--Lib/test/test_symbol.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_symbol.py b/Lib/test/test_symbol.py
new file mode 100644
index 0000000000..4475bbcac4
--- /dev/null
+++ b/Lib/test/test_symbol.py
@@ -0,0 +1,45 @@
+import unittest
+from test import support
+import filecmp
+import os
+import sys
+import subprocess
+
+
+SYMBOL_FILE = support.findfile('symbol.py')
+GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
+ '..', '..', 'Include', 'graminit.h')
+TEST_PY_FILE = 'symbol_test.py'
+
+
+class TestSymbolGeneration(unittest.TestCase):
+
+ def _copy_file_without_generated_symbols(self, source_file, dest_file):
+ with open(source_file, 'rb') as fp:
+ lines = fp.readlines()
+ nl = lines[0][len(lines[0].rstrip()):]
+ with open(dest_file, 'wb') as fp:
+ fp.writelines(lines[:lines.index(b"#--start constants--" + nl) + 1])
+ fp.writelines(lines[lines.index(b"#--end constants--" + nl):])
+
+ def _generate_symbols(self, grammar_file, target_symbol_py_file):
+ proc = subprocess.Popen([sys.executable,
+ SYMBOL_FILE,
+ grammar_file,
+ target_symbol_py_file], stderr=subprocess.PIPE)
+ stderr = proc.communicate()[1]
+ return proc.returncode, stderr
+
+ @unittest.skipIf(not os.path.exists(GRAMMAR_FILE),
+ 'test only works from source build directory')
+ def test_real_grammar_and_symbol_file(self):
+ self._copy_file_without_generated_symbols(SYMBOL_FILE, TEST_PY_FILE)
+ self.addCleanup(support.unlink, TEST_PY_FILE)
+ self.assertFalse(filecmp.cmp(SYMBOL_FILE, TEST_PY_FILE))
+ self.assertEqual((0, b''), self._generate_symbols(GRAMMAR_FILE,
+ TEST_PY_FILE))
+ self.assertTrue(filecmp.cmp(SYMBOL_FILE, TEST_PY_FILE))
+
+
+if __name__ == "__main__":
+ unittest.main()