def test_module(self):
name = '<module>'
- path = 'path/to/module'
+ path = os.path.join('', 'path', 'to', 'module')
mock = self.mocker({name: path})
with util.uncache(name):
module = mock.load_module(name)
def test_package(self):
name = '<pkg>'
- path = '/path/to/{}/__init__'.format(name)
+ path = os.path.join('path', 'to', name, '__init__')
mock = self.mocker({name: path})
with util.uncache(name):
module = mock.load_module(name)
def test_lacking_parent(self):
name = 'pkg.mod'
- path = 'path/to/pkg/mod'
+ path = os.path.join('path', 'to', 'pkg', 'mod')
mock = self.mocker({name: path})
with util.uncache(name):
module = mock.load_module(name)
def test_module_reuse(self):
name = 'mod'
- path = 'path/to/mod'
+ path = os.path.join('path', 'to', 'mod')
module = imp.new_module(name)
mock = self.mocker({name: path})
with util.uncache(name):
name = "mod"
module = imp.new_module(name)
module.blah = None
- mock = self.mocker({name: 'path/to/mod'})
+ mock = self.mocker({name: os.path.join('path', 'to', 'mod')})
mock.source = b"1/0"
with util.uncache(name):
sys.modules[name] = module
def test_unloadable(self):
name = "mod"
- mock = self.mocker({name: 'path/to/mod'})
+ mock = self.mocker({name: os.path.join('path', 'to', 'mod')})
mock.source = b"1/0"
with util.uncache(name):
self.assertRaises(ZeroDivisionError, mock.load_module, name)
def test_default_encoding(self):
# Should have no problems with UTF-8 text.
name = 'mod'
- mock = PyLoaderMock({name: 'path/to/mod'})
+ mock = PyLoaderMock({name: os.path.join('path', 'to', 'mod')})
source = 'x = "ü"'
mock.source = source.encode('utf-8')
returned_source = mock.get_source(name)
def test_decoded_source(self):
# Decoding should work.
name = 'mod'
- mock = PyLoaderMock({name: 'path/to/mod'})
+ mock = PyLoaderMock({name: os.path.join('path', 'to', 'mod')})
source = "# coding: Latin-1\nx='ü'"
assert source.encode('latin-1') != source.encode('utf-8')
mock.source = source.encode('latin-1')
@source_util.writes_bytecode
def run_test(self, dont_write_bytecode):
name = 'mod'
- mock = PyPycLoaderMock({name: 'path/to/mod'})
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')})
sys.dont_write_bytecode = dont_write_bytecode
with util.uncache(name):
mock.load_module(name)
name = 'mod'
bad_magic = b'\x00\x00\x00\x00'
assert bad_magic != imp.get_magic()
- mock = PyPycLoaderMock({name: 'path/to/mod'},
- {name: {'path': 'path/to/mod.bytecode',
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')},
+ {name: {'path': os.path.join('path', 'to',
+ 'mod.bytecode'),
'magic': bad_magic}})
with util.uncache(name):
mock.load_module(name)
# Bytecode with an older mtime should be regenerated.
name = 'mod'
old_mtime = PyPycLoaderMock.default_mtime - 1
- mock = PyPycLoaderMock({name: 'path/to/mod'},
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')},
{name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}})
with util.uncache(name):
mock.load_module(name)
# A bad magic number should lead to an ImportError.
name = 'mod'
bad_magic = b'\x00\x00\x00\x00'
- mock = PyPycLoaderMock({}, {name: {'path': 'path/to/mod',
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod'),
'magic': bad_magic}})
with util.uncache(name):
self.assertRaises(ImportError, mock.load_module, name)
def test_bad_bytecode(self):
# Bad code object bytecode should elad to an ImportError.
name = 'mod'
- mock = PyPycLoaderMock({}, {name: {'path': '/path/to/mod', 'bc': b''}})
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod'),
+ 'bc': b''}})
with util.uncache(name):
self.assertRaises(ImportError, mock.load_module, name)
def test_source_path_ImportError(self):
# An ImportError from source_path should trigger an ImportError.
name = 'mod'
- mock = PyPycLoaderMock({}, {name: {'path': 'path/to/mod'}})
+ mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
+ 'mod')}})
with util.uncache(name):
self.assertRaises(ImportError, mock.load_module, name)
def test_bytecode_path_ImportError(self):
# An ImportError from bytecode_path should trigger an ImportError.
name = 'mod'
- mock = PyPycLoaderMock({name: 'path/to/mod'})
+ mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')})
bad_meth = types.MethodType(raise_ImportError, mock)
mock.bytecode_path = bad_meth
with util.uncache(name):