def test_find_module(self): self.assertTrue(find_module('celery')) imp = Mock() imp.return_value = None with self.assertRaises(NotAPackage): find_module('foo.bar.baz', imp=imp) self.assertTrue(find_module('celery.worker.request'))
def test_find_module(): assert find_module('celery') imp = Mock() imp.return_value = None with pytest.raises(NotAPackage): find_module('foo.bar.baz', imp=imp) assert find_module('celery.worker.request')
def test_find_module(): def imp_side_effect(module): if module == 'foo': return None else: raise ImportError(module) assert find_module('celery') imp = Mock() imp.side_effect = imp_side_effect with pytest.raises(NotAPackage) as exc_info: find_module('foo.bar.baz', imp=imp) assert exc_info.value.args[0] == 'foo' assert find_module('celery.worker.request')
def load_confmod(parser, confmod): # import here so we can fix the sys.path when running the script directly from openkongqi.conf import config_from_object if confmod is None: parser.print_help() sys.exit(1) try: find_module(confmod) except (ImportError, NotAPackage): sys.stderr.write("configuration parameter is not a module" "({})\n".format(confmod)) parser.print_help() sys.exit(1) mod = import_from_cwd(confmod) config_from_object(mod)
def test_find_module_pep420_namespace_package(tmp_path, monkeypatch): monkeypatch.chdir(str(tmp_path)) (tmp_path / 'pkg' / 'foo').mkdir(parents=True) (tmp_path / 'pkg' / 'foo' / '__init__.py').write_text('') (tmp_path / 'pkg' / 'foo' / 'bar.py').write_text('') with patch.dict(sys.modules): for modname in list(sys.modules): if modname == 'pkg' or modname.startswith('pkg.'): del sys.modules[modname] with pytest.raises(ImportError): find_module('pkg.missing') with pytest.raises(ImportError): find_module('pkg.foo.missing') assert find_module('pkg.foo.bar') with pytest.raises(NotAPackage) as exc_info: find_module('pkg.foo.bar.missing') assert exc_info.value.args[0] == 'pkg.foo.bar'
def find_module(self, module): return find_module(module)
def test_find_module(self): self.assertTrue(find_module("celery")) imp = Mock() imp.return_value = None with self.assertRaises(NotAPackage): find_module("foo.bar.baz", imp=imp)