示例#1
0
 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'))
示例#2
0
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')
示例#3
0
 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'))
示例#4
0
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')
示例#5
0
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')
示例#6
0
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)
示例#7
0
文件: bin.py 项目: gams/openkongqi
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)
示例#8
0
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'
示例#9
0
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'
示例#10
0
 def find_module(self, module):
     return find_module(module)
示例#11
0
 def find_module(self, module):
     return find_module(module)
示例#12
0
 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)
示例#13
0
 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)