コード例 #1
0
    def __init__(cls, what, bases=None, dict_=None):  # noqa
        if '__depends_on__' in dict_:
            mod_names, package_names = parse_mod_deps(dict_['__depends_on__'])
            mods_exist = [module_exists(m) for m in mod_names]

            if not all(mods_exist):
                missing_pkgs = [p for p, x in zip(package_names, mods_exist)
                                if not x]
                if len(missing_pkgs) > 1:
                    error_msg = '{} depends on missing [{}] packages.'.format(
                        cls.__name__, ", ".join(missing_pkgs))
                else:
                    error_msg = '{} depends on missing "{}" package.'.format(
                        cls.__name__, missing_pkgs[0])

                def _apply(cls, args, run):
                    raise ImportError(error_msg)
                cls.__doc__ = '( ' + error_msg + ')'
                cls.apply = classmethod(_apply)
                cls._enabled = False

        type.__init__(cls, what, bases, dict_)
コード例 #2
0
    def __init__(cls, what, bases=None, dict_=None):  # noqa
        if '__depends_on__' in dict_:
            mod_names, package_names = parse_mod_deps(dict_['__depends_on__'])
            mods_exist = [module_exists(m) for m in mod_names]

            if not all(mods_exist):
                missing_pkgs = [p for p, x in zip(package_names, mods_exist)
                                if not x]
                if len(missing_pkgs) > 1:
                    error_msg = '{} depends on missing [{}] packages.'.format(
                        cls.__name__, ", ".join(missing_pkgs))
                else:
                    error_msg = '{} depends on missing "{}" package.'.format(
                        cls.__name__, missing_pkgs[0])

                def _apply(cls, args, run):
                    raise ImportError(error_msg)
                cls.__doc__ = '( ' + error_msg + ')'
                cls.apply = classmethod(_apply)
                cls._enabled = False

        type.__init__(cls, what, bases, dict_)
コード例 #3
0
def test_module_exists_does_not_import_module():
    assert module_exists("tests.donotimport")
コード例 #4
0
def test_module_exists_base_level_modules():
    assert module_exists("pytest")
    assert not module_exists("clearly_non_existing_module_name")
コード例 #5
0
ファイル: test_utils.py プロジェクト: namanUIUC/sacred
def test_module_exists_base_level_modules():
    assert module_exists('pytest')
    assert not module_exists('clearly_non_existing_module_name')
コード例 #6
0
ファイル: test_utils.py プロジェクト: elanmart/sacred
def test_module_exists_does_not_import_module():
    assert module_exists('tests.donotimport')
コード例 #7
0
ファイル: test_utils.py プロジェクト: elanmart/sacred
def test_module_exists_base_level_modules():
    assert module_exists('pytest')
    assert not module_exists('clearly_non_existing_module_name')