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


Python test_support.unlink函数代码示例

本文整理汇总了Python中test.test_support.unlink函数的典型用法代码示例。如果您正苦于以下问题:Python unlink函数的具体用法?Python unlink怎么用?Python unlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_tofromfile

 def test_tofromfile(self):
     if test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=313708"):
         return
     a = array.array(self.typecode, 2*self.example)
     self.assertRaises(TypeError, a.tofile)
     self.assertRaises(TypeError, a.tofile, cStringIO.StringIO())
     test_support.unlink(test_support.TESTFN)
     f = open(test_support.TESTFN, 'wb')
     try:
         a.tofile(f)
         f.close()
         b = array.array(self.typecode)
         f = open(test_support.TESTFN, 'rb')
         self.assertRaises(TypeError, b.fromfile)
         self.assertRaises(
             TypeError,
             b.fromfile,
             cStringIO.StringIO(), len(self.example)
         )
         b.fromfile(f, len(self.example))
         self.assertEqual(b, array.array(self.typecode, self.example))
         self.assertNotEqual(a, b)
         b.fromfile(f, len(self.example))
         self.assertEqual(a, b)
         self.assertRaises(EOFError, b.fromfile, f, 1)
         f.close()
     finally:
         if not f.closed:
             f.close()
         test_support.unlink(test_support.TESTFN)
开发者ID:BillyboyD,项目名称:main,代码行数:30,代码来源:test_array.py

示例2: test_builtin_max_min

    def test_builtin_max_min(self):
        self.assertEqual(max(SequenceClass(5)), 4)
        self.assertEqual(min(SequenceClass(5)), 0)
        self.assertEqual(max(8, -1), 8)
        self.assertEqual(min(8, -1), -1)

        d = {"one": 1, "two": 2, "three": 3}
        self.assertEqual(max(d), "two")
        self.assertEqual(min(d), "one")
        self.assertEqual(max(d.itervalues()), 3)
        self.assertEqual(min(iter(d.itervalues())), 1)

        f = open(TESTFN, "w")
        try:
            f.write("medium line\n")
            f.write("xtra large line\n")
            f.write("itty-bitty line\n")
        finally:
            f.close()
        f = open(TESTFN, "r")
        try:
            self.assertEqual(min(f), "itty-bitty line\n")
            f.seek(0, 0)
            self.assertEqual(max(f), "xtra large line\n")
        finally:
            f.close()
            try:
                unlink(TESTFN)
            except OSError:
                pass
开发者ID:BillyboyD,项目名称:main,代码行数:30,代码来源:test_iter.py

示例3: test_realpath_resolve_before_normalizing

        def test_realpath_resolve_before_normalizing(self):
            # Bug #990669: Symbolic links should be resolved before we
            # normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
            # in the following hierarchy:
            # a/k/y
            #
            # and a symbolic link 'link-y' pointing to 'y' in directory 'a',
            # then realpath("link-y/..") should return 'k', not 'a'.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.mkdir(ABSTFN + "/k/y")
                os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y")

                # Absolute path.
                self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
                # Relative path.
                with support.change_cwd(dirname(ABSTFN)):
                    self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
                                     ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "/link-y")
                safe_rmdir(ABSTFN + "/k/y")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:25,代码来源:test_posixpath.py

示例4: test_write_long_to_file

 def test_write_long_to_file(self):
     for v in range(marshal.version + 1):
         _testcapi.pymarshal_write_long_to_file(0x12345678, test_support.TESTFN, v)
         with open(test_support.TESTFN, 'rb') as f:
             data = f.read()
         test_support.unlink(test_support.TESTFN)
         self.assertEqual(data, b'\x78\x56\x34\x12')
开发者ID:abhinavthomas,项目名称:pypy,代码行数:7,代码来源:test_marshal.py

示例5: test_countOf

    def test_countOf(self):
        from operator import countOf
        self.assertEqual(countOf([1,2,2,3,2,5], 2), 3)
        self.assertEqual(countOf((1,2,2,3,2,5), 2), 3)
        self.assertEqual(countOf("122325", "2"), 3)
        self.assertEqual(countOf("122325", "6"), 0)

        self.assertRaises(TypeError, countOf, 42, 1)
        self.assertRaises(TypeError, countOf, countOf, countOf)

        d = {"one": 3, "two": 3, "three": 3, 1j: 2j}
        for k in d:
            self.assertEqual(countOf(d, k), 1)
        self.assertEqual(countOf(d.itervalues(), 3), 3)
        self.assertEqual(countOf(d.itervalues(), 2j), 1)
        self.assertEqual(countOf(d.itervalues(), 1j), 0)

        f = open(TESTFN, "w")
        try:
            f.write("a\n" "b\n" "c\n" "b\n")
        finally:
            f.close()
        f = open(TESTFN, "r")
        try:
            for letter, count in ("a", 1), ("b", 2), ("c", 1), ("d", 0):
                f.seek(0, 0)
                self.assertEqual(countOf(f, letter + "\n"), count)
        finally:
            f.close()
            try:
                unlink(TESTFN)
            except OSError:
                pass
