Commit 27354cce authored by Florent Xicluna's avatar Florent Xicluna

Use test.support and unittest features. Fix duplicated test (bad merge in...

Use test.support and unittest features.  Fix duplicated test (bad merge in r79033).  Fix comment for issue #7902.
parent ad5b1df6
import builtins import builtins
import errno
import imp import imp
from importlib.test.import_ import test_relative_imports from importlib.test.import_ import test_relative_imports
from importlib.test.import_ import util as importlib_util from importlib.test.import_ import util as importlib_util
...@@ -7,7 +6,6 @@ import marshal ...@@ -7,7 +6,6 @@ import marshal
import os import os
import py_compile import py_compile
import random import random
import shutil
import stat import stat
import sys import sys
import unittest import unittest
...@@ -25,11 +23,7 @@ def remove_files(name): ...@@ -25,11 +23,7 @@ def remove_files(name):
name + ".pyw", name + ".pyw",
name + "$py.class"): name + "$py.class"):
unlink(f) unlink(f)
try: rmtree('__pycache__')
shutil.rmtree('__pycache__')
except OSError as error:
if error.errno != errno.ENOENT:
raise
class ImportTests(unittest.TestCase): class ImportTests(unittest.TestCase):
...@@ -205,13 +199,6 @@ class ImportTests(unittest.TestCase): ...@@ -205,13 +199,6 @@ class ImportTests(unittest.TestCase):
import test.support as y import test.support as y
self.assertTrue(y is test.support, y.__name__) 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): def test_failing_reload(self):
# A failing reload should leave the module object in sys.modules. # A failing reload should leave the module object in sys.modules.
source = TESTFN + os.extsep + "py" source = TESTFN + os.extsep + "py"
...@@ -337,8 +324,7 @@ func_filename = func.__code__.co_filename ...@@ -337,8 +324,7 @@ func_filename = func.__code__.co_filename
unload(self.module_name) unload(self.module_name)
unlink(self.file_name) unlink(self.file_name)
unlink(self.compiled_name) unlink(self.compiled_name)
if os.path.exists(self.dir_name): rmtree(self.dir_name)
shutil.rmtree(self.dir_name)
def import_module(self): def import_module(self):
ns = globals() ns = globals()
...@@ -405,7 +391,7 @@ class PathsTests(unittest.TestCase): ...@@ -405,7 +391,7 @@ class PathsTests(unittest.TestCase):
self.syspath = sys.path[:] self.syspath = sys.path[:]
def tearDown(self): def tearDown(self):
shutil.rmtree(self.path) rmtree(self.path)
sys.path[:] = self.syspath sys.path[:] = self.syspath
# Regression test for http://bugs.python.org/issue1293. # Regression test for http://bugs.python.org/issue1293.
...@@ -478,16 +464,13 @@ class RelativeImportTests(unittest.TestCase): ...@@ -478,16 +464,13 @@ class RelativeImportTests(unittest.TestCase):
self.assertRaises(ValueError, check_relative) self.assertRaises(ValueError, check_relative)
def test_absolute_import_without_future(self): def test_absolute_import_without_future(self):
# If absolute import syntax is used, then do not try to perform # If explicit relative import syntax is used, then do not try
# a relative import in the face of failure. # to perform a relative import in the face of failure.
# Issue #7902. # Issue #7902.
try: with self.assertRaises(ImportError):
from .os import sep from .os import sep
except ImportError:
pass
else:
self.fail("explicit relative import triggered an " self.fail("explicit relative import triggered an "
"implicit relative import") "implicit absolute import")
class OverridingImportBuiltinTests(unittest.TestCase): class OverridingImportBuiltinTests(unittest.TestCase):
def test_override_builtin(self): def test_override_builtin(self):
...@@ -596,7 +579,7 @@ class PycacheTests(unittest.TestCase): ...@@ -596,7 +579,7 @@ class PycacheTests(unittest.TestCase):
def test_package___cached__(self): def test_package___cached__(self):
# Like test___cached__ but for packages. # Like test___cached__ but for packages.
def cleanup(): def cleanup():
shutil.rmtree('pep3147') rmtree('pep3147')
os.mkdir('pep3147') os.mkdir('pep3147')
self.addCleanup(cleanup) self.addCleanup(cleanup)
# Touch the __init__.py # Touch the __init__.py
...@@ -618,7 +601,7 @@ class PycacheTests(unittest.TestCase): ...@@ -618,7 +601,7 @@ class PycacheTests(unittest.TestCase):
# Like test___cached__ but ensuring __cached__ when imported from a # Like test___cached__ but ensuring __cached__ when imported from a
# PEP 3147 pyc file. # PEP 3147 pyc file.
def cleanup(): def cleanup():
shutil.rmtree('pep3147') rmtree('pep3147')
os.mkdir('pep3147') os.mkdir('pep3147')
self.addCleanup(cleanup) self.addCleanup(cleanup)
unload('pep3147.foo') unload('pep3147.foo')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment