本文整理汇总了Python中test.test_support.py3k_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.py3k_bytes方法的具体用法?Python test_support.py3k_bytes怎么用?Python test_support.py3k_bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.py3k_bytes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWeakRefs
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testWeakRefs(self):
# verify weak references
p = proxy(self.f)
p.write(bytes(range(10)))
self.assertEqual(self.f.tell(), p.tell())
self.f.close()
self.f = None
self.assertRaises(ReferenceError, getattr, p, 'tell')
示例2: testSeekTell
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testSeekTell(self):
self.f.write(bytes(range(20)))
self.assertEqual(self.f.tell(), 20)
self.f.seek(0)
self.assertEqual(self.f.tell(), 0)
self.f.seek(10)
self.assertEqual(self.f.tell(), 10)
self.f.seek(5, 1)
self.assertEqual(self.f.tell(), 15)
self.f.seek(-5, 1)
self.assertEqual(self.f.tell(), 10)
self.f.seek(-5, 2)
self.assertEqual(self.f.tell(), 15)
示例3: testBytesOpen
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testBytesOpen(self):
# Opening a bytes filename
try:
fn = TESTFN.encode("ascii")
except UnicodeEncodeError:
self.skipTest('could not encode %r to ascii' % TESTFN)
f = _FileIO(fn, "w")
try:
f.write(b"abc")
f.close()
with open(TESTFN, "rb") as f:
self.assertEqual(f.read(), b"abc")
finally:
os.unlink(TESTFN)
示例4: testTruncate
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testTruncate(self):
f = _FileIO(TESTFN, 'w')
f.write(bytes(bytearray(range(10))))
self.assertEqual(f.tell(), 10)
f.truncate(5)
self.assertEqual(f.tell(), 10)
self.assertEqual(f.seek(0, os.SEEK_END), 5)
f.truncate(15)
self.assertEqual(f.tell(), 5)
self.assertEqual(f.seek(0, os.SEEK_END), 15)
f.close()
示例5: testTruncateOnWindows
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testTruncateOnWindows(self):
def bug801631():
# SF bug <http://www.python.org/sf/801631>
# "file.truncate fault on windows"
f = _FileIO(TESTFN, 'w')
f.write(bytes(range(11)))
f.close()
f = _FileIO(TESTFN,'r+')
data = f.read(5)
if data != bytes(range(5)):
self.fail("Read on file opened for update failed %r" % data)
if f.tell() != 5:
self.fail("File pos after read wrong %d" % f.tell())
f.truncate()
if f.tell() != 5:
self.fail("File pos after ftruncate wrong %d" % f.tell())
f.close()
size = os.path.getsize(TESTFN)
if size != 5:
self.fail("File size after ftruncate wrong %d" % size)
try:
bug801631()
finally:
os.unlink(TESTFN)
示例6: testBytesOpen
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testBytesOpen(self):
# Opening a bytes filename
try:
fn = TESTFN.encode("ascii")
except UnicodeEncodeError:
# Skip test
return
f = _FileIO(fn, "w")
try:
f.write(b"abc")
f.close()
with open(TESTFN, "rb") as f:
self.assertEqual(f.read(), b"abc")
finally:
os.unlink(TESTFN)
示例7: testWeakRefs
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testWeakRefs(self):
# verify weak references
p = proxy(self.f)
p.write(bytes(range(10)))
self.assertEqual(self.f.tell(), p.tell())
self.f.close()
self.f = None
gc_collect()
self.assertRaises(ReferenceError, getattr, p, 'tell')
示例8: testBytesOpen
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testBytesOpen(self):
# Opening a bytes filename
try:
fn = TESTFN.encode("ascii")
except UnicodeEncodeError:
# Skip test
return
f = self.f = _FileIO(fn, "w")
f.write(b"abc")
f.close()
with open(TESTFN, "rb") as f:
self.f = f
self.assertEqual(f.read(), b"abc")
示例9: testTruncate
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testTruncate(self):
f = self.f = _FileIO(TESTFN, 'w')
f.write(bytes(bytearray(range(10))))
self.assertEqual(f.tell(), 10)
f.truncate(5)
self.assertEqual(f.tell(), 10)
self.assertEqual(f.seek(0, os.SEEK_END), 5)
f.truncate(15)
self.assertEqual(f.tell(), 5)
#XXX: next assert not working in Jython:
#self.assertEqual(f.seek(0, os.SEEK_END), 15)
f.close()
示例10: testTruncateOnWindows
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import py3k_bytes [as 别名]
def testTruncateOnWindows(self):
def bug801631():
# SF bug <http://www.python.org/sf/801631>
# "file.truncate fault on windows"
f = self.f = _FileIO(TESTFN, 'w')
f.write(bytes(range(11)))
f.close()
f = self.f = _FileIO(TESTFN,'r+')
data = f.read(5)
if data != bytes(range(5)):
self.fail("Read on file opened for update failed %r" % data)
if f.tell() != 5:
self.fail("File pos after read wrong %d" % f.tell())
f.truncate()
if f.tell() != 5:
self.fail("File pos after ftruncate wrong %d" % f.tell())
f.close()
size = os.path.getsize(TESTFN)
if size != 5:
self.fail("File size after ftruncate wrong %d" % size)
# Test for bug 801631
bug801631()