本文整理匯總了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()