当前位置: 首页>>代码示例>>Python>>正文


Python unittest.skipUnless函数代码示例

本文整理汇总了Python中unittest.skipUnless函数的典型用法代码示例。如果您正苦于以下问题:Python skipUnless函数的具体用法?Python skipUnless怎么用?Python skipUnless使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了skipUnless函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_tarball

    def _make_tarball(self, target_name):
        tmpdir = self.mkdtemp()
        self.write_file([tmpdir, 'file1'], 'xxx')
        self.write_file([tmpdir, 'file2'], 'xxx')
        os.mkdir(os.path.join(tmpdir, 'sub'))
        self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
        tmpdir2 = self.mkdtemp()
        unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0], 'source and target should be on same drive')
        base_name = os.path.join(tmpdir2, target_name)
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            make_tarball(splitdrive(base_name)[1], '.')
        finally:
            os.chdir(old_dir)

        tarball = base_name + '.tar.gz'
        self.assertTrue(os.path.exists(tarball))
        base_name = os.path.join(tmpdir2, target_name)
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            make_tarball(splitdrive(base_name)[1], '.', compress=None)
        finally:
            os.chdir(old_dir)

        tarball = base_name + '.tar'
        self.assertTrue(os.path.exists(tarball))
        return
开发者ID:webiumsk,项目名称:WOT-0.9.12-CT,代码行数:29,代码来源:test_archive_util.py

示例2: _make_tarball

    def _make_tarball(self, tmpdir, target_name, suffix, **kwargs):
        tmpdir2 = self.mkdtemp()
        unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
                            "source and target should be on same drive")

        base_name = os.path.join(tmpdir2, target_name)

        # working with relative paths to avoid tar warnings
        with change_cwd(tmpdir):
            make_tarball(splitdrive(base_name)[1], 'dist', **kwargs)

        # check if the compressed tarball was created
        tarball = base_name + suffix
        self.assertTrue(os.path.exists(tarball))
        self.assertEqual(self._tarinfo(tarball), self._created_files)
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:15,代码来源:test_archive_util.py

示例3: skip_if_missing_requirements

def skip_if_missing_requirements(*requirements):
    try:
        pkg_resources.require(*requirements)
        msg = ''
    except pkg_resources.DistributionNotFound:
        msg = 'Missing one or more requirements (%s)' % '|'.join(requirements)
    return skipUnless(msg == '', msg)
开发者ID:chrissamuel,项目名称:karaage,代码行数:7,代码来源:integration.py

示例4: create_simple_test_method

def create_simple_test_method(validator, expected, value, num):
    if expected is not None and issubclass(expected, Exception):
        test_mask = 'test_%s_raises_error_%d'

        def test_func(self):
            # assertRaises not used, so as to be able to produce an error message
            # containing the tested value
            try:
                validator(value)
            except expected:
                pass
            else:
                self.fail("%s not raised when validating '%s'" % (
                    expected.__name__, value))
    else:
        test_mask = 'test_%s_%d'

        def test_func(self):
            try:
                self.assertEqual(expected, validator(value))
            except ValidationError as e:
                self.fail("Validation of '%s' failed. Error message was: %s" % (
                    value, str(e)))
    if isinstance(validator, types.FunctionType):
        val_name = validator.__name__
    else:
        val_name = validator.__class__.__name__
    test_name = test_mask % (val_name, num)
    if validator is validate_image_file_extension:
        SKIP_MSG = "Pillow is required to test validate_image_file_extension"
        test_func = skipUnless(PILLOW_IS_INSTALLED, SKIP_MSG)(test_func)
    return test_name, test_func
开发者ID:AMontagu,项目名称:django,代码行数:32,代码来源:tests.py

示例5: make_reviewed

def make_reviewed(fn):
    """
    Just setting the WIDGY_MEZZANINE_SITE is not enough during tests, because
    WidgyPage.root_node has been set to point to VersionTracker.  We have to
    manually point it to ReviewedVersionTracker.  We do this only in tests
    because on a normal run, you are never going to be changing what models a
    ForeignKey points to (I would hope).
    """
    from widgy.contrib.widgy_mezzanine.admin import publish_page_on_approve

    site = reviewed_widgy_site
    rel = WidgyPage._meta.get_field('root_node').rel
    old_model = rel.model
    dispatch_uid = str(uuid.uuid4())

    fn = override_settings(WIDGY_MEZZANINE_SITE=site)(fn)
    fn = skipUnless(REVIEW_QUEUE_INSTALLED, 'review_queue is not installed')(fn)

    def up():
        # BBB Django 1.8 compatiblity
        if django.VERSION < (1, 9):
            rel.to = site.get_version_tracker_model()
        else:
            rel.model = site.get_version_tracker_model()
        post_save.connect(publish_page_on_approve,
                          sender=site.get_version_tracker_model().commit_model,
                          dispatch_uid=dispatch_uid)

    def down():
        # BBB Django 1.8 compatiblity
        if django.VERSION < (1, 9):
            rel.to = old_model
        else:
            rel.model = old_model
        post_save.disconnect(dispatch_uid=dispatch_uid)

    if isinstance(fn, type):
        old_pre_setup = fn._pre_setup
        old_post_teardown = fn._post_teardown

        def _pre_setup(self):
            up()
            old_pre_setup(self)

        def _post_teardown(self):
            old_post_teardown(self)
            down()

        fn._pre_setup = _pre_setup
        fn._post_teardown = _post_teardown

        return fn
    else:
        def change_foreign_key(*args, **kwargs):
            up()
            try:
                return fn(*args, **kwargs)
            finally:
                down()
        return change_foreign_key
开发者ID:DjangoBD,项目名称:django-widgy,代码行数:60,代码来源:test_core.py

示例6: add_test_based_on_test_class

 def add_test_based_on_test_class(class_, **attr):
     attr.update(create_storage=create_storage)
     new_class = class_.__class__(
         prefix + class_.__name__, (class_, ),
         attr,
         )
     new_class = unittest.skipUnless(storage_is_available, "Storage not available")(new_class)
     suite.addTest(unittest.makeSuite(new_class))
开发者ID:zodb,项目名称:relstorage,代码行数:8,代码来源:testblob.py

示例7: skipUnlessDom0

def skipUnlessDom0(test_item):
    '''Decorator that skips test outside dom0.

    Some tests (especially integration tests) have to be run in more or less
    working dom0. This is checked by connecting to libvirt.
    ''' # pylint: disable=invalid-name

    return unittest.skipUnless(in_dom0, 'outside dom0')(test_item)
开发者ID:v6ak,项目名称:qubes-core-admin,代码行数:8,代码来源:__init__.py

示例8: skipUnlessGit

def skipUnlessGit(test_item):
    '''Decorator that skips test outside git repo.

    There are very few tests that an be run only in git. One example is
    correctness of example code that won't get included in RPM.
    ''' # pylint: disable=invalid-name

    return unittest.skipUnless(in_git, 'outside git tree')(test_item)
开发者ID:v6ak,项目名称:qubes-core-admin,代码行数:8,代码来源:__init__.py

示例9: skip_unless_master

def skip_unless_master(func_or_class):
    """
    Only run the decorated test for code on master or destined for master.

    Use this to skip tests that we expect to fail on a named release branch.
    Please use carefully!
    """
    return unittest.skipUnless(RELEASE_LINE == "master", "Test often fails on named releases")(func_or_class)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:8,代码来源:release.py

示例10: requires_docker_image

def requires_docker_image(image_name):
    """
    Mark a test as requiring a Docker image to run.
    """

    return unittest.skipUnless(
        docker_image_available(image_name),
        "Docker image {0} is required.".format(image_name)
    )
开发者ID:infoxchange,项目名称:docker-forklift,代码行数:9,代码来源:base.py

示例11: skip_unless_pacemaker_features

def skip_unless_pacemaker_features(version_tuple, feature):
    return skipUnless(
        is_minimum_pacemaker_features(*version_tuple),
        "Pacemaker must support feature set version {version} to test {feature}"
            .format(
                version=format_version(version_tuple),
                feature=feature
            )
    )
开发者ID:tomjelinek,项目名称:pcs,代码行数:9,代码来源:misc.py

示例12: skipUnlessEnv

def skipUnlessEnv(varname):
    '''Decorator generator for skipping tests without environment variable set.

    Some tests require working X11 display, like those using GTK library, which
    segfaults without connection to X.
    Other require their own, custom variables.
    '''

    return unittest.skipUnless(os.getenv(varname), 'no {} set'.format(varname))
开发者ID:ttasket,项目名称:qubes-core-admin,代码行数:9,代码来源:__init__.py

示例13: get_installed_locales

    def get_installed_locales(self, codes, msg=None):
        def normalize(code):
            # OS X and Ubuntu (at the very least) differ slightly in locale code formatting
            return code.strip().replace("-", "").lower()

        try:
            installed_codes = dict(((normalize(code), code) for
                                    code in subprocess.check_output(["locale", "-a"]).split()))
        except (subprocess.CalledProcessError, OSError):
            raise unittest.SkipTest("locale command not available, cannot test")

        if msg is None:
            msg = "One of %s tested locales is not installed" % (codes,)
        available_codes = []
        for code in codes:
            if normalize(code) in installed_codes:
                available_codes.append(installed_codes[normalize(code)])
        unittest.skipUnless(available_codes, msg)
        return available_codes
开发者ID:Stewori,项目名称:jython,代码行数:19,代码来源:test_os_jy.py

示例14: skip_if_not_supported

 def skip_if_not_supported(y):
     msg = "strftime() is limited to [1; 9999] with Visual Studio"
     # Check that it doesn't crash for year > 9999
     try:
         time.strftime('%Y', (y,) + (0,) * 8)
     except ValueError:
         cond = False
     else:
         cond = True
     return unittest.skipUnless(cond, msg)
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:10,代码来源:test_time.py

示例15: skipUnlessImported

def skipUnlessImported(module, obj):
    import importlib
    try:
        m = importlib.import_module(module)
    except ImportError:
        m = None
    return unittest.skipUnless(
        obj in dir(m),
        "Skipping test because {} could not be imported from {}".format(
            obj, module))
开发者ID:AdamUnger,项目名称:incubator-airflow,代码行数:10,代码来源:tests.py


注:本文中的unittest.skipUnless函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。