当前位置: 首页>>代码示例>>Python>>正文


Python test_support.py3k_bytes方法代码示例

本文整理汇总了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') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_fileio.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_fileio.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_fileio.py

示例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() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_fileio.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_fileio.py

示例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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:17,代码来源:test_fileio.py

示例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') 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:11,代码来源:test_fileio.py

示例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") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:15,代码来源:test_fileio.py

示例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() 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:14,代码来源:test_fileio.py

示例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() 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:28,代码来源:test_fileio.py


注:本文中的test.test_support.py3k_bytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。