[Python-checkins] CVS: python/dist/src/Lib/test test_import.py,1.6,1.7

Tim Peters tim_one@users.sourceforge.net
2001年8月04日 01:12:38 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv379/python/dist/src/Lib/test
Modified Files:
	test_import.py 
Log Message:
Derived from SF patch #446899 Permit import of .pyw under Windows, from
David Bolen.
Index: test_import.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_import.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_import.py	2001年08月01日 20:23:18	1.6
--- test_import.py	2001年08月04日 08:12:35	1.7
***************
*** 17,64 ****
 import double_const # don't blink -- that *was* the test
 
! sys.path.insert(0, os.curdir)
! 
! source = TESTFN + ".py"
! pyo = TESTFN + ".pyo"
! if sys.platform.startswith('java'):
! pyc = TESTFN + "$py.class"
! else:
! pyc = TESTFN + ".pyc"
 
! f = open(source, "w")
! print >> f, "# This will test Python's ability to import a .py file"
! a = random.randrange(1000)
! b = random.randrange(1000)
! print >> f, "a =", a
! print >> f, "b =", b
! f.close()
 
- try:
 try:
! mod = __import__(TESTFN)
! except ImportError, err:
! raise ValueError, "import from .py failed: %s" % err
 
! if mod.a != a or mod.b != b:
! print a, "!=", mod.a
! print b, "!=", mod.b
! raise ValueError, "module loaded (%s) but contents invalid" % mod
! finally:
! os.unlink(source)
 
- try:
 try:
! reload(mod)
! except ImportError, err:
! raise ValueError, "import from .pyc/.pyo failed: %s" % err
! finally:
! try:
! os.unlink(pyc)
! except os.error:
! pass
! try:
! os.unlink(pyo)
! except os.error:
! pass
 
! del sys.path[0]
--- 17,71 ----
 import double_const # don't blink -- that *was* the test
 
! def test_with_extension(ext): # ext normally ".py"; perhaps ".pyw"
! source = TESTFN + ext
! pyo = TESTFN + ".pyo"
! if sys.platform.startswith('java'):
! pyc = TESTFN + "$py.class"
! else:
! pyc = TESTFN + ".pyc"
 
! f = open(source, "w")
! print >> f, "# This tests Python's ability to import a", ext, "file."
! a = random.randrange(1000)
! b = random.randrange(1000)
! print >> f, "a =", a
! print >> f, "b =", b
! f.close()
 
 try:
! try:
! mod = __import__(TESTFN)
! except ImportError, err:
! raise ValueError("import from %s failed: %s" % (ext, err))
 
! if mod.a != a or mod.b != b:
! print a, "!=", mod.a
! print b, "!=", mod.b
! raise ValueError("module loaded (%s) but contents invalid" % mod)
! finally:
! os.unlink(source)
 
 try:
! try:
! reload(mod)
! except ImportError, err:
! raise ValueError("import from .pyc/.pyo failed: %s" % err)
! finally:
! try:
! os.unlink(pyc)
! except os.error:
! pass
! try:
! os.unlink(pyo)
! except os.error:
! pass
! del sys.modules[TESTFN]
 
! sys.path.insert(0, os.curdir)
! try:
! test_with_extension(".py")
! if sys.platform.startswith("win"):
! for ext in ".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw":
! test_with_extension(ext)
! finally:
! del sys.path[0]

AltStyle によって変換されたページ (->オリジナル) /