python类skipUnless()的实例源码

test_archive_util.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _make_tarball(self, target_name):
        # creating something to tar
        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)

        # working with relative paths to avoid tar warnings
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            make_tarball(splitdrive(base_name)[1], '.')
        finally:
            os.chdir(old_dir)

        # check if the compressed tarball was created
        tarball = base_name + '.tar.gz'
        self.assertTrue(os.path.exists(tarball))

        # trying an uncompressed one
        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))
test_xpickle.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_unicode(self):
        if not test_support.have_unicode:
            # Python 2.5 has no unittest.skipUnless
            self.skipTest('no unicode support')
        endcases = [u'', u'<\\u>', u'<\\%c>' % 0x1234, u'<\n>', u'<\\>']
        for proto in pickletester.protocols:
            for u in endcases:
                p = self.dumps(u, proto)
                u2 = self.loads(p)
                self.assertEqual(u2, u)

    # The ability to pickle recursive objects was added in 2.7.11 to fix
    # a crash in CPickle (issue #892902).
test_curses.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def requires_curses_func(name):
    return unittest.skipUnless(hasattr(curses, name),
                               'requires curses.%s' % name)
support.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def requires_tcl(*version):
    return unittest.skipUnless(tcl_version >= version,
            'requires Tcl version >= ' + '.'.join(map(str, version)))
test_archive_util.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _make_tarball(self, target_name):
        # creating something to tar
        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)

        # working with relative paths to avoid tar warnings
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            make_tarball(splitdrive(base_name)[1], '.')
        finally:
            os.chdir(old_dir)

        # check if the compressed tarball was created
        tarball = base_name + '.tar.gz'
        self.assertTrue(os.path.exists(tarball))

        # trying an uncompressed one
        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))
test_xpickle.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_unicode(self):
        if not test_support.have_unicode:
            # Python 2.5 has no unittest.skipUnless
            self.skipTest('no unicode support')
        endcases = [u'', u'<\\u>', u'<\\%c>' % 0x1234, u'<\n>', u'<\\>']
        for proto in pickletester.protocols:
            for u in endcases:
                p = self.dumps(u, proto)
                u2 = self.loads(p)
                self.assertEqual(u2, u)

    # The ability to pickle recursive objects was added in 2.7.11 to fix
    # a crash in CPickle (issue #892902).
test_curses.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def requires_curses_func(name):
    return unittest.skipUnless(hasattr(curses, name),
                               'requires curses.%s' % name)
support.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run_unittest(*classes):
    """Run tests from unittest.TestCase-derived classes."""
    valid_types = (unittest.TestSuite, unittest.TestCase)
    suite = unittest.TestSuite()
    for cls in classes:
        if isinstance(cls, str):
            if cls in sys.modules:
                suite.addTest(unittest.findTestCases(sys.modules[cls]))
            else:
                raise ValueError("str arguments must be keys in sys.modules")
        elif isinstance(cls, valid_types):
            suite.addTest(cls)
        else:
            suite.addTest(unittest.makeSuite(cls))
    def case_pred(test):
        if match_tests is None:
            return True
        for name in test.id().split("."):
            if fnmatch.fnmatchcase(name, match_tests):
                return True
        return False
    _filter_suite(suite, case_pred)
    _run_suite(suite)

# We don't have sysconfig on Py2.6:
# #=======================================================================
# # Check for the presence of docstrings.
# 
# HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
#                    sys.platform == 'win32' or
#                    sysconfig.get_config_var('WITH_DOC_STRINGS'))
# 
# requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
#                                           "test requires docstrings")
# 
# 
# #=======================================================================
# doctest driver.
test_archive_util.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _make_tarball(self, target_name):
        # creating something to tar
        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)

        # working with relative paths to avoid tar warnings
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            make_tarball(splitdrive(base_name)[1], '.')
        finally:
            os.chdir(old_dir)

        # check if the compressed tarball was created
        tarball = base_name + '.tar.gz'
        self.assertTrue(os.path.exists(tarball))

        # trying an uncompressed one
        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))
__init__.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def need_symbol(name):
    return unittest.skipUnless(name in ctypes_symbols,
                               '{!r} is required'.format(name))
support.py 文件源码 项目:islam-buddy 作者: hamir 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run_unittest(*classes):
    """Run tests from unittest.TestCase-derived classes."""
    valid_types = (unittest.TestSuite, unittest.TestCase)
    suite = unittest.TestSuite()
    for cls in classes:
        if isinstance(cls, str):
            if cls in sys.modules:
                suite.addTest(unittest.findTestCases(sys.modules[cls]))
            else:
                raise ValueError("str arguments must be keys in sys.modules")
        elif isinstance(cls, valid_types):
            suite.addTest(cls)
        else:
            suite.addTest(unittest.makeSuite(cls))
    def case_pred(test):
        if match_tests is None:
            return True
        for name in test.id().split("."):
            if fnmatch.fnmatchcase(name, match_tests):
                return True
        return False
    _filter_suite(suite, case_pred)
    _run_suite(suite)

# We don't have sysconfig on Py2.6:
# #=======================================================================
# # Check for the presence of docstrings.
# 
# HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
#                    sys.platform == 'win32' or
#                    sysconfig.get_config_var('WITH_DOC_STRINGS'))
# 
# requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
#                                           "test requires docstrings")
# 
# 
# #=======================================================================
# doctest driver.
utils.py 文件源码 项目:bezier 作者: dhermes 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def needs_helpers_speedup(test_class):
    if bezier is None:
        has_speedup = False  # pragma: NO COVER
    else:
        has_speedup = bezier._HAS_HELPERS_SPEEDUP

    decorator = unittest.skipUnless(
        has_speedup, 'No helpers speedup available')
    return decorator(test_class)
utils.py 文件源码 项目:bezier 作者: dhermes 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def needs_curve_speedup(test_class):
    if bezier is None:
        has_speedup = False  # pragma: NO COVER
    else:
        has_speedup = bezier._HAS_CURVE_SPEEDUP

    decorator = unittest.skipUnless(
        has_speedup, 'No curve speedup available')
    return decorator(test_class)
utils.py 文件源码 项目:bezier 作者: dhermes 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def needs_surface_speedup(test_class):
    if bezier is None:
        has_speedup = False  # pragma: NO COVER
    else:
        has_speedup = bezier._HAS_SURFACE_SPEEDUP

    decorator = unittest.skipUnless(
        has_speedup, 'No surface speedup available')
    return decorator(test_class)


# pylint: disable=invalid-name
utils.py 文件源码 项目:bezier 作者: dhermes 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def needs_curve_intersection_speedup(test_class):
    if bezier is None:
        has_speedup = False  # pragma: NO COVER
    else:
        has_speedup = bezier._HAS_CURVE_INTERSECTION_SPEEDUP

    decorator = unittest.skipUnless(
        has_speedup, 'No curve intersection speedup available')
    return decorator(test_class)
# pylint: enable=invalid-name


# pylint: disable=invalid-name
utils.py 文件源码 项目:bezier 作者: dhermes 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def needs_surface_intersection_speedup(test_class):
    if bezier is None:
        has_speedup = False  # pragma: NO COVER
    else:
        has_speedup = bezier._HAS_SURFACE_INTERSECTION_SPEEDUP

    decorator = unittest.skipUnless(
        has_speedup, 'No surface intersection speedup available')
    return decorator(test_class)
# pylint: enable=invalid-name
test_cuckoo.py 文件源码 项目:cuckoodroid-2.0 作者: idanr1986 项目源码 文件源码 阅读 75 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # Symlink the darwin analyzer into Cuckoo's analyzer directory
        source = path.join(ANALYZER_ROOT, "analyzer", "darwin")
        destination = path.join(cuckoo_root(), "analyzer", "darwin")
        # setUpClass() is called even when @unittest.skipUnless skips
        # all the tests, so we verify it again...
        if path.exists(cuckoo_root()):
            if not path.exists(destination):
                symlink(source, destination)
            # Initialize Cuckoo Host
            cls.launch_cuckoo()
backports.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skipUnless(condition, reason):
        if condition:
            return lambda item: item
        else:
            return skip(reason)
test_shutil.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_make_tarball(self):
        # creating something to tar
        tmpdir = self.mkdtemp()
        write_file((tmpdir, 'file1'), 'xxx')
        write_file((tmpdir, 'file2'), 'xxx')
        os.mkdir(os.path.join(tmpdir, 'sub'))
        write_file((tmpdir, 'sub', 'file3'), 'xxx')

        tmpdir2 = self.mkdtemp()
        # force shutil to create the directory
        os.rmdir(tmpdir2)
        unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
                            "source and target should be on same drive")

        base_name = os.path.join(tmpdir2, 'archive')

        # working with relative paths to avoid tar warnings
        old_dir = os.getcwd()
        os.chdir(tmpdir)
        try:
            _make_tarball(splitdrive(base_name)[1], '.')
        finally:
            os.chdir(old_dir)

        # check if the compressed tarball was created
        tarball = base_name + '.tar.gz'
        self.assertTrue(os.path.exists(tarball))

        # trying an uncompressed one
        base_name = os.path.join(tmpdir2, 'archive')
        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))
test_time.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号