summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_uu.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-08-17 20:00:11 (GMT)
committerBarry Warsaw <barry@python.org>2001-08-17 20:00:11 (GMT)
commitd1795705de6f92020d14291d9842793d54c9cf54 (patch)
tree5ae76fc4f69cb85a92b47ae0c39d5e7c7905fee2 /Lib/test/test_uu.py
parent59dae8ad360d2a13e1e7615c04c29863f7de562b (diff)
downloadcpython-d1795705de6f92020d14291d9842793d54c9cf54.zip
cpython-d1795705de6f92020d14291d9842793d54c9cf54.tar.gz
cpython-d1795705de6f92020d14291d9842793d54c9cf54.tar.bz2
Test that uu.py will not override an existing file if out_file isn't
given and the path is gleaned from the uu header.
Diffstat (limited to 'Lib/test/test_uu.py')
-rw-r--r--Lib/test/test_uu.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
index 8c324d1..07bd482 100644
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -122,3 +122,37 @@ try:
raise TestFailed("No exception thrown")
except uu.Error, e:
verify(str(e) == 'No valid begin line found in input file')
+
+# Test to verify that decode() will refuse to overwrite an existing file
+import tempfile
+outfile = tempfile.mktemp()
+inp = StringIO('Here is a message to be uuencoded')
+out = StringIO()
+uu.encode(inp, out, outfile)
+out.seek(0)
+try:
+ if verbose:
+ print '9. decode w/file not exists is okay'
+ uu.decode(out)
+ if not os.path.exists(outfile):
+ raise TestFailed('uudecode w/ out_file=None failed')
+ fp = open(outfile)
+ data = fp.read()
+ fp.close()
+ if data <> inp.getvalue():
+ raise TestFailed('uudecode stored something weird')
+ # Try to write it again, which should cause a failure
+ if verbose:
+ print '10. uudecode w/file exists fails'
+ out.seek(0)
+ try:
+ uu.decode(out)
+ except uu.Error:
+ pass
+ else:
+ raise TestFailed('expected to get a "file exists" error')
+finally:
+ try:
+ os.unlink(outfile)
+ except OSError:
+ pass