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


Python test_support.verify函数代码示例

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


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

示例1: test_logs

def test_logs():
    import math

    if verbose:
        print "log and log10"

    LOG10E = math.log10(math.e)

    for exp in range(10) + [100, 1000, 10000]:
        value = 10 ** exp
        log10 = math.log10(value)
        verify(fcmp(log10, exp) == 0)

        # log10(value) == exp, so log(value) == log10(value)/log10(e) ==
        # exp/LOG10E
        expected = exp / LOG10E
        log = math.log(value)
        verify(fcmp(log, expected) == 0)

    for bad in -(1L << 10000), -2L, 0L:
        try:
            math.log(bad)
            raise TestFailed("expected ValueError from log(<= 0)")
        except ValueError:
            pass

        try:
            math.log10(bad)
            raise TestFailed("expected ValueError from log10(<= 0)")
        except ValueError:
            pass
开发者ID:facchinm,项目名称:SiRFLive,代码行数:31,代码来源:test_long.py

示例2: test_im_class

def test_im_class():
    class C:
        def foo(self): pass
    verify(C.foo.im_class is C)
    verify(C().foo.im_class is C)
    cantset(C.foo, "im_class", C)
    cantset(C().foo, "im_class", C)
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:7,代码来源:test_funcattrs.py

示例3: test_float_overflow

def test_float_overflow():
    import math

    if verbose:
        print "long->float overflow"

    for x in -2.0, -1.0, 0.0, 1.0, 2.0:
        verify(float(long(x)) == x)

    shuge = '12345' * 120
    huge = 1L << 30000
    mhuge = -huge
    namespace = {'huge': huge, 'mhuge': mhuge, 'shuge': shuge, 'math': math}
    for test in ["float(huge)", "float(mhuge)",
                 "complex(huge)", "complex(mhuge)",
                 "complex(huge, 1)", "complex(mhuge, 1)",
                 "complex(1, huge)", "complex(1, mhuge)",
                 "1. + huge", "huge + 1.", "1. + mhuge", "mhuge + 1.",
                 "1. - huge", "huge - 1.", "1. - mhuge", "mhuge - 1.",
                 "1. * huge", "huge * 1.", "1. * mhuge", "mhuge * 1.",
                 "1. // huge", "huge // 1.", "1. // mhuge", "mhuge // 1.",
                 "1. / huge", "huge / 1.", "1. / mhuge", "mhuge / 1.",
                 "1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.",
                 "math.sin(huge)", "math.sin(mhuge)",
                 "math.sqrt(huge)", "math.sqrt(mhuge)", # should do better
                 "math.floor(huge)", "math.floor(mhuge)",]:
                 #XXX: not working
                 #"float(shuge) == int(shuge)"]:

        try:
            eval(test, namespace)
        except OverflowError:
            pass
        else:
            raise TestFailed("expected OverflowError from %s" % test)
开发者ID:denis-vilyuzhanin,项目名称:OpenModelSphereMirror,代码行数:35,代码来源:test_long.py

示例4: check_all

 def check_all(self, modname):
     names = {}
     original_sys_modules = sys.modules.copy()
     try:
         exec "import %s" % modname in names
     except ImportError:
         # Silent fail here seems the best route since some modules
         # may not be available in all environments.
         # We restore sys.modules to avoid leaving broken modules behind,
         # but we must not remove built-in modules from sys.modules
         # (because they can't be re-imported, typically)
         for name in sys.modules.keys():
             if name in original_sys_modules:
                 continue
             # XXX hackish
             mod = sys.modules[name]
             if not hasattr(mod, '__file__'):
                 continue
             if (mod.__file__.lower().endswith('.py') or
                 mod.__file__.lower().endswith('.pyc') or
                 mod.__file__.lower().endswith('.pyo')):
                 del sys.modules[name]
         return
     verify(hasattr(sys.modules[modname], "__all__"),
            "%s has no __all__ attribute" % modname)
     names = {}
     exec "from %s import *" % modname in names
     if names.has_key("__builtins__"):
         del names["__builtins__"]
     keys = set(names)
     all = set(sys.modules[modname].__all__)
     verify(keys==all, "%s != %s" % (keys, all))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:32,代码来源:test___all__.py

示例5: test_im_doc

def test_im_doc():
    class C:
        def foo(self): "hello"
    verify(C.foo.__doc__ == "hello")
    verify(C().foo.__doc__ == "hello")
    cantset(C.foo, "__doc__", "hello")
    cantset(C().foo, "__doc__", "hello")
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:7,代码来源:test_funcattrs.py

