• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unittest2.skipUnless函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: only_run_with_partitioned_database

def only_run_with_partitioned_database(cls):
    """
    Only runs the test with the partitioned database settings.
    """
    skip_unless = skipUnless(
        settings.USE_PARTITIONED_DATABASE, 'Only applicable if sharding is setup'
    )
    return skip_unless(partitioned(cls))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:8,代码来源:utils.py


示例2: _importorskip

def _importorskip(modname, minversion=None):
    try:
        mod = importlib.import_module(modname)
        has = True
        if minversion is not None:
            if LooseVersion(mod.__version__) < LooseVersion(minversion):
                raise ImportError('Minimum version not satisfied')
    except ImportError:
        has = False
    # TODO: use pytest.skipif instead of unittest.skipUnless
    # Using `unittest.skipUnless` is a temporary workaround for pytest#568,
    # wherein class decorators stain inherited classes.
    # xref: xarray#1531, implemented in xarray #1557.
    func = unittest.skipUnless(has, reason='requires {}'.format(modname))
    return has, func
开发者ID:jcmgray,项目名称:xarray,代码行数:15,代码来源:__init__.py


示例3: int

else:
    log.info("Using Cassandra version: %s", CASSANDRA_VERSION)
    CCM_KWARGS["version"] = CASSANDRA_VERSION

if CASSANDRA_VERSION >= "2.2":
    default_protocol_version = 4
elif CASSANDRA_VERSION >= "2.1":
    default_protocol_version = 3
elif CASSANDRA_VERSION >= "2.0":
    default_protocol_version = 2
else:
    default_protocol_version = 1

PROTOCOL_VERSION = int(os.getenv("PROTOCOL_VERSION", default_protocol_version))

notprotocolv1 = unittest.skipUnless(PROTOCOL_VERSION > 1, "Protocol v1 not supported")
lessthenprotocolv4 = unittest.skipUnless(PROTOCOL_VERSION < 4, "Protocol versions 4 or greater not supported")
greaterthanprotocolv3 = unittest.skipUnless(PROTOCOL_VERSION >= 4, "Protocol versions less than 4 are not supported")

greaterthancass20 = unittest.skipUnless(CASSANDRA_VERSION >= "2.1", "Cassandra version 2.1 or greater required")
greaterthanorequalcass30 = unittest.skipUnless(CASSANDRA_VERSION >= "3.0", "Cassandra version 3.0 or greater required")
lessthancass30 = unittest.skipUnless(CASSANDRA_VERSION < "3.0", "Cassandra version less then 3.0 required")


def get_cluster():
    return CCM_CLUSTER


def get_node(node_id):
    return CCM_CLUSTER.nodes["node%s" % node_id]
开发者ID:heqing90,项目名称:python-driver,代码行数:30,代码来源:__init__.py


示例4: TestBreakDefaultIntHandler

@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
    "if threads have been used")
class TestBreakDefaultIntHandler(TestBreak):
    int_handler = signal.default_int_handler

@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
    "if threads have been used")
class TestBreakSignalIgnored(TestBreak):
    int_handler = signal.SIG_IGN

@unittest.skipUnless(hasattr(os, 'kill'), "Test requires os.kill")
@unittest.skipIf(sys.platform =="win32", "Test cannot run on Windows")
@unittest.skipIf(sys.platform == 'freebsd6', "Test kills regrtest on freebsd6 "
    "if threads have been used")
class TestBreakSignalDefault(TestBreak):
    int_handler = signal.SIG_DFL


# Should also skip some tests on Jython
skipper = unittest2.skipUnless(hasattr(os, 'kill') and signal is not None,
                               "test uses os.kill(...) and the signal module")
skipper2 = unittest2.skipIf(sys.platform == 'win32', "can't run on windows")

TestBreak = skipper(skipper2(TestBreak))

if __name__ == '__main__':
    unittest2.main()
开发者ID:anupkrish24,项目名称:kaLLogs,代码行数:30,代码来源:test_break.py


示例5: cyimport

# limitations under the License.

from cassandra.cython_deps import HAVE_CYTHON, HAVE_NUMPY

if HAVE_CYTHON:
    import pyximport
    pyximport.install()

try:
    import unittest2 as unittest
except ImportError:
    import unittest  # noqa

def cyimport(import_path):
    """
    Import a Cython module if available, otherwise return None
    (and skip any relevant tests).
    """
    try:
        return __import__(import_path, fromlist=[True])
    except ImportError:
        if HAVE_CYTHON:
            raise
        return None