开发者ID:BillyboyD,项目名称:main,代码行数:33,代码来源:test_iter.py

示例6: test_builtin_tuple

    def test_builtin_tuple(self):
        self.assertEqual(tuple(SequenceClass(5)), (0, 1, 2, 3, 4))
        self.assertEqual(tuple(SequenceClass(0)), ())
        self.assertEqual(tuple([]), ())
        self.assertEqual(tuple(()), ())
        self.assertEqual(tuple("abc"), ("a", "b", "c"))

        d = {"one": 1, "two": 2, "three": 3}
        self.assertEqual(tuple(d), tuple(d.keys()))

        self.assertRaises(TypeError, tuple, list)
        self.assertRaises(TypeError, tuple, 42)

        f = open(TESTFN, "w")
        try:
            for i in range(5):
                f.write("%d\n" % i)
        finally:
            f.close()
        f = open(TESTFN, "r")
        try:
            self.assertEqual(tuple(f), ("0\n", "1\n", "2\n", "3\n", "4\n"))
            f.seek(0, 0)
            self.assertEqual(tuple(f),
                             ("0\n", "1\n", "2\n", "3\n", "4\n"))
        finally:
            f.close()
            try:
                unlink(TESTFN)
            except OSError:
                pass
开发者ID:BillyboyD,项目名称:main,代码行数:31,代码来源:test_iter.py

示例7: test_read_short_from_file

 def test_read_short_from_file(self):
     with open(test_support.TESTFN, "wb") as f:
         f.write(b"\x34\x12xxxx")
     r, p = _testcapi.pymarshal_read_short_from_file(test_support.TESTFN)
     test_support.unlink(test_support.TESTFN)
     self.assertEqual(r, 0x1234)
     self.assertEqual(p, 2)
开发者ID:bq,项目名称:witbox-updater,代码行数:7,代码来源:test_marshal.py

示例8: test_execfile

    def test_execfile(self):
        globals = {'a': 1, 'b': 2}
        locals = {'b': 200, 'c': 300}

        class M:
            "Test mapping interface versus possible calls from execfile()."
            def __init__(self):
                self.z = 10
            def __getitem__(self, key):
                if key == 'z':
                    return self.z
                raise KeyError
            def __setitem__(self, key, value):
                if key == 'z':
                    self.z = value
                    return
                raise KeyError

        locals = M()
        locals['z'] = 0
        execfile(TESTFN, globals, locals)
        self.assertEqual(locals['z'], 2)

        self.assertRaises(TypeError, execfile)
        self.assertRaises(TypeError, execfile, TESTFN, {}, ())
        unlink(TESTFN)
开发者ID:aniket134,项目名称:XBMC-video-plugins,代码行数:26,代码来源:test_builtin_jy.py

示例9: test_tofromfile

 def test_tofromfile(self):
     a = array.array(self.typecode, 2*self.example)
     self.assertRaises(TypeError, a.tofile)
     self.assertRaises(TypeError, a.tofile, cStringIO.StringIO())
     test_support.unlink(test_support.TESTFN)
     f = open(test_support.TESTFN, 'wb')
     try:
         a.tofile(f)
         f.close()
         b = array.array(self.typecode)
         f = open(test_support.TESTFN, 'rb')
         self.assertRaises(TypeError, b.fromfile)
         self.assertRaises(
             TypeError,
             b.fromfile,
             cStringIO.StringIO(), len(self.example)
         )
         b.fromfile(f, len(self.example))
         self.assertEqual(b, array.array(self.typecode, self.example))
         self.assertNotEqual(a, b)
         b.fromfile(f, len(self.example))
         self.assertEqual(a, b)
         self.assertRaises(EOFError, b.fromfile, f, 1)
         f.close()
     finally:
         if not f.closed:
             f.close()
         test_support.unlink(test_support.TESTFN)
开发者ID:AojiaoZero,项目名称:CrossApp,代码行数:28,代码来源:test_array.py

示例10: test_encode

    def test_encode(self):
        fin = fout = None
        try:
            test_support.unlink(self.tmpin)
            fin = open(self.tmpin, 'wb')
            fin.write(plaintext)
            fin.close()

            fin = open(self.tmpin, 'rb')
            fout = open(self.tmpout, 'w')
            uu.encode(fin, fout, self.tmpin, mode=0644)
            fin.close()
            fout.close()

            fout = open(self.tmpout, 'r')
            s = fout.read()
            fout.close()
            self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))

            # in_file and out_file as filenames
            uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0644)
            fout = open(self.tmpout, 'r')
            s = fout.read()
            fout.close()
            self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))

        finally:
            self._kill(fin)
            self._kill(fout)
开发者ID:321boom,项目名称:The-Powder-Toy,代码行数:29,代码来源:test_uu.py

