python类skipIf()的实例源码

testing.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testing.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
testutils.py 文件源码 项目:psycopg2-for-aws-lambda 作者: iwitaly 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def skipIf(cond, msg):
        def skipIf_(f):
            @wraps(f)
            def skipIf__(self):
                if cond:
                    with warnings.catch_warnings():
                        warnings.simplefilter('always', UserWarning)
                        warnings.warn(msg)
                    return
                else:
                    return f(self)
            return skipIf__
        return skipIf_
testutils.py 文件源码 项目:psycopg2-for-aws-lambda 作者: iwitaly 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def skip(msg):
        return skipIf(True, msg)
testutils.py 文件源码 项目:psycopg2-for-aws-lambda 作者: iwitaly 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def skipIf(cond, msg):
        def skipIf_(f):
            @wraps(f)
            def skipIf__(self):
                if cond:
                    with warnings.catch_warnings():
                        warnings.simplefilter('always', UserWarning)
                        warnings.warn(msg)
                    return
                else:
                    return f(self)
            return skipIf__
        return skipIf_
testutils.py 文件源码 项目:psycopg2-for-aws-lambda 作者: iwitaly 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def skip(msg):
        return skipIf(True, msg)
utils.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
utils.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def require_jinja2(test_func):
    """
    Decorator to enable a Jinja2 template engine in addition to the regular
    Django template engine for a test or skip it if Jinja2 isn't available.
    """
    test_func = skipIf(jinja2 is None, "this test requires jinja2")(test_func)
    test_func = override_settings(TEMPLATES=[{
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
    }, {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'APP_DIRS': True,
        'OPTIONS': {'keep_trailing_newline': True},
    }])(test_func)
    return test_func
utils.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
utils.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
test_e2e.py 文件源码 项目:packet-queue 作者: google 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def root_required(method):
  decorator = unittest.skipIf(os.getuid() != 0, 'root required')
  return decorator(method)
helper.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def with_requires(*requirements):
    """Run a test case only when given requirements are satisfied.

    .. admonition:: Example

       This test case runs only when `numpy>=1.10` is installed.

       >>> from cupy import testing
       ... class Test(unittest.TestCase):
       ...     @testing.with_requires('numpy>=1.10')
       ...     def test_for_numpy_1_10(self):
       ...         pass

    Args:
        requirements: A list of string representing requirement condition to
            run a given test case.

    """
    ws = pkg_resources.WorkingSet()
    try:
        ws.require(*requirements)
        skip = False
    except pkg_resources.ResolutionError:
        skip = True

    msg = 'requires: {}'.format(','.join(requirements))
    return unittest.skipIf(skip, msg)
attr.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def multi_gpu(gpu_num):
    """Decorator to indicate number of GPUs required to run the test.

    Tests can be annotated with this decorator (e.g., ``@multi_gpu(2)``) to
    declare number of GPUs required to run. When running tests, if
    ``CUPY_TEST_GPU_LIMIT`` environment variable is set to value greater
    than or equals to 0, test cases that require GPUs more than the limit will
    be skipped.
    """

    check_available()
    return unittest.skipIf(
        0 <= _gpu_limit and _gpu_limit < gpu_num,
        reason='{} GPUs required'.format(gpu_num))
test_base.py 文件源码 项目:Taigabot 作者: FrozenPigs 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_with_rw_repo(self, rw_repo):
        assert not rw_repo.config_reader("repository").getboolean("core", "bare")
        assert osp.isdir(osp.join(rw_repo.working_tree_dir, 'lib'))

    #@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes!  sometimes...")
common_imports.py 文件源码 项目:Taigabot 作者: FrozenPigs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def skipIf(condition, why,
               _skip=lambda test_method: None,
               _keep=lambda test_method: test_method):
        if condition:
            return _skip
        return _keep
testutils.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skip_if_windows(reason):
    """Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    """
    def decorator(func):
        return unittest.skipIf(
            platform.system() not in ['Darwin', 'Linux'], reason)(func)
    return decorator
py26compat.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skipIf(condition, reason):
        def skipper(func):
            def skip(*args, **kwargs):
                return
            if condition:
                return skip
            return func
        return skipper
tests_aula2.py 文件源码 项目:minicurso-python 作者: CalicoUFSC 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def test_likes(self):
        for i in range(10):
            x = map(str, list(range(i)))

            shuffle(x)

            self.assertEqual(aula2.likes(x), gabarito_aula2.likes(x)

    @unittest.skipIf('remove_duplicates' not in vars(aula2),
                     'Função "remove_duplicates" não foi encontrada')
    def test_remove_duplicates(self):
        for _ in range(40):
            t = [randint(0,5) for _ in range(randint(0, 30))]

            self.assertEqual(aula2.remove_duplicates(t), remove_duplicates(t))

    @unittest.skipIf('different_evenness' not in vars(aula2),
                     'Função "different_evenness" não foi encontrada')
    def test_different_evenness(self):
        for _ in range(40):
            testlen=randint(3,50)
            oddeven=randint(0,1)
            testmat=[randint(0,25)*2+oddeven for x in range(testlen)]
            solution=randint(1,testlen)
            testmat[solution-1]+=1
            testmat=(" ").join(map(str,testmat))
            self.assertEqual(different_evenness(testmat), solution)

if __name__ == '__main__':
    unittest.main(verbosity=2)
mod_pedalboard_converter_test.py 文件源码 项目:PluginsManager 作者: PedalPi 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def test_discover_system_effect(self):
        converter = self.mod_converter
        pedalboard_path = self.here / Path('teste.pedalboard')

        print(converter.get_pedalboard_info(pedalboard_path))
        pedalboard = converter.convert(pedalboard_path)
        print(pedalboard.json)

    #@unittest.skipIf('TRAVIS' in os.environ, 'Mod-ui not configured in Travis build')
test_fortiosapi_virsh.py 文件源码 项目:fortiosapi 作者: fortinet-solutions-cse 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_02getsystemglobal(self):
        resp = fgt.get('system','global', vdom="global")
        fortiversion = resp['version']
        self.assertEqual(resp['status'], 'success')

    #should put a test on version to disable if less than 5.6 don't work decoration 
    #@unittest.skipIf(Version(fgt.get_version()) < Version('5.6'),
    #                 "not supported with fortios before 5.6")


问题


面经


文章

微信
公众号

扫码关注公众号