[Python-checkins] python/dist/src/Lib/test test_tempfile.py,1.7,1.8

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Sat, 17 Aug 2002 07:50:26 -0700


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

Modified Files:
	test_tempfile.py 
Log Message:
Get rid of _once(); inlining it takes less code. :-)

Also, don't call gettempdir() in the default expression for the 'dir'
argument to various functions; use 'dir=None' for the default and
insert 'if dir is None: dir = gettemptir()' in the bodies.  That way
the work done by gettempdir is postponed until needed.



Index: test_tempfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_tempfile.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_tempfile.py	17 Aug 2002 11:41:01 -0000	1.7
--- test_tempfile.py	17 Aug 2002 14:50:24 -0000	1.8
***************
*** 85,149 ****
  
  
- class test__once(TC):
-     """Test the internal function _once."""
- 
-     def setUp(self):
-         tempfile.once_var = None
-         self.already_called = 0
- 
-     def tearDown(self):
-         del tempfile.once_var
- 
-     def callMeOnce(self):
-         self.failIf(self.already_called, "callMeOnce called twice")
-         self.already_called = 1
-         return 24
- 
-     def do_once(self):
-         tempfile._once('once_var', self.callMeOnce)
- 
-     def test_once_initializes(self):
-         """_once initializes its argument"""
- 
-         self.do_once()
- 
-         self.assertEqual(tempfile.once_var, 24,
-                          "once_var=%d, not 24" % tempfile.once_var)
-         self.assertEqual(self.already_called, 1,
-                          "already_called=%d, not 1" % self.already_called)
- 
-     def test_once_means_once(self):
-         """_once calls the callback just once"""
- 
-         self.do_once()
-         self.do_once()
-         self.do_once()
-         self.do_once()
- 
-     def test_once_namespace_safe(self):
-         """_once does not modify anything but its argument"""
- 
-         env_copy = tempfile.__dict__.copy()
- 
-         self.do_once()
- 
-         env = tempfile.__dict__
- 
-         a = env.keys()
-         a.sort()
-         b = env_copy.keys()
-         b.sort()
- 
-         self.failIf(len(a) != len(b))
-         for i in xrange(len(a)):
-             self.failIf(a[i] != b[i])
- 
-             key = a[i]
-             if key != 'once_var':
-                 self.failIf(env[key] != env_copy[key])
- 
- test_classes.append(test__once)
- 
- 
  class test__RandomNameSequence(TC):
      """Test the internal iterator object _RandomNameSequence."""
--- 85,88 ----