示例11: _testBogusZipFile

    def _testBogusZipFile(self):
        test_support.unlink(TESTMOD)
        fp = open(TESTMOD, 'w+')
        fp.write(struct.pack('=I', 0x06054B50))
        fp.write('a' * 18)
        fp.close()
        z = zipimport.zipimporter(TESTMOD)

        try:
            self.assertRaises(TypeError, z.find_module, None)
            self.assertRaises(TypeError, z.load_module, None)
            self.assertRaises(TypeError, z.is_package, None)
            self.assertRaises(TypeError, z.get_code, None)
            self.assertRaises(TypeError, z.get_data, None)
            self.assertRaises(TypeError, z.get_source, None)

            error = zipimport.ZipImportError
            self.assertEqual(z.find_module('abc'), None)

            self.assertRaises(error, z.load_module, 'abc')
            self.assertRaises(error, z.get_code, 'abc')
            self.assertRaises(IOError, z.get_data, 'abc')
            self.assertRaises(error, z.get_source, 'abc')
            self.assertRaises(error, z.is_package, 'abc')
        finally:
            zipimport._zip_directory_cache.clear()
开发者ID:2uller,项目名称:LotF,代码行数:26,代码来源:test_zipimport.py

示例12: test_input_and_raw_input

 def test_input_and_raw_input(self):
     self.write_testfile()
     fp = open(TESTFN, 'r')
     savestdin = sys.stdin
     savestdout = sys.stdout # Eats the echo
     try:
         sys.stdin = fp
         sys.stdout = BitBucket()
         self.assertEqual(input(), 2)
         self.assertEqual(input('testing\n'), 2)
         self.assertEqual(raw_input(), 'The quick brown fox jumps over the lazy dog.')
         self.assertEqual(raw_input('testing\n'), 'Dear John')
         sys.stdin = cStringIO.StringIO("NULL\0")
         self.assertRaises(TypeError, input, 42, 42)
         sys.stdin = cStringIO.StringIO("    'whitespace'")
         self.assertEqual(input(), 'whitespace')
         sys.stdin = cStringIO.StringIO()
         self.assertRaises(EOFError, input)
         del sys.stdout
         self.assertRaises(RuntimeError, input, 'prompt')
         del sys.stdin
         self.assertRaises(RuntimeError, input, 'prompt')
     finally:
         sys.stdin = savestdin
         sys.stdout = savestdout
         fp.close()
         unlink(TESTFN)
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:27,代码来源:230_test_builtin.py

示例13: suite

def suite():
    try:
        # this is special, it used to segfault the interpreter
        import bsddb.test.test_1413192
    except:
        for f in ['__db.001', '__db.002', '__db.003', 'log.0000000001']:
            unlink(f)

    test_modules = [
        'test_associate',
        'test_basics',
        'test_compat',
        'test_dbobj',
        'test_dbshelve',
        'test_dbtables',
        'test_env_close',
        'test_get_none',
        'test_join',
        'test_lock',
        'test_misc',
        'test_queue',
        'test_recno',
        'test_thread',
        'test_sequence',
        'test_cursor_pget_bug',
        ]

    alltests = unittest.TestSuite()
    for name in test_modules:
        module = __import__("bsddb.test."+name, globals(), locals(), name)
        #print module,name
        alltests.addTest(module.test_suite())
    return alltests
开发者ID:Alex-CS,项目名称:sonify,代码行数:33,代码来源:test_bsddb3.py

示例14: testThreads

 def testThreads(self):
     # BufferedWriter should not raise exceptions or crash
     # when called from multiple threads.
     try:
         # We use a real file object because it allows us to
         # exercise situations where the GIL is released before
         # writing the buffer to the raw streams. This is in addition
         # to concurrency issues due to switching threads in the middle
         # of Python code.
         with io.open(test_support.TESTFN, "wb", buffering=0) as raw:
             bufio = io.BufferedWriter(raw, 8)
             errors = []
             def f():
                 try:
                     # Write enough bytes to flush the buffer
                     s = b"a" * 19
                     for i in range(50):
                         bufio.write(s)
                 except Exception as e:
                     errors.append(e)
                     raise
             threads = [threading.Thread(target=f) for x in range(20)]
             for t in threads:
                 t.start()
             time.sleep(0.02) # yield
             for t in threads:
                 t.join()
             self.assertFalse(errors,
                 "the following exceptions were caught: %r" % errors)
     finally:
         test_support.unlink(test_support.TESTFN)
开发者ID:CRYPTOlab,项目名称:python-resin,代码行数:31,代码来源:test_io.py

示例15: test_read_long_from_file

 def test_read_long_from_file(self):
     with open(test_support.TESTFN, 'wb') as f:
         f.write(b'\x78\x56\x34\x12xxxx')
     r, p = _testcapi.pymarshal_read_long_from_file(test_support.TESTFN)
     test_support.unlink(test_support.TESTFN)
     self.assertEqual(r, 0x12345678)
     self.assertEqual(p, 4)
开发者ID:abhinavthomas,项目名称:pypy,代码行数:7,代码来源:test_marshal.py


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