Factor out helper code from importlib.test.extension.test_path_hook.

This commit is contained in:
Brett Cannon 2009-02-07 02:06:43 +00:00
parent 36d1f3eb41
commit 534b2cd176
6 changed files with 21 additions and 42 deletions

View file

@ -1,31 +1,12 @@
import importlib
from . import util
import collections
import imp
from os import path
import sys
import unittest
PATH = None
EXT = None
FILENAME = None
NAME = '_testcapi'
_file_exts = [x[0] for x in imp.get_suffixes() if x[2] == imp.C_EXTENSION]
try:
for PATH in sys.path:
for EXT in _file_exts:
FILENAME = NAME + EXT
FILEPATH = path.join(PATH, FILENAME)
if path.exists(path.join(PATH, FILENAME)):
raise StopIteration
else:
PATH = EXT = FILENAME = FILEPATH = None
except StopIteration:
pass
del _file_exts
class PathHookTests(unittest.TestCase):
"""Test the path hook for extension modules."""
@ -38,7 +19,7 @@ def hook(self, entry):
def test_success(self):
# Path hook should handle a directory where a known extension module
# exists.
self.assert_(hasattr(self.hook(PATH), 'find_module'))
self.assert_(hasattr(self.hook(util.PATH), 'find_module'))
def test_main():