[Python-checkins] r84097 - python/branches/py3k/Lib/test/test_import.py
florent.xicluna
python-checkins at python.org
Mon Aug 16 20:41:19 CEST 2010
Author: florent.xicluna
Date: Mon Aug 16 20:41:19 2010
New Revision: 84097
Log:
Use test.support and unittest features. Fix duplicated test (bad merge in r79033). Fix comment for issue #7902.
Modified:
python/branches/py3k/Lib/test/test_import.py
Modified: python/branches/py3k/Lib/test/test_import.py
==============================================================================
--- python/branches/py3k/Lib/test/test_import.py (original)
+++ python/branches/py3k/Lib/test/test_import.py Mon Aug 16 20:41:19 2010
@@ -1,5 +1,4 @@
import builtins
-import errno
import imp
from importlib.test.import_ import test_relative_imports
from importlib.test.import_ import util as importlib_util
@@ -7,7 +6,6 @@
import os
import py_compile
import random
-import shutil
import stat
import sys
import unittest
@@ -25,11 +23,7 @@
name + ".pyw",
name + "$py.class"):
unlink(f)
- try:
- shutil.rmtree('__pycache__')
- except OSError as error:
- if error.errno != errno.ENOENT:
- raise
+ rmtree('__pycache__')
class ImportTests(unittest.TestCase):
@@ -205,13 +199,6 @@
import test.support as y
self.assertTrue(y is test.support, y.__name__)
- def test_import_initless_directory_warning(self):
- with warnings.catch_warnings():
- # Just a random non-package directory we always expect to be
- # somewhere in sys.path...
- warnings.simplefilter('error', ImportWarning)
- self.assertRaises(ImportWarning, __import__, "site-packages")
-
def test_failing_reload(self):
# A failing reload should leave the module object in sys.modules.
source = TESTFN + os.extsep + "py"
@@ -337,8 +324,7 @@
unload(self.module_name)
unlink(self.file_name)
unlink(self.compiled_name)
- if os.path.exists(self.dir_name):
- shutil.rmtree(self.dir_name)
+ rmtree(self.dir_name)
def import_module(self):
ns = globals()
@@ -405,7 +391,7 @@
self.syspath = sys.path[:]
def tearDown(self):
- shutil.rmtree(self.path)
+ rmtree(self.path)
sys.path[:] = self.syspath
# Regression test for http://bugs.python.org/issue1293.
@@ -478,16 +464,13 @@
self.assertRaises(ValueError, check_relative)
def test_absolute_import_without_future(self):
- # If absolute import syntax is used, then do not try to perform
- # a relative import in the face of failure.
+ # If explicit relative import syntax is used, then do not try
+ # to perform a relative import in the face of failure.
# Issue #7902.
- try:
+ with self.assertRaises(ImportError):
from .os import sep
- except ImportError:
- pass
- else:
self.fail("explicit relative import triggered an "
- "implicit relative import")
+ "implicit absolute import")
class OverridingImportBuiltinTests(unittest.TestCase):
def test_override_builtin(self):
@@ -596,7 +579,7 @@
def test_package___cached__(self):
# Like test___cached__ but for packages.
def cleanup():
- shutil.rmtree('pep3147')
+ rmtree('pep3147')
os.mkdir('pep3147')
self.addCleanup(cleanup)
# Touch the __init__.py
@@ -618,7 +601,7 @@
# Like test___cached__ but ensuring __cached__ when imported from a
# PEP 3147 pyc file.
def cleanup():
- shutil.rmtree('pep3147')
+ rmtree('pep3147')
os.mkdir('pep3147')
self.addCleanup(cleanup)
unload('pep3147.foo')
More information about the Python-checkins
mailing list