python中r 4.2f%r_Python test.support方法代碼示例

本文整理匯總了Python中test.support方法的典型用法代碼示例。如果您正苦於以下問題:Python test.support方法的具體用法?Python test.support怎麽用?Python test.support使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊test的用法示例。

在下文中一共展示了test.support方法的26個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: test_threads_join

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_threads_join(self):

# Non-daemon threads should be joined at subinterpreter shutdown

# (issue #18808)

r, w = os.pipe()

self.addCleanup(os.close, r)

self.addCleanup(os.close, w)

code = r"""if 1:

import os

import threading

import time

def f():

# Sleep a bit so that the thread is still running when

# Py_EndInterpreter is called.

time.sleep(0.05)

os.write(%d, b"x")

threading.Thread(target=f).start()

""" % (w,)

ret = test.support.run_in_subinterp(code)

self.assertEqual(ret, 0)

# The thread was joined properly.

self.assertEqual(os.read(r, 1), b"x")

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,

示例2: test_daemon_threads_fatal_error

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_daemon_threads_fatal_error(self):

subinterp_code = r"""if 1:

import os

import threading

import time

def f():

# Make sure the daemon thread is still running when

# Py_EndInterpreter is called.

time.sleep(10)

threading.Thread(target=f, daemon=True).start()

"""

script = r"""if 1:

import _testcapi

_testcapi.run_in_subinterp(%r)

""" % (subinterp_code,)

with test.support.SuppressCrashReport():

rc, out, err = assert_python_failure("-c", script)

self.assertIn("Fatal Python error: Py_EndInterpreter: "

"not the last thread", err.decode())

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,

示例3: _run_object_doctest

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def _run_object_doctest(obj, module):

finder = doctest.DocTestFinder(verbose=verbose, recurse=False)

runner = doctest.DocTestRunner(verbose=verbose)

# Use the object's fully qualified name if it has one

# Otherwise, use the module's name

try:

name = "%s.%s" % (obj.__module__, obj.__qualname__)

except AttributeError:

name = module.__name__

for example in finder.find(obj, name, module):

runner.run(example)

f, t = runner.failures, runner.tries

if f:

raise test.support.TestFailed("%d of %d doctests failed" % (f, t))

if verbose:

print ('doctest (%s) ... %d tests with zero failures' % (module.__name__, t))

return f, t

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,

示例4: test_pdb_issue4201

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_pdb_issue4201(self):

test_src = textwrap.dedent("""\

def f():

pass

import pdb

pdb.Pdb(nosigint=True).runcall(f)

""")

with test.support.temp_dir() as d:

script_name = make_script(d, 'script', test_src)

p = spawn_python(script_name)

p.stdin.write(b'l\n')

data = kill_python(p)

# bdb/pdb applies normcase to its filename before displaying

self.assertIn(os.path.normcase(script_name.encode('utf-8')), data)

zip_name, run_name = make_zip_script(d, "test_zip",

script_name, '__main__.py')

p = spawn_python(zip_name)

p.stdin.write(b'l\n')

data = kill_python(p)

# bdb/pdb applies normcase to its filename before displaying

self.assertIn(os.path.normcase(run_name.encode('utf-8')), data)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,

示例5: test_issue22668

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_issue22668(self):

a = array.array('H', [256, 256, 256, 256])

x = memoryview(a)

m = x.cast('B')

b = m.cast('H')

c = b[0:2]

d = memoryview(b)

del b

self.assertEqual(c[0], 256)

self.assertEqual(d[0], 256)

self.assertEqual(c.format, "H")

self.assertEqual(d.format, "H")

_ = m.cast('I')

self.assertEqual(c[0], 256)

self.assertEqual(d[0], 256)

self.assertEqual(c.format, "H")

self.assertEqual(d.format, "H")

# Variations on source objects for the buffer: bytes-like objects, then arrays

# with itemsize > 1.

# NOTE: support for multi-dimensional objects is unimplemented.

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,

示例6: test_ctypes_cast

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_ctypes_cast(self):

# Issue 15944: Allow all source formats when casting to bytes.

ctypes = test.support.import_module("ctypes")

p6 = bytes(ctypes.c_double(0.6))

d = ctypes.c_double()

m = memoryview(d).cast("B")

m[:2] = p6[:2]

m[2:] = p6[2:]

self.assertEqual(d.value, 0.6)

for format in "Bbc":

with self.subTest(format):

d = ctypes.c_double()

m = memoryview(d).cast(format)

m[:2] = memoryview(p6).cast(format)[:2]

m[2:] = memoryview(p6).cast(format)[2:]

self.assertEqual(d.value, 0.6)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,

示例7: test_recursionlimit_fatalerror

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_recursionlimit_fatalerror(self):

# A fatal error occurs if a second recursion limit is hit when recovering

# from a first one.

code = textwrap.dedent("""

import sys

def f():

try:

f()

except RecursionError:

f()

sys.setrecursionlimit(%d)

f()""")

with test.support.SuppressCrashReport():

for i in (50, 1000):

sub = subprocess.Popen([sys.executable, '-c', code % i],

stderr=subprocess.PIPE)

err = sub.communicate()[1]

self.assertTrue(sub.returncode, sub.returncode)

self.assertIn(

b"Fatal Python error: Cannot recover from stack overflow",

err)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,

示例8: test_pythontypes

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_pythontypes(self):

# check all types defined in Python/

size = test.support.calcobjsize

vsize = test.support.calcvobjsize

check = self.check_sizeof

# _ast.AST

import _ast

check(_ast.AST(), size('P'))

try:

raise TypeError

except TypeError:

tb = sys.exc_info()[2]

# traceback

if tb is not None:

check(tb, size('2P2i'))

# symtable entry

# XXX

# sys.flags

check(sys.flags, vsize('') + self.P * len(sys.flags))

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,

示例9: check_enough_semaphores

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def check_enough_semaphores():

"""Check that the system supports enough semaphores to run the test."""

# minimum number of semaphores available according to POSIX

nsems_min = 256

try:

nsems = os.sysconf("SC_SEM_NSEMS_MAX")

except (AttributeError, ValueError):

# sysconf not available or setting not available

return

if nsems == -1 or nsems >= nsems_min:

return

raise unittest.SkipTest("The OS doesn't support enough semaphores "

"to run the test (required: %d)." % nsems_min)

#

# Creates a wrapper for a function which records the time it takes to finish

#

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,

示例10: test_stderr_flush

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_stderr_flush(self):

# sys.stderr is flushed at process shutdown (issue #13812)

if self.TYPE == "threads":

self.skipTest('test not appropriate for {}'.format(self.TYPE))

testfn = test.support.TESTFN

self.addCleanup(test.support.unlink, testfn)

proc = self.Process(target=self._test_stderr_flush, args=(testfn,))

proc.start()

proc.join()

with open(testfn, 'r') as f:

err = f.read()

# The whole traceback was printed

self.assertIn("ZeroDivisionError", err)

self.assertIn("test_multiprocessing.py", err)

self.assertIn("1/0 # MARKER", err)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,

示例11: test_no_import_lock_contention

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_no_import_lock_contention(self):

with test.support.temp_cwd():

module_name = 'imported_by_an_imported_module'

with open(module_name + '.py', 'w') as f:

f.write("""if 1:

import multiprocessing

q = multiprocessing.Queue()

q.put('knock knock')

q.get(timeout=3)

q.close()

del q

""")

with test.support.DirsOnSysPath(os.getcwd()):

try:

__import__(module_name)

except pyqueue.Empty:

self.fail("Probable regression on import lock contention;"

" see Issue #22853")

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,

示例12: test_traceback

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_traceback(self):

# We want ensure that the traceback from the child process is

# contained in the traceback raised in the main process.

if self.TYPE == 'processes':

with self.Pool(1) as p:

try:

p.apply(self._test_traceback)

except Exception as e:

exc = e

else:

raise AssertionError('expected RuntimeError')

self.assertIs(type(exc), RuntimeError)

self.assertEqual(exc.args, (123,))

cause = exc.__cause__

self.assertIs(type(cause), multiprocessing.pool.RemoteTraceback)

self.assertIn('raise RuntimeError(123) # some comment', cause.tb)

with test.support.captured_stderr() as f1:

try:

raise exc

except RuntimeError:

sys.excepthook(*sys.exc_info())

self.assertIn('raise RuntimeError(123) # some comment',

f1.getvalue())

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:26,

示例13: test_fd_transfer

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_fd_transfer(self):

if self.TYPE != 'processes':

self.skipTest("only makes sense with processes")

conn, child_conn = self.Pipe(duplex=True)

p = self.Process(target=self._writefd, args=(child_conn, b"foo"))

p.daemon = True

p.start()

self.addCleanup(test.support.unlink, test.support.TESTFN)

with open(test.support.TESTFN, "wb") as f:

fd = f.fileno()

if msvcrt:

fd = msvcrt.get_osfhandle(fd)

reduction.send_handle(conn, fd, p.pid)

p.join()

with open(test.support.TESTFN, "rb") as f:

self.assertEqual(f.read(), b"foo")

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,

示例14: _listener

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def _listener(cls, conn, families):

for fam in families:

l = cls.connection.Listener(family=fam)

conn.send(l.address)

new_conn = l.accept()

conn.send(new_conn)

new_conn.close()

l.close()

l = socket.socket()

l.bind((test.support.HOST, 0))

l.listen()

conn.send(l.getsockname())

new_conn, addr = l.accept()

conn.send(new_conn)

new_conn.close()

l.close()

conn.recv()

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,

示例15: _run_object_doctest

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def _run_object_doctest(obj, module):

finder = doctest.DocTestFinder(verbose=verbose, recurse=False)

runner = doctest.DocTestRunner(verbose=verbose)

# Use the object's fully qualified name if it has one

# Otherwise, use the module's name

try:

name = "%s.%s" % (obj.__module__, obj.__name__)

except AttributeError:

name = module.__name__

for example in finder.find(obj, name, module):

runner.run(example)

f, t = runner.failures, runner.tries

if f:

raise test.support.TestFailed("%d of %d doctests failed" % (f, t))

if verbose:

print ('doctest (%s) ... %d tests with zero failures' % (module.__name__, t))

return f, t

開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:19,

示例16: test_recursionlimit_fatalerror

​點讚 6

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_recursionlimit_fatalerror(self):

# A fatal error occurs if a second recursion limit is hit when recovering

# from a first one.

code = textwrap.dedent("""

import sys

def f():

try:

f()

except RuntimeError:

f()

sys.setrecursionlimit(%d)

f()""")

with test.support.SuppressCrashReport():

for i in (50, 1000):

sub = subprocess.Popen([sys.executable, '-c', code % i],

stderr=subprocess.PIPE)

err = sub.communicate()[1]

self.assertTrue(sub.returncode, sub.returncode)

self.assertIn(

b"Fatal Python error: Cannot recover from stack overflow",

err)

開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:25,

示例17: collect_test_support

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def collect_test_support(info_add):

try:

from test import support

except ImportError:

return

attributes = ('IPV6_ENABLED',)

copy_attributes(info_add, support, 'test_support.%s', attributes)

call_func(info_add, 'test_support._is_gui_available', support, '_is_gui_available')

call_func(info_add, 'test_support.python_is_optimized', support, 'python_is_optimized')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,

示例18: setUp

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def setUp(self):

self._threads = test.support.threading_setup()

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,

示例19: tearDown

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def tearDown(self):

test.support.threading_cleanup(*self._threads)

test.support.reap_children()

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,

示例20: test_various_ops_small_stack

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_various_ops_small_stack(self):

if verbose:

print('with 256kB thread stack size...')

try:

threading.stack_size(262144)

except _thread.error:

raise unittest.SkipTest(

'platform does not support changing thread stack size')

self.test_various_ops()

threading.stack_size(0)

# run with a large thread stack size (1MB)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,

示例21: test_various_ops_large_stack

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_various_ops_large_stack(self):

if verbose:

print('with 1MB thread stack size...')

try:

threading.stack_size(0x100000)

except _thread.error:

raise unittest.SkipTest(

'platform does not support changing thread stack size')

self.test_various_ops()