# @cythontest
# def test_something(self): ...
cythontest = unittest.skipUnless(HAVE_CYTHON, 'Cython is not available')
numpytest  = unittest.skipUnless(HAVE_CYTHON and HAVE_NUMPY, 'NumPy is not available')
开发者ID:bbirand,项目名称:python-driver,代码行数:30,代码来源:utils.py


示例6: check_rd201012

def check_rd201012():
    import rdkit.rdBase
    from rdkit.rdBase import rdkitVersion
    assert rdkitVersion[:7] == "2010.12", rdkitVersion

def check_rd201112_svn():
    import rdkit.rdBase
    from rdkit.rdBase import rdkitVersion
    assert rdkitVersion[:7] == "2011.12", rdkitVersion

def _check(required):
    req = required.split()
    for name in versions:
        if name in req:
            return
    raise AssertionError("Missing one of %r: %r" % (required, versions))

class TestToxVersion(unittest2.TestCase):
    def test_enough_specifications(self):
        _check("x32 x64")
        _check("py25 py26 py27 py32")
        _check("oe174 oe2011Oct ob223 ob230 ob23svn1 rd201106 rd201103 rd201012 rd201112_svn")
        
    def test_version(self):
        for name in versions:
            func = globals()["check_" + name]
            func()

TestToxVersion = unittest2.skipUnless(envstr, "Not building under the tox environment")(
    TestToxVersion)
开发者ID:llazzaro,项目名称:chem-fingerprints,代码行数:30,代码来源:test_tox_version.py


示例7: monkey_patch

if "gevent" in EVENT_LOOP_MANAGER:
    import gevent.monkey
    gevent.monkey.patch_all()
    from cassandra.io.geventreactor import GeventConnection
    connection_class = GeventConnection
elif "eventlet" in EVENT_LOOP_MANAGER:
    from eventlet import monkey_patch
    monkey_patch()

    from cassandra.io.eventletreactor import EventletConnection
    connection_class = EventletConnection
elif "async" in EVENT_LOOP_MANAGER:
    from cassandra.io.asyncorereactor import AsyncoreConnection
    connection_class = AsyncoreConnection
elif "twisted" in EVENT_LOOP_MANAGER:
    from cassandra.io.twistedreactor import TwistedConnection
    connection_class = TwistedConnection

else:
    try:
        from cassandra.io.libevreactor import LibevConnection
        connection_class = LibevConnection
    except ImportError:
        connection_class = None


MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False))

notwindows = unittest.skipUnless(not "Windows" in platform.system(), "This test is not adequate for windows")
notpypy = unittest.skipUnless(not platform.python_implementation() == 'PyPy', "This tests is not suitable for pypy")
notmonkeypatch = unittest.skipUnless(MONKEY_PATCH_LOOP, "Skipping this test because monkey patching is required")
开发者ID:stonefly,项目名称:python-driver,代码行数:31,代码来源:__init__.py


示例8: skip_unless_words

def skip_unless_words(func):
    return unittest2.skipUnless(
        os.path.isfile(words_file),
        'Cannot find system words file {}'.format(words_file)
    )(func)
开发者ID:alex2,项目名称:vorlauf,代码行数:5,代码来源:test.py


示例9: TestConcrete

import os
import sys
try:
    import unittest2 as unittest
except ImportError:
    import unittest

from rpaths import unicode, Path, PosixPath, WindowsPath


windows_only = unittest.skipUnless(issubclass(Path, WindowsPath),
                                   "Only runs on Windows")
posix_only = unittest.skipUnless(issubclass(Path, PosixPath),
                                 "Only runs on POSIX")


class TestConcrete(unittest.TestCase):
    """Tests for Path.

    Because this tests the concrete Path, it needs to be run on both Windows
    and POSIX to ensure everything is correct.
    """
    def test_cwd(self):
        """Tests cwd, in_dir."""
        cwd = os.getcwd()

        if os.name == 'nt' and isinstance(cwd, bytes):
            cwd = cwd.decode('mbcs')
        elif os.name != 'nt' and isinstance(cwd, unicode):
            cwd = cwd.encode(sys.getfilesystemencoding())
        self.assertEqual(Path.cwd().path, cwd)
开发者ID:VnC-,项目名称:rpaths,代码行数:31,代码来源:test_concrete.py


示例10: TestGitWorkingCopy

