[Python-checkins] CVS: python/dist/src/Lib/test test_uu.py,1.2,1.3

Barry Warsaw bwarsaw@users.sourceforge.net
Fri, 17 Aug 2001 13:00:13 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv14530

Modified Files:
	test_uu.py 
Log Message:
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.


Index: test_uu.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_uu.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_uu.py	2001/08/03 13:04:03	1.2
--- test_uu.py	2001/08/17 20:00:11	1.3
***************
*** 123,124 ****
--- 123,158 ----
  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