threading.stack_size(0)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:12,

示例22: setUp

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def setUp(self):

self.maxDiff = None

self.prog_name = 'bogus_program_xxxx'

self.temp_path_dir = os.path.abspath(os.getcwd())

self.env = test.support.EnvironmentVarGuard()

self.addCleanup(self.env.__exit__)

for cv in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS',

'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',

'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',

'PY_CORE_CFLAGS'):

if cv in self.env:

self.env.unset(cv)

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,

示例23: test__find_executable

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test__find_executable(self):

if self.env['PATH']:

self.env['PATH'] = self.env['PATH'] + ':'

self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir)

test.support.unlink(self.prog_name)

self.assertIsNone(_osx_support._find_executable(self.prog_name))

self.addCleanup(test.support.unlink, self.prog_name)

with open(self.prog_name, 'w') as f:

f.write("#!/bin/sh\n/bin/echo OK\n")

os.chmod(self.prog_name, stat.S_IRWXU)

self.assertEqual(self.prog_name,

_osx_support._find_executable(self.prog_name))

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,

示例24: test__read_output

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test__read_output(self):

if self.env['PATH']:

self.env['PATH'] = self.env['PATH'] + ':'

self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir)

test.support.unlink(self.prog_name)

self.addCleanup(test.support.unlink, self.prog_name)

with open(self.prog_name, 'w') as f:

f.write("#!/bin/sh\n/bin/echo ExpectedOutput\n")

os.chmod(self.prog_name, stat.S_IRWXU)

self.assertEqual('ExpectedOutput',

_osx_support._read_output(self.prog_name))

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,

示例25: test__find_appropriate_compiler

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test__find_appropriate_compiler(self):

compilers = (

('gcc-test', 'i686-apple-darwin11-llvm-gcc-4.2'),

('clang', 'clang version 3.1'),

)

config_vars = {

'CC': 'gcc-test -pthreads',

'CXX': 'cc++-test',

'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',

'LDFLAGS': '-arch ppc -arch i386 -g',

'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',

'BLDSHARED': 'gcc-test -bundle -arch ppc -arch i386 -g',

'LDSHARED': 'gcc-test -bundle -arch ppc -arch i386 '

'-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g',

}

expected_vars = {

'CC': 'clang -pthreads',

'CXX': 'clang++',

'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',

'LDFLAGS': '-arch ppc -arch i386 -g',

'CPPFLAGS': '-I. -isysroot /Developer/SDKs/MacOSX10.4u.sdk',

'BLDSHARED': 'clang -bundle -arch ppc -arch i386 -g',

'LDSHARED': 'clang -bundle -arch ppc -arch i386 '

'-isysroot /Developer/SDKs/MacOSX10.4u.sdk -g',

}

self.add_expected_saved_initial_values(config_vars, expected_vars)

suffix = (':' + self.env['PATH']) if self.env['PATH'] else ''

self.env['PATH'] = os.path.abspath(self.temp_path_dir) + suffix

for c_name, c_output in compilers:

test.support.unlink(c_name)

self.addCleanup(test.support.unlink, c_name)

with open(c_name, 'w') as f:

f.write("#!/bin/sh\n/bin/echo " + c_output)

os.chmod(c_name, stat.S_IRWXU)

self.assertEqual(expected_vars,

_osx_support._find_appropriate_compiler(

config_vars))

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:40,

示例26: test_inspect_getsource_issue4223

​點讚 5

# 需要導入模塊: import test [as 別名]

# 或者: from test import support [as 別名]

def test_inspect_getsource_issue4223(self):

test_src = "def foo(): pass\n"

with test.support.temp_dir() as d:

init_name = make_script(d, '__init__', test_src)

name_in_zip = os.path.join('zip_pkg',

os.path.basename(init_name))

zip_name, run_name = make_zip_script(d, 'test_zip',

init_name, name_in_zip)

os.remove(init_name)

sys.path.insert(0, zip_name)

import zip_pkg

try:

self.assertEqual(inspect.getsource(zip_pkg.foo), test_src)

finally:

del sys.modules["zip_pkg"]

開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:17,

注:本文中的test.support方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值