2013-11-08 15:25:37 -04:00
|
|
|
from .. import util
|
2012-04-14 15:10:13 -03:00
|
|
|
|
2013-11-08 15:25:37 -04:00
|
|
|
machinery = util.import_importlib('importlib.machinery')
|
|
|
|
|
2009-01-17 20:24:28 -04:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
2013-11-08 15:25:37 -04:00
|
|
|
class PathHookTest:
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
"""Test the path hook for source."""
|
|
|
|
|
2012-04-22 20:58:33 -03:00
|
|
|
def path_hook(self):
|
2013-11-08 15:25:37 -04:00
|
|
|
return self.machinery.FileFinder.path_hook((self.machinery.SourceFileLoader,
|
|
|
|
self.machinery.SOURCE_SUFFIXES))
|
2012-04-22 20:58:33 -03:00
|
|
|
|
2009-01-17 20:24:28 -04:00
|
|
|
def test_success(self):
|
2014-05-09 15:32:57 -03:00
|
|
|
with util.create_modules('dummy') as mapping:
|
2012-04-22 20:58:33 -03:00
|
|
|
self.assertTrue(hasattr(self.path_hook()(mapping['.root']),
|
2016-05-10 19:21:03 -03:00
|
|
|
'find_spec'))
|
|
|
|
|
|
|
|
def test_success_legacy(self):
|
|
|
|
with util.create_modules('dummy') as mapping:
|
|
|
|
self.assertTrue(hasattr(self.path_hook()(mapping['.root']),
|
|
|
|
'find_module'))
|
2009-01-17 20:24:28 -04:00
|
|
|
|
2010-07-03 19:18:47 -03:00
|
|
|
def test_empty_string(self):
|
2016-05-10 19:21:03 -03:00
|
|
|
# The empty string represents the cwd.
|
|
|
|
self.assertTrue(hasattr(self.path_hook()(''), 'find_spec'))
|
|
|
|
|
|
|
|
def test_empty_string_legacy(self):
|
2010-07-03 19:18:47 -03:00
|
|
|
# The empty string represents the cwd.
|
2012-04-22 20:58:33 -03:00
|
|
|
self.assertTrue(hasattr(self.path_hook()(''), 'find_module'))
|
2010-07-03 19:18:47 -03:00
|
|
|
|
2014-05-16 14:40:40 -03:00
|
|
|
|
|
|
|
(Frozen_PathHookTest,
|
|
|
|
Source_PathHooktest
|
|
|
|
) = util.test_both(PathHookTest, machinery=machinery)
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-11-08 15:25:37 -04:00
|
|
|
unittest.main()
|