class TestGitWorkingCopy(unittest.TestCase, BaseTestWorkingCopy):
    
    def setUp(self):
        self.repository_path = os.path.abspath("../example_repositories/git")
        os.symlink("%s/git" % self.repository_path, "%s/.git" % self.repository_path)
        self.repos = GitRepository(self.repository_path)
        self.tmpdir = tempfile.mkdtemp()
        self.repos.checkout(self.tmpdir)
        self.wc = GitWorkingCopy(self.tmpdir)
        self.latest_version = "38598c93c7036a1c44bbb6075517243edfa88860"
        self.previous_version = "3491ce1d9a66abc9d49d5844ee05167c6a854ad9"
        
    def tearDown(self):
        os.unlink("%s/.git" % self.repository_path)
        shutil.rmtree(self.tmpdir)
TestGitWorkingCopy = unittest.skipUnless(have_git, "Could not import git")(TestGitWorkingCopy) # not using as class decorator for the sake of Python 2.5


#@unittest.skipUnless(have_pysvn, "Could not import pysvn")
class TestSubversionWorkingCopy(unittest.TestCase, BaseTestWorkingCopy):
    
    def setUp(self):
        self.repository_path = os.path.abspath("../example_repositories/subversion")
        self.repos = SubversionRepository("file://%s" % self.repository_path)
        self.tmpdir = tempfile.mkdtemp()
        self.repos.checkout(self.tmpdir)
        self.wc = SubversionWorkingCopy(self.tmpdir)
        self.latest_version = "3"
        self.previous_version = "1"
        
    def tearDown(self):
开发者ID:dcherian,项目名称:sumatra,代码行数:31,代码来源:test_versioncontrol.py


示例11: int

PROTOCOL_VERSION = int(os.getenv('PROTOCOL_VERSION', default_protocol_version))


def local_decorator_creator():
    if not CASSANDRA_IP.startswith("127.0.0."):
        return unittest.skip('Tests only runs against local C*')

    def _id_and_mark(f):
        f.local = True
        return f

    return _id_and_mark

local = local_decorator_creator()
notprotocolv1 = unittest.skipUnless(PROTOCOL_VERSION > 1, 'Protocol v1 not supported')
lessthenprotocolv4 = unittest.skipUnless(PROTOCOL_VERSION < 4, 'Protocol versions 4 or greater not supported')
greaterthanprotocolv3 = unittest.skipUnless(PROTOCOL_VERSION >= 4, 'Protocol versions less than 4 are not supported')
protocolv5 = unittest.skipUnless(5 in get_supported_protocol_versions(), 'Protocol versions less than 5 are not supported')

greaterthancass20 = unittest.skipUnless(CASSANDRA_VERSION >= Version('2.1'), 'Cassandra version 2.1 or greater required')
greaterthancass21 = unittest.skipUnless(CASSANDRA_VERSION >= Version('2.2'), 'Cassandra version 2.2 or greater required')
greaterthanorequalcass30 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.0'), 'Cassandra version 3.0 or greater required')
greaterthanorequalcass36 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.6'), 'Cassandra version 3.6 or greater required')
greaterthanorequalcass3_10 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.10'), 'Cassandra version 3.10 or greater required')
greaterthanorequalcass3_11 = unittest.skipUnless(CASSANDRA_VERSION >= Version('3.11'), 'Cassandra version 3.10 or greater required')
greaterthanorequalcass40 = unittest.skipUnless(CASSANDRA_VERSION >= Version('4.0'), 'Cassandra version 4.0 or greater required')
lessthanorequalcass40 = unittest.skipIf(CASSANDRA_VERSION >= Version('4.0'), 'Cassandra version 4.0 or greater required')
lessthancass30 = unittest.skipUnless(CASSANDRA_VERSION < Version('3.0'), 'Cassandra version less then 3.0 required')
pypy = unittest.skipUnless(platform.python_implementation() == "PyPy", "Test is skipped unless it's on PyPy")
notpy3 = unittest.skipIf(sys.version_info >= (3, 0), "Test not applicable for Python 3.x runtime")
开发者ID:datastax,项目名称:python-driver,代码行数:30,代码来源:__init__.py


示例12: ProductEnvironment

            self._load_product_from_data(self.global_env, self.default_product)
            self._env = env = ProductEnvironment(
                    self.global_env, self.default_product)
        return env

    @env.setter
    def env(self, value):
        pass

    def setUp(self):
        test_pygments.PygmentsRendererTestCase.setUp(self)
        self.pygments = Mimeview(self.env).renderers[0]

    def tearDown(self):
        self.global_env.reset_db()
        self.global_env = self._env = None

ProductPygmentsRendererTestCase = unittest.skipUnless(
        test_pygments.have_pygments, 
        'mimeview/tests/pygments (no pygments installed)'
    )(ProductPygmentsRendererTestCase)

def test_suite():
    return unittest.TestSuite([
            unittest.makeSuite(ProductPygmentsRendererTestCase,'test'),
        ])

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')

开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:29,代码来源:pygments.py


示例13: dict

        errors = data['validation_errors']
        self.assertIn('email', errors)
        self.assertIn('enter a value', errors['email'].lower())

        # everything required is now provided
        person = dict(name='Jeffrey', email='[email protected]', age=24)
        response = self.app.post('/api/test', data=dumps(person))
        self.assertEqual(response.status_code, 201)
        personid = loads(response.data)['id']

        # check that the provided field values are in there
        response = self.app.get('/api/test/' + str(personid))
        self.assertEqual(response.status_code, 200)
        data = loads(response.data)
        self.assertEqual(data['name'], 'Jeffrey')
        self.assertEqual(data['email'], '[email protected]')


# skipUnless should be used as a decorator, but Python 2.5 doesn't have
# decorators.
SAVTest = skipUnless(has_savalidation and sav_version >= (0, 2),
                     'savalidation not found.')(SAVTest)


def load_tests(loader, standard_tests, pattern):
    """Returns the test suite for this module."""
    suite = TestSuite()
    suite.addTest(loader.loadTestsFromTestCase(SimpleValidationTest))
    suite.addTest(loader.loadTestsFromTestCase(SAVTest))
    return suite
开发者ID:ewang,项目名称:flask-restless,代码行数:30,代码来源:test_validation.py


示例14: hasattr

import os
from functools import partial

try:
    import unittest2 as unittest
except ImportError:
    import unittest

if not hasattr(unittest, "skipUnless"):
    raise Exception("Please install unittest2 package (unittest.skipUnless attribute is missing)")

SKLIK_LOGIN = os.environ.get("SKLIK_LOGIN")
SKLIK_PASSWORD = os.environ.get("SKLIK_PASSWORD")

SKLIK_BAJAJA_URL = "https://api.sklik.cz/sandbox/bajaja/RPC2"
SKLIK_CIPISEK_URL = "https://api.sklik.cz/sandbox/cipisek/RPC2"


only_with_login = partial(
    unittest.skipUnless(SKLIK_LOGIN and SKLIK_PASSWORD, "SKLIK_LOGIN or SKLIK_PASSWORD environment var not set")
)


def get_client(cls, url=SKLIK_CIPISEK_URL):
    return cls(url, SKLIK_LOGIN, SKLIK_PASSWORD, debug=False)
开发者ID:mergado,项目名称:sklik-api-client-python,代码行数:25,代码来源:__init__.py


示例15: is_windows

    from cassandra.io.twistedreactor import TwistedConnection
    connection_class = TwistedConnection
elif "asyncio" in EVENT_LOOP_MANAGER:
    from cassandra.io.asyncioreactor import AsyncioConnection
    connection_class = AsyncioConnection

else:
    try:
        from cassandra.io.libevreactor import LibevConnection
        connection_class = LibevConnection
    except ImportError:
        connection_class = None


# If set to to true this will force the Cython tests to run regardless of whether they are installed
cython_env = os.getenv('VERIFY_CYTHON', "False")


VERIFY_CYTHON = False

if(cython_env == 'True'):
    VERIFY_CYTHON = True


def is_windows():
    return "Windows" in platform.system()


notwindows = unittest.skipUnless(not is_windows(), "This test is not adequate for windows")
notpypy = unittest.skipUnless(not platform.python_implementation() == 'PyPy', "This tests is not suitable for pypy")
开发者ID:datastax,项目名称:python-driver,代码行数:30,代码来源:__init__.py


示例16: loads

        self.assertEqual(200, response.status_code)
        data = loads(response.data)
        self.assertEqual(2, len(data["pets"]))
        for pet in data["pets"]:
            self.assertEqual(owner.id, pet["ownerid"])

        response = self.app.get("/api/lazy_pet/1")
        self.assertEqual(200, response.status_code)
        data = loads(response.data)
        self.assertFalse(isinstance(data["owner"], list))
        self.assertEqual(owner.id, data["ownerid"])


# skipUnless should be used as a decorator, but Python 2.5 doesn't have
# decorators.
FSATest = skipUnless(has_flask_sqlalchemy, "Flask-SQLAlchemy not found.")(FSAModelTest)


class ModelTestCase(TestSupport):
    """Provides tests for helper functions which operate on pure SQLAlchemy
    models.

    """

    def test_get_columns(self):
        """Test for getting the names of columns as strings."""
        columns = _get_columns(self.Person)
        self.assertEqual(sorted(columns.keys()), sorted(["age", "birth_date", "computers", "id", "name", "other"]))

    def test_get_relations(self):
        """Tests getting the names of the relations of a model as strings."""
开发者ID:titansgroup,项目名称:flask-restless,代码行数:31,代码来源:test_views.py


示例17: object

else:
    import unittest
import logbook
import six

_missing = object()


def get_total_delta_seconds(delta):
    """
    Replacement for datetime.timedelta.total_seconds() for Python 2.5, 2.6 and 3.1
    """
    return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 10**6) / 10**6


require_py3 = unittest.skipUnless(six.PY3, "Requires Python 3")
def require_module(module_name):
    try:
        __import__(module_name)
    except ImportError:
        return unittest.skip("Requires the %r module" % (module_name,))
    return lambda func: func

class LogbookTestSuite(unittest.TestSuite):
    pass

class LogbookTestCase(unittest.TestCase):
    def setUp(self):
        self.log = logbook.Logger('testlogger')

# silence deprecation warning displayed on Py 3.2
开发者ID:Zecterma,项目名称:logbook,代码行数:31,代码来源:utils.py


示例18: int

            log.info("Using DSE credentials file located at {0}".format(DSE_CRED))
            CCM_KWARGS['dse_credentials_file'] = DSE_CRED


if CASSANDRA_VERSION >= '2.2':
    default_protocol_version = 4
elif CASSANDRA_VERSION >= '2.1':
    default_protocol_version = 3
elif CASSANDRA_VERSION >= '2.0':
    default_protocol_version = 2
else:
    default_protocol_version = 1

PROTOCOL_VERSION = int(os.getenv('PROTOCOL_VERSION', default_protocol_version))

notprotocolv1 = unittest.skipUnless(PROTOCOL_VERSION > 1, 'Protocol v1 not supported')
lessthenprotocolv4 = unittest.skipUnless(PROTOCOL_VERSION < 4, 'Protocol versions 4 or greater not supported')
greaterthanprotocolv3 = unittest.skipUnless(PROTOCOL_VERSION >= 4, 'Protocol versions less than 4 are not supported')

greaterthancass20 = unittest.skipUnless(CASSANDRA_VERSION >= '2.1', 'Cassandra version 2.1 or greater required')
greaterthanorequalcass30 = unittest.skipUnless(CASSANDRA_VERSION >= '3.0', 'Cassandra version 3.0 or greater required')
lessthancass30 = unittest.skipUnless(CASSANDRA_VERSION < '3.0', 'Cassandra version less then 3.0 required')


def get_cluster():
    return CCM_CLUSTER


def get_node(node_id):
    return CCM_CLUSTER.nodes['node%s' % node_id]
开发者ID:mklew,项目名称:python-driver,代码行数:30,代码来源:__init__.py


示例19: skipSlowTest

def skipSlowTest():
    return skipUnless(os.environ.get('PYCHEF_SLOW_TESTS'), 'slow tests skipped, set $PYCHEF_SLOW_TESTS=1 to enable')
开发者ID:calebgroom,项目名称:pychef,代码行数:2,代码来源:__init__.py


示例20: TempDir

# See the License for the specific language governing permissions and
# limitations under the License.

"""Various utilities used in tests."""

import contextlib
import os
import tempfile
import shutil
import sys

import six
import unittest2


RunOnlyOnPython27 = unittest2.skipUnless(sys.version_info[:2] == (2, 7), "Only runs in Python 2.7")


@contextlib.contextmanager
def TempDir(change_to=False):
    if change_to:
        original_dir = os.getcwd()
    path = tempfile.mkdtemp()
    try:
        if change_to:
            os.chdir(path)
        yield path
    finally:
        if change_to:
            os.chdir(original_dir)
        shutil.rmtree(path)
开发者ID:sushanthpy,项目名称:apitools,代码行数:31,代码来源:test_utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unittest2.TestCase类代码示例发布时间:2022-05-27
下一篇:
Python unittest2.skipIf函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap