[Python-checkins] python/dist/src/Lib/test test_logging.py,1.10,1.11

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 22 Jul 2003 17:05:09 -0700


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

Modified Files:
	test_logging.py 
Log Message:
Fred wasn't kidding -- there really are docs for the locale module <wink>.

Obtain the original locale in the documented way.  This way actually
works for me.

Restore the original locale at the end, instead of forcing to "C".

Move the locale fiddling into the test driver instead of doing it as a
side effect of merely importing the module.  I don't know why the test
is mucking with locale (and also added a comment saying so), but it
surely has no justification for doing that as an import side-effect.
Now whenever the locale-changing code executes, the locale-restoring code
will also get run.


Index: test_logging.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_logging.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_logging.py	18 Jul 2003 03:19:20 -0000	1.10
--- test_logging.py	23 Jul 2003 00:05:07 -0000	1.11
***************
*** 27,40 ****
  import select
  import os, sys, string, struct, types, cPickle, cStringIO
! import socket, threading, time, locale
  import logging, logging.handlers, logging.config
  
- try:
-     cur_locale = locale.setlocale(locale.LC_ALL, '')
- except (ValueError, locale.Error):
-     # this happens on a Solaris box which only supports "C" locale
-     # or a Mac OS X box which supports very little locale stuff at all
-     cur_locale = None
- 
  BANNER = "-- %-10s %-6s ---------------------------------------------------\n"
  
--- 27,33 ----
  import select
  import os, sys, string, struct, types, cPickle, cStringIO
! import socket, threading, time
  import logging, logging.handlers, logging.config
  
  BANNER = "-- %-10s %-6s ---------------------------------------------------\n"
  
***************
*** 408,412 ****
      sys.stdout.flush()
  
! def test_main():
      rootLogger = logging.getLogger("")
      rootLogger.setLevel(logging.DEBUG)
--- 401,405 ----
      sys.stdout.flush()
  
! def test_main_inner():
      rootLogger = logging.getLogger("")
      rootLogger.setLevel(logging.DEBUG)
***************
*** 475,480 ****
          sys.stdout.flush()
  
!     if cur_locale:
!         locale.setlocale(locale.LC_ALL, "C")
  
  if __name__ == "__main__":
--- 468,489 ----
          sys.stdout.flush()
  
! def test_main():
!     import locale
!     # Set the locale to the platform-dependent default.  I have no idea
!     # why the test does this, but in any case we save the current locale
!     # first so we can restore it at the end.
!     try:
!         original_locale = locale.setlocale(locale.LC_ALL)
!         locale.setlocale(locale.LC_ALL, '')
!     except (ValueError, locale.Error):
!         # this happens on a Solaris box which only supports "C" locale
!         # or a Mac OS X box which supports very little locale stuff at all
!         original_locale = None
! 
!     try:
!         test_main_inner()
!     finally:
!         if original_locale:
!             locale.setlocale(locale.LC_ALL, original_locale)
  
  if __name__ == "__main__":