summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_zipfile.py')
-rw-r--r--Lib/test/test_zipfile.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index e07380d..367f37e 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -19,7 +19,8 @@ from tempfile import TemporaryFile
from random import randint, random
from unittest import skipUnless
-from test.support import TESTFN, run_unittest, findfile, unlink
+from test.support import (TESTFN, run_unittest, findfile, unlink,
+ captured_stdout)
TESTFN2 = TESTFN + "2"
TESTFNDIR = TESTFN + "d"
@@ -735,6 +736,28 @@ class PyZipFileTests(unittest.TestCase):
self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
os.remove(TESTFN)
+ def test_write_pyfile_bad_syntax(self):
+ os.mkdir(TESTFN2)
+ try:
+ with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp:
+ fp.write("Bad syntax in python file\n")
+
+ with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
+ # syntax errors are printed to stdout
+ with captured_stdout() as s:
+ zipfp.writepy(os.path.join(TESTFN2, "mod1.py"))
+
+ self.assertIn("SyntaxError", s.getvalue())
+
+ # as it will not have compiled the python file, it will
+ # include the .py file not .pyc or .pyo
+ names = zipfp.namelist()
+ self.assertIn('mod1.py', names)
+ self.assertNotIn('mod1.pyc', names)
+ self.assertNotIn('mod1.pyo', names)
+
+ finally:
+ shutil.rmtree(TESTFN2)
class OtherTests(unittest.TestCase):
zips_with_bad_crc = {