本文整理汇总了Python中_pyio.open方法的典型用法代码示例。如果您正苦于以下问题:Python _pyio.open方法的具体用法?Python _pyio.open怎么用?Python _pyio.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pyio
的用法示例。
在下文中一共展示了_pyio.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSetBufferSize
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testSetBufferSize(self):
# make sure that explicitly setting the buffer size doesn't cause
# misbehaviour especially with repeated close() calls
for s in (-1, 0, 1, 512):
try:
f = self.open(TESTFN, 'wb', s)
f.write(str(s).encode("ascii"))
f.close()
f.close()
f = self.open(TESTFN, 'rb', s)
d = int(f.read().decode("ascii"))
f.close()
f.close()
except IOError as msg:
self.fail('error setting buffer size %d: %s' % (s, str(msg)))
self.assertEqual(d, s)
示例2: test_main
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def test_main():
base_tests = (TestCRNewlines,
TestLFNewlines,
TestCRLFNewlines,
TestMixedNewlines)
tests = []
# Test the C and Python implementations.
for test in base_tests:
class CTest(test):
open = io.open
CTest.__name__ = str("C" + test.__name__)
class PyTest(test):
open = staticmethod(pyio.open)
PyTest.__name__ = str("Py" + test.__name__)
tests.append(CTest)
tests.append(PyTest)
support.run_unittest(*tests)
示例3: testSetBufferSize
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testSetBufferSize(self):
# make sure that explicitly setting the buffer size doesn't cause
# misbehaviour especially with repeated close() calls
for s in (-1, 0, 1, 512):
try:
f = self.open(TESTFN, 'wb', s)
f.write(str(s).encode("ascii"))
f.close()
f.close()
f = self.open(TESTFN, 'rb', s)
d = int(f.read().decode("ascii"))
f.close()
f.close()
except OSError as msg:
self.fail('error setting buffer size %d: %s' % (s, str(msg)))
self.assertEqual(d, s)
示例4: setUp
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def setUp(self):
self.f = self.open(TESTFN, 'wb')
示例5: testReadinto
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testReadinto(self):
# verify readinto
self.f.write(b'12')
self.f.close()
a = array('b', b'x'*10)
self.f = self.open(TESTFN, 'rb')
n = self.f.readinto(a)
self.assertEqual(b'12', a.tostring()[:n])
示例6: testReadinto_text
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testReadinto_text(self):
# verify readinto refuses text files
a = array('b', b'x'*10)
self.f.close()
self.f = self.open(TESTFN, 'r')
if hasattr(self.f, "readinto"):
self.assertRaises(TypeError, self.f.readinto, a)
示例7: testWritelinesUserList
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testWritelinesUserList(self):
# verify writelines with instance sequence
l = UserList([b'1', b'2'])
self.f.writelines(l)
self.f.close()
self.f = self.open(TESTFN, 'rb')
buf = self.f.read()
self.assertEqual(buf, b'12')
示例8: testModeStrings
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testModeStrings(self):
# check invalid mode strings
self.open(TESTFN, 'wb').close()
for mode in ("", "aU", "wU+"):
try:
f = self.open(TESTFN, mode)
except ValueError:
pass
else:
f.close()
self.fail('%r is an invalid file mode' % mode)
示例9: testTruncateOnWindows
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testTruncateOnWindows(self):
# SF bug <http://www.python.org/sf/801631>
# "file.truncate fault on windows"
f = self.open(TESTFN, 'wb')
try:
f.write(b'12345678901') # 11 bytes
f.close()
f = self.open(TESTFN,'rb+')
data = f.read(5)
if data != b'12345':
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)
finally:
f.close()
示例10: setUp
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def setUp(self):
data = self.DATA
if "b" in self.WRITEMODE:
data = data.encode("ascii")
with self.open(support.TESTFN, self.WRITEMODE) as fp:
fp.write(data)
示例11: test_read
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def test_read(self):
with self.open(support.TESTFN, self.READMODE) as fp:
data = fp.read()
self.assertEqual(data, DATA_LF)
self.assertEqual(set(fp.newlines), set(self.NEWLINE))
示例12: test_readlines
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def test_readlines(self):
with self.open(support.TESTFN, self.READMODE) as fp:
data = fp.readlines()
self.assertEqual(data, DATA_SPLIT)
self.assertEqual(set(fp.newlines), set(self.NEWLINE))
示例13: test_seek
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def test_seek(self):
with self.open(support.TESTFN, self.READMODE) as fp:
fp.readline()
pos = fp.tell()
data = fp.readlines()
self.assertEqual(data, DATA_SPLIT[1:])
fp.seek(pos)
data = fp.readlines()
self.assertEqual(data, DATA_SPLIT[1:])
示例14: test_tell
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def test_tell(self):
with self.open(support.TESTFN, self.READMODE) as fp:
self.assertEqual(repr(fp.newlines), repr(None))
data = fp.readline()
pos = fp.tell()
self.assertEqual(repr(fp.newlines), repr(self.NEWLINE))
示例15: testModeStrings
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import open [as 别名]
def testModeStrings(self):
# check invalid mode strings
for mode in ("", "aU", "wU+"):
try:
f = self.open(TESTFN, mode)
except ValueError:
pass
else:
f.close()
self.fail('%r is an invalid file mode' % mode)