[Python-checkins] python/dist/src/Lib/test test_pep277.py,1.1,1.2

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 05 Oct 2002 10:54:59 -0700


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

Modified Files:
	test_pep277.py 
Log Message:
This test fails on Win98, which is fine, but when it failed it left
a junk directory behind that caused 4 other tests to fail later.  Now
it cleans up after itself, and the 4 bogus later failures don't happen.


Index: test_pep277.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pep277.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_pep277.py	3 Oct 2002 23:14:10 -0000	1.1
--- test_pep277.py	5 Oct 2002 17:54:56 -0000	1.2
***************
*** 7,11 ****
      from nt import _getfullpathname
  except ImportError:
!     raise TestSkipped, "test works only on NT"
  
  filenames = [
--- 7,11 ----
      from nt import _getfullpathname
  except ImportError:
!     raise TestSkipped, "test works only on NT+"
  
  filenames = [
***************
*** 21,27 ****
      ]
  
  class UnicodeFileTests(unittest.TestCase):
      def setUp(self):
-         self.files = [os.path.join(TESTFN, f) for f in filenames]
          try:
              os.mkdir(TESTFN)
--- 21,37 ----
      ]
  
+ # Destroy directory dirname and all files under it, to one level.
+ def deltree(dirname):
+     # Don't hide legitimate errors:  if one of these suckers exists, it's
+     # an error if we can't remove it.
+     if os.path.exists(dirname):
+         for fname in os.listdir(dirname):
+             os.unlink(os.path.join(dirname, fname))
+         os.rmdir(dirname)
+ 
  class UnicodeFileTests(unittest.TestCase):
+     files = [os.path.join(TESTFN, f) for f in filenames]
+ 
      def setUp(self):
          try:
              os.mkdir(TESTFN)
***************
*** 35,41 ****
  
      def tearDown(self):
!         for name in self.files:
!             os.unlink(name)
!         os.rmdir(TESTFN)
  
      def _apply_failure(self, fn, filename, expected_exception,
--- 45,49 ----
  
      def tearDown(self):
!         deltree(TESTFN)
  
      def _apply_failure(self, fn, filename, expected_exception,
***************
*** 101,105 ****
      suite = unittest.TestSuite()
      suite.addTest(unittest.makeSuite(UnicodeFileTests))
!     run_suite(suite)
  
  if __name__ == "__main__":
--- 109,116 ----
      suite = unittest.TestSuite()
      suite.addTest(unittest.makeSuite(UnicodeFileTests))
!     try:
!         run_suite(suite)
!     finally:
!         deltree(TESTFN)
  
  if __name__ == "__main__":