本文整理汇总了Python中test.test_support.check_impl_detail函数的典型用法代码示例。如果您正苦于以下问题:Python check_impl_detail函数的具体用法?Python check_impl_detail怎么用?Python check_impl_detail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_impl_detail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_gc_during_creation
def check_gc_during_creation(self, makeref):
if test_support.check_impl_detail():
import gc
thresholds = gc.get_threshold()
gc.set_threshold(1, 1, 1)
gc_collect()
class A:
pass
def callback(*args):
pass
referenced = A()
a = A()
a.a = a
a.wr = makeref(referenced)
try:
# now make sure the object and the ref get labeled as
# cyclic trash:
a = A()
weakref.ref(referenced, callback)
finally:
if test_support.check_impl_detail():
gc.set_threshold(*thresholds)
开发者ID:Zekom,项目名称:pypyjs,代码行数:27,代码来源:test_weakref.py
示例2: test_bug737473
def test_bug737473(self):
import os, tempfile, time
savedpath = sys.path[:]
testdir = tempfile.mkdtemp()
try:
sys.path.insert(0, testdir)
testfile = os.path.join(testdir, 'test_bug737473.py')
with open(testfile, 'w') as f:
print >> f, """
def test():
raise ValueError"""
if 'test_bug737473' in sys.modules:
del sys.modules['test_bug737473']
import test_bug737473
try:
test_bug737473.test()
except ValueError:
# this loads source code to linecache
traceback.extract_tb(sys.exc_traceback)
# If this test runs too quickly, test_bug737473.py's mtime
# attribute will remain unchanged even if the file is rewritten.
# Consequently, the file would not reload. So, added a sleep()
# delay to assure that a new, distinct timestamp is written.
# Since WinME with FAT32 has multisecond resolution, more than
# three seconds are needed for this test to pass reliably :-(
time.sleep(4)
with open(testfile, 'w') as f:
print >> f, """
def test():
raise NotImplementedError"""
reload(test_bug737473)
try:
test_bug737473.test()
except NotImplementedError:
src = traceback.extract_tb(sys.exc_traceback)[-1][-1]
self.assertEqual(src, 'raise NotImplementedError')
finally:
sys.path[:] = savedpath
for f in os.listdir(testdir):
os.unlink(os.path.join(testdir, f))
os.rmdir(testdir)
err = self.get_exception_format(self.syntax_error_bad_indentation2,
IndentationError)
self.assertEqual(len(err), 4)
self.assertEqual(err[1].strip(), "print(2)")
self.assertIn("^", err[2])
if check_impl_detail():
self.assertEqual(err[1].find("p"), err[2].find("^"))
if check_impl_detail(pypy=True):
self.assertEqual(err[1].find("2)") + 1, err[2].find("^"))
开发者ID:mozillazg,项目名称:pypy,代码行数:56,代码来源:test_traceback.py
示例3: test_builtin_function
def test_builtin_function(self):
eq = self.assertEqual
# Functions
eq(repr(hash), '<built-in function hash>')
# Methods
if check_impl_detail(cpython=True):
self.assertTrue(repr(''.split).startswith(
'<built-in method split of str object at 0x'))
elif check_impl_detail(pypy=True):
eq(repr(''.split), "<bound method str.split of ''>")
开发者ID:alemacgo,项目名称:pypy,代码行数:10,代码来源:test_repr.py
示例4: test_cmptypes
def test_cmptypes(self):
# Built-in tp_compare slots expect their arguments to have the
# same type, but a user-defined __coerce__ doesn't have to obey.
# SF #980352
evil_coercer = CoerceTo(42)
# Make sure these don't crash any more
self.assertNotEquals(cmp(u'fish', evil_coercer), 0)
self.assertNotEquals(cmp(slice(1), evil_coercer), 0)
# ...but that this still works
if check_impl_detail():
# NB. I (arigo) would consider the following as implementation-
# specific. For example, in CPython, if we replace 42 with 42.0
# both below and in CoerceTo() above, then the test fails. This
# hints that the behavior is really dependent on some obscure
# internal details.
class WackyComparer(object):
def __cmp__(slf, other):
self.assert_(other == 42, 'expected evil_coercer, got %r' % other)
return 0
self.assertEquals(cmp(WackyComparer(), evil_coercer), 0)
# ...and classic classes too, since that code path is a little different
class ClassicWackyComparer:
def __cmp__(slf, other):
self.assert_(other == 42, 'expected evil_coercer, got %r' % other)
return 0
self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 0)
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:test_coercion.py
示例5: test_invalid_string
def test_invalid_string(self):
m = ast.Module([ast.Expr(ast.Str(43))])
ast.fix_missing_locations(m)
with self.assertRaises(TypeError) as cm:
compile(m, "<test>", "exec")
if test_support.check_impl_detail():
self.assertIn("string must be of type str or uni", str(cm.exception))
开发者ID:ArneBab,项目名称:pypyjs,代码行数:7,代码来源:test_ast.py
示例6: test_invalid_identitifer
def test_invalid_identitifer(self):
m = ast.Module([ast.Expr(ast.Name(u"x", ast.Load()))])
ast.fix_missing_locations(m)
with self.assertRaises(TypeError) as cm:
compile(m, "<test>", "exec")
if test_support.check_impl_detail():
self.assertIn("identifier must be of type str", str(cm.exception))
开发者ID:ArneBab,项目名称:pypyjs,代码行数:7,代码来源:test_ast.py
示例7: test_repr
def test_repr(self):
l0 = []
l2 = [0, 1, 2]
a0 = self.type2test(l0)
a2 = self.type2test(l2)
self.assertEqual(str(a0), str(l0))
self.assertEqual(repr(a0), repr(l0))
self.assertEqual(repr(a2), repr(l2))
self.assertEqual(str(a2), "[0, 1, 2]")
self.assertEqual(repr(a2), "[0, 1, 2]")
a2.append(a2)
a2.append(3)
self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")
if test_support.check_impl_detail():
depth = sys.getrecursionlimit() + 100
else:
depth = 1000 * 1000 # should be enough to exhaust the stack
l0 = []
for i in xrange(depth):
l0 = [l0]
self.assertRaises(RuntimeError, repr, l0)
开发者ID:mozillazg,项目名称:pypy,代码行数:25,代码来源:list_tests.py
示例8: test_no_len_for_infinite_repeat
def test_no_len_for_infinite_repeat(self):
# The repeat() object can also be infinite
if test_support.check_impl_detail(pypy=True):
# 3.4 (PEP 424) behavior
self.assertEqual(len(repeat(None)), NotImplemented)
else:
self.assertRaises(TypeError, len, repeat(None))
开发者ID:Alkalit,项目名称:pypyjs,代码行数:7,代码来源:test_iterlen.py
示例9: test_module_with_large_stack
def test_module_with_large_stack(self, module='longlist'):
# Regression test for http://bugs.python.org/issue561858.
filename = module + os.extsep + 'py'
# Create a file with a list of 65000 elements.
with open(filename, 'w+') as f:
f.write('d = [\n')
for i in range(65000):
f.write('"",\n')
f.write(']')
# Compile & remove .py file, we only need .pyc (or .pyo).
with open(filename, 'r') as f:
py_compile.compile(filename)
if check_impl_detail(pypy=False):
# pypy refuses to import a .pyc if the .py does not exist
unlink(filename)
# Need to be able to load from current dir.
sys.path.append('')
# This used to crash.
exec 'import ' + module
reload(longlist)
# Cleanup.
del sys.path[-1]
unlink(filename + 'c')
unlink(filename + 'o')
开发者ID:MichaelBlume,项目名称:pypy,代码行数:29,代码来源:test_import.py
示例10: test_rewrite_pyc_with_read_only_source
def test_rewrite_pyc_with_read_only_source(self):
# Issue 6074: a long time ago on posix, and more recently on Windows,
# a read only source file resulted in a read only pyc file, which
# led to problems with updating it later
sys.path.insert(0, os.curdir)
fname = TESTFN + os.extsep + "py"
try:
# Write a Python file, make it read-only and import it
with open(fname, 'w') as f:
f.write("x = 'original'\n")
# Tweak the mtime of the source to ensure pyc gets updated later
s = os.stat(fname)
os.utime(fname, (s.st_atime, s.st_mtime-100000000))
os.chmod(fname, 0400)
m1 = __import__(TESTFN)
self.assertEqual(m1.x, 'original')
# Change the file and then reimport it
os.chmod(fname, 0600)
with open(fname, 'w') as f:
f.write("x = 'rewritten'\n")
unload(TESTFN)
m2 = __import__(TESTFN)
self.assertEqual(m2.x, 'rewritten')
# Now delete the source file and check the pyc was rewritten
if check_impl_detail(pypy=False):
unlink(fname)
unload(TESTFN)
m3 = __import__(TESTFN)
self.assertEqual(m3.x, 'rewritten')
finally:
chmod_files(TESTFN)
remove_files(TESTFN)
unload(TESTFN)
del sys.path[0]
开发者ID:Alkalit,项目名称:pypyjs,代码行数:34,代码来源:test_import.py
示例11: test_popitem
def test_popitem(self):
# dict.popitem()
for copymode in -1, +1:
# -1: b has same structure as a
# +1: b is a.copy()
for log2size in range(12):
size = 2**log2size
a = {}
b = {}
for i in range(size):
a[repr(i)] = i
if copymode < 0:
b[repr(i)] = i
if copymode > 0:
b = a.copy()
for i in range(size):
ka, va = ta = a.popitem()
self.assertEqual(va, int(ka))
kb, vb = tb = b.popitem()
self.assertEqual(vb, int(kb))
if test_support.check_impl_detail():
self.assertFalse(copymode < 0 and ta != tb)
self.assertFalse(a)
self.assertFalse(b)
d = {}
self.assertRaises(KeyError, d.popitem)
开发者ID:mozillazg,项目名称:pypy,代码行数:27,代码来源:test_dict.py
示例12: test_one
def test_one(n):
global mutate, dict1, dict2, dict1keys, dict2keys
# Fill the dicts without mutating them.
mutate = 0
dict1keys = fill_dict(dict1, range(n), n)
dict2keys = fill_dict(dict2, range(n), n)
# Enable mutation, then compare the dicts so long as they have the
# same size.
mutate = 1
if verbose:
print "trying w/ lengths", len(dict1), len(dict2),
while dict1 and len(dict1) == len(dict2):
if verbose:
print ".",
try:
if random.random() < 0.5:
c = cmp(dict1, dict2)
else:
c = dict1 == dict2
except RuntimeError:
# CPython never raises RuntimeError here, but other implementations
# might, and it's fine.
if check_impl_detail(cpython=True):
raise
if verbose:
print
开发者ID:mozillazg,项目名称:pypy,代码行数:28,代码来源:test_mutants.py
示例13: test_c_buffer_raw
def test_c_buffer_raw(self, memoryview=memoryview):
buf = c_buffer(32)
buf.raw = memoryview("Hello, World")
self.assertEqual(buf.value, "Hello, World")
if test_support.check_impl_detail():
self.assertRaises(TypeError, setattr, buf, "value", memoryview("abc"))
self.assertRaises(ValueError, setattr, buf, "raw", memoryview("x" * 100))
开发者ID:BartoszCichecki,项目名称:onlinepython,代码行数:8,代码来源:test_strings.py
示例14: test_descriptors
def test_descriptors(self):
eq = self.assertEqual
# method descriptors
if check_impl_detail(cpython=True):
eq(repr(dict.items), "<method 'items' of 'dict' objects>")
elif check_impl_detail(pypy=True):
eq(repr(dict.items), "<unbound method dict.items>")
# XXX member descriptors
# XXX attribute descriptors
# XXX slot descriptors
# static and class methods
class C:
def foo(cls): pass
x = staticmethod(C.foo)
self.assertTrue(repr(x).startswith('<staticmethod object at 0x'))
x = classmethod(C.foo)
self.assertTrue(repr(x).startswith('<classmethod object at 0x'))
开发者ID:alemacgo,项目名称:pypy,代码行数:17,代码来源:test_repr.py
示例15: test_bad_indentation
def test_bad_indentation(self):
err = self.get_exception_format(self.syntax_error_bad_indentation, IndentationError)
self.assertTrue(len(err) == 4)
self.assertTrue(err[1].strip() == "print 2")
if check_impl_detail():
# on CPython, there is a "^" at the end of the line
# on PyPy, there is a "^" too, but at the start, more logically
self.assertIn("^", err[2])
self.assertTrue(err[1].find("2") == err[2].find("^"))
开发者ID:cimarieta,项目名称:usp,代码行数:9,代码来源:test_traceback.py
示例16: test_exec_with_general_mapping_for_locals
def test_exec_with_general_mapping_for_locals(self):
class M:
"Test mapping interface versus possible calls from eval()."
def __getitem__(self, key):
if key == 'a':
return 12
raise KeyError
def __setitem__(self, key, value):
self.results = (key, value)
def keys(self):
return list('xyz')
m = M()
g = globals()
exec 'z = a' in g, m
self.assertEqual(m.results, ('z', 12))
try:
exec 'z = b' in g, m
except NameError:
pass
else:
self.fail('Did not detect a KeyError')
exec 'z = dir()' in g, m
self.assertEqual(m.results, ('z', list('xyz')))
exec 'z = globals()' in g, m
self.assertEqual(m.results, ('z', g))
exec 'z = locals()' in g, m
self.assertEqual(m.results, ('z', m))
if check_impl_detail():
try:
exec 'z = b' in m
except TypeError:
pass
else:
self.fail('Did not validate globals as a real dict')
class A:
"Non-mapping"
pass
m = A()
try:
exec 'z = a' in g, m
except TypeError:
pass
else:
self.fail('Did not validate locals as a mapping')
# Verify that dict subclasses work as well
class D(dict):
def __getitem__(self, key):
if key == 'a':
return 12
return dict.__getitem__(self, key)
d = D()
exec 'z = a' in g, d
self.assertEqual(d['z'], 12)
开发者ID:ArneBab,项目名称:pypyjs,代码行数:57,代码来源:test_compile.py
示例17: test_select_mutated
def test_select_mutated(self):
a = []
class F:
def fileno(self):
del a[-1]
return sys.__stdout__.fileno()
a[:] = [F()] * 10
result = select.select([], a, [])
# CPython: 'a' ends up with 5 items, because each fileno()
# removes an item and at the middle the iteration stops.
# PyPy: 'a' ends up empty, because the iteration is done on
# a copy of the original list: fileno() is called 10 times.
if test_support.check_impl_detail(cpython=True):
self.assertEqual(len(result[1]), 5)
self.assertEqual(len(a), 5)
if test_support.check_impl_detail(pypy=True):
self.assertEqual(len(result[1]), 10)
self.assertEqual(len(a), 0)
开发者ID:Alkalit,项目名称:pypyjs,代码行数:18,代码来源:test_select.py
示例18: _test_dict_attribute
def _test_dict_attribute(self, cls):
obj = cls()
obj.x = 5
self.assertEqual(obj.__dict__, {'x': 5})
if support.check_impl_detail():
with self.assertRaises(AttributeError):
obj.__dict__ = {}
with self.assertRaises(AttributeError):
del obj.__dict__
开发者ID:gevent,项目名称:gevent,代码行数:9,代码来源:test_threading_local.py
示例19: test_exc
def test_exc(formatstr, args, exception, excmsg):
try:
testformat(formatstr, args)
except exception, exc:
if str(exc) == excmsg or not test_support.check_impl_detail():
if verbose:
print "yes"
else:
if verbose: print 'no'
print 'Unexpected ', exception, ':', repr(str(exc))
开发者ID:ArneBab,项目名称:pypyjs,代码行数:10,代码来源:test_format.py
示例20: test_startswith_endswith_errors
def test_startswith_endswith_errors(self):
with self.assertRaises(UnicodeDecodeError):
'\xff'.startswith(u'x')
with self.assertRaises(UnicodeDecodeError):
'\xff'.endswith(u'x')
for meth in ('foo'.startswith, 'foo'.endswith):
with self.assertRaises(TypeError) as cm:
meth(['f'])
if test_support.check_impl_detail():
exc = str(cm.exception)
self.assertIn('unicode', exc)
self.assertIn('str', exc)
self.assertIn('tuple', exc)
开发者ID:ArneBab,项目名称:pypyjs,代码行数:13,代码来源:test_str.py
注:本文中的test.test_support.check_impl_detail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论