示例6: check_all

 def check_all(self, modname):
     names = {}
     try:
         exec "import %s" % modname in names
     except ImportError:
         # Silent fail here seems the best route since some modules
         # may not be available in all environments.
         # Since an ImportError may leave a partial module object in
         # sys.modules, get rid of that first.  Here's what happens if
         # you don't:  importing pty fails on Windows because pty tries to
         # import FCNTL, which doesn't exist.  That raises an ImportError,
         # caught here.  It also leaves a partial pty module in sys.modules.
         # So when test_pty is called later, the import of pty succeeds,
         # but shouldn't.  As a result, test_pty crashes with an
         # AttributeError instead of an ImportError, and regrtest interprets
         # the latter as a test failure (ImportError is treated as "test
         # skipped" -- which is what test_pty should say on Windows).
         try:
             del sys.modules[modname]
         except KeyError:
             pass
         return
     verify(hasattr(sys.modules[modname], "__all__"),
            "%s has no __all__ attribute" % modname)
     names = {}
     exec "from %s import *" % modname in names
     if names.has_key("__builtins__"):
         del names["__builtins__"]
     keys = Set(names)
     all = Set(sys.modules[modname].__all__)
     verify(keys==all, "%s != %s" % (keys, all))
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:31,代码来源:test___all__.py

示例7: test_im_name

def test_im_name():
    class C:
        def foo(self): pass
    verify(C.foo.__name__ == "foo")
    verify(C().foo.__name__ == "foo")
    cantset(C.foo, "__name__", "foo")
    cantset(C().foo, "__name__", "foo")
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:7,代码来源:test_funcattrs.py

示例8: test_func_code

def test_func_code():
    a = b = 24

    def f():
        pass

    def g():
        print 12

    def f1():
        print a

    def g1():
        print b

    def f2():
        print a, b

    verify(type(f.func_code) is types.CodeType)
    f.func_code = g.func_code
    cantset(f, "func_code", None)
    # can't change the number of free vars
    cantset(f, "func_code", f1.func_code, exception=ValueError)
    cantset(f1, "func_code", f.func_code, exception=ValueError)
    cantset(f1, "func_code", f2.func_code, exception=ValueError)
    f1.func_code = g1.func_code
开发者ID:thecodemaiden,项目名称:breve,代码行数:26,代码来源:test_funcattrs.py

示例9: test

def test():
    if not hasattr(gc, 'get_debug'):
        if verbose:
            print "skipping test_gc: too many GC differences with CPython"
        return
    if verbose:
        print "disabling automatic collection"
    enabled = gc.isenabled()
    gc.disable()
    verify(not gc.isenabled())
    debug = gc.get_debug()
    gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak

    try:
        test_all()
    finally:
        gc.set_debug(debug)
        # test gc.enable() even if GC is disabled by default
        if verbose:
            print "restoring automatic collection"
        # make sure to always test gc.enable()
        gc.enable()
        verify(gc.isenabled())
        if not enabled:
            gc.disable()
开发者ID:thepian,项目名称:themaestro,代码行数:25,代码来源:test_gc.py

示例10: drive_one

def drive_one(pattern, length):
    q, r = divmod(length, len(pattern))
    teststring = pattern * q + pattern[:r]
    verify(len(teststring) == length)
    try_one(teststring)
    try_one(teststring + "x")
    try_one(teststring[:-1])
开发者ID:Alex-CS,项目名称:sonify,代码行数:7,代码来源:test_bufio.py

示例11: test_main

def test_main(verbose=None):
    from test.test_support import verify
    import sys
    for func in tests:
        expected = tests[func]
        result = list(func())
        verify(result == expected, "%s: expected %s, got %s" % (
                func.__name__, expected, result))
开发者ID:Alex-CS,项目名称:sonify,代码行数:8,代码来源:test_closuregen.py

示例12: test_im_self

def test_im_self():
    class C:
        def foo(self): pass
    verify(C.foo.im_self is None)
    c = C()
    verify(c.foo.im_self is c)
    cantset(C.foo, "im_self", None)
    cantset(c.foo, "im_self", c)
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:8,代码来源:test_funcattrs.py

示例13: test_im_dict

def test_im_dict():
    class C:
        def foo(self): pass
        foo.bar = 42
    verify(C.foo.__dict__ == {'bar': 42})
    verify(C().foo.__dict__ == {'bar': 42})
    cantset(C.foo, "__dict__", C.foo.__dict__)
    cantset(C().foo, "__dict__", C.foo.__dict__)
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:8,代码来源:test_funcattrs.py

示例14: test_anon

def test_anon():
    print "  anonymous mmap.mmap(-1, PAGESIZE)..."
    m = mmap.mmap(-1, PAGESIZE)
    for x in xrange(PAGESIZE):
        verify(m[x] == '\0', "anonymously mmap'ed contents should be zero")

    for x in xrange(PAGESIZE):
        m[x] = ch = chr(x & 255)
        vereq(m[x], ch)
开发者ID:Alex-CS,项目名称:sonify,代码行数:9,代码来源:test_mmap.py

示例15: testdgram

def testdgram(proto, addr):
    s = socket.socket(proto, socket.SOCK_DGRAM)
    s.sendto(teststring, addr)
    buf = data = receive(s, 100)
    while data and '\n' not in buf:
        data = receive(s, 100)
        buf += data
    verify(buf == teststring)
    s.close()
开发者ID:005,项目名称:gevent,代码行数:9,代码来源:test_socketserver.py


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