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


Python test_support.unlink方法代码示例

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


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

示例1: test_debug_mode

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_debug_mode(self):
        with open(TESTFN, "w") as f:
            f.write("[global]\n")
            f.write("command_packages = foo.bar, splat")
        self.addCleanup(unlink, TESTFN)

        files = [TESTFN]
        sys.argv.append("build")

        with captured_stdout() as stdout:
            self.create_distribution(files)
        stdout.seek(0)
        self.assertEqual(stdout.read(), '')
        distutils.dist.DEBUG = True
        try:
            with captured_stdout() as stdout:
                self.create_distribution(files)
            stdout.seek(0)
            self.assertEqual(stdout.read(), '')
        finally:
            distutils.dist.DEBUG = False 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_dist.py

示例2: test_command_packages_configfile

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_command_packages_configfile(self):
        sys.argv.append("build")
        self.addCleanup(os.unlink, TESTFN)
        f = open(TESTFN, "w")
        try:
            print >> f, "[global]"
            print >> f, "command_packages = foo.bar, splat"
        finally:
            f.close()

        d = self.create_distribution([TESTFN])
        self.assertEqual(d.get_command_packages(),
                         ["distutils.command", "foo.bar", "splat"])

        # ensure command line overrides config:
        sys.argv[1:] = ["--command-packages", "spork", "build"]
        d = self.create_distribution([TESTFN])
        self.assertEqual(d.get_command_packages(),
                         ["distutils.command", "spork"])

        # Setting --command-packages to '' should cause the default to
        # be used even if a config file specified something else:
        sys.argv[1:] = ["--command-packages", "", "build"]
        d = self.create_distribution([TESTFN])
        self.assertEqual(d.get_command_packages(), ["distutils.command"]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_dist.py

示例3: testWithOpen

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def testWithOpen(self):
        tfn = tempfile.mktemp()
        try:
            f = None
            with open(tfn, "w") as f:
                self.assertFalse(f.closed)
                f.write("Booh\n")
            self.assertTrue(f.closed)
            f = None
            with self.assertRaises(ZeroDivisionError):
                with open(tfn, "r") as f:
                    self.assertFalse(f.closed)
                    self.assertEqual(f.read(), "Booh\n")
                    1 // 0
            self.assertTrue(f.closed)
        finally:
            test_support.unlink(tfn) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_contextlib.py

示例4: run_script

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def run_script(self, input="", args=("-",), substfile="xx yy\n"):
        substfilename = test_support.TESTFN + ".subst"
        with open(substfilename, "w") as file:
            file.write(substfile)
        self.addCleanup(test_support.unlink, substfilename)

        argv = ["fixcid.py", "-s", substfilename] + list(args)
        script = os.path.join(scriptsdir, "fixcid.py")
        with test_support.swap_attr(sys, "argv", argv), \
                test_support.swap_attr(sys, "stdin", StringIO(input)), \
                test_support.captured_stdout() as output:
            try:
                runpy.run_path(script, run_name="__main__")
            except SystemExit as exit:
                self.assertEqual(exit.code, 0)
        return output.getvalue() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_tools.py

示例5: test_realpath_deep_recursion

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_realpath_deep_recursion(self):
            depth = 10
            try:
                os.mkdir(ABSTFN)
                for i in range(depth):
                    os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1))
                os.symlink('.', ABSTFN + '/0')
                self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)

                # Test using relative path as well.
                with support.change_cwd(ABSTFN):
                    self.assertEqual(realpath('%d' % depth), ABSTFN)
            finally:
                for i in range(depth + 1):
                    test_support.unlink(ABSTFN + '/%d' % i)
                safe_rmdir(ABSTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_posixpath.py

示例6: test_realpath_resolve_parents

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_realpath_resolve_parents(self):
            # We also need to resolve any symlinks in the parents of a relative
            # path passed to realpath. E.g.: current working directory is
            # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
            # realpath("a"). This should return /usr/share/doc/a/.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/y")
                os.symlink(ABSTFN + "/y", ABSTFN + "/k")

                with support.change_cwd(ABSTFN + "/k"):
                    self.assertEqual(realpath("a"), ABSTFN + "/y/a")
            finally:
                test_support.unlink(ABSTFN + "/k")
                safe_rmdir(ABSTFN + "/y")
                safe_rmdir(ABSTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_posixpath.py

示例7: test_realpath_resolve_before_normalizing

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
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:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_posixpath.py

示例8: test_init_close_fobj

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_init_close_fobj(self):
        # Issue #7341: Close the internal file object in the TarFile
        # constructor in case of an error. For the test we rely on
        # the fact that opening an empty file raises a ReadError.
        empty = os.path.join(TEMPDIR, "empty")
        with open(empty, "wb") as fobj:
            fobj.write("")

        try:
            tar = object.__new__(tarfile.TarFile)
            try:
                tar.__init__(empty)
            except tarfile.ReadError:
                self.assertTrue(tar.fileobj.closed)
            else:
                self.fail("ReadError not raised")
        finally:
            support.unlink(empty) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_tarfile.py

示例9: test_path_with_null_unicode

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_path_with_null_unicode(self):
        fn = test_support.TESTFN_UNICODE
        try:
            fn.encode(test_support.TESTFN_ENCODING)
        except (UnicodeError, TypeError):
            self.skipTest("Requires unicode filenames support")
        fn_with_NUL = fn + u'\0'
        self.addCleanup(test_support.unlink, fn)
        test_support.unlink(fn)
        fd = None
        try:
            with self.assertRaises(TypeError):
                fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
        finally:
            if fd is not None:
                os.close(fd)
        self.assertFalse(os.path.exists(fn))
        self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
        self.assertFalse(os.path.exists(fn))
        open(fn, 'wb').close()
        self.assertRaises(TypeError, os.stat, fn_with_NUL) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_posix.py

示例10: test_path_with_null_byte

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_path_with_null_byte(self):
        fn = test_support.TESTFN
        fn_with_NUL = fn + '\0'
        self.addCleanup(test_support.unlink, fn)
        test_support.unlink(fn)
        fd = None
        try:
            with self.assertRaises(TypeError):
                fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
        finally:
            if fd is not None:
                os.close(fd)
        self.assertFalse(os.path.exists(fn))
        self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
        self.assertFalse(os.path.exists(fn))
        open(fn, 'wb').close()
        self.assertRaises(TypeError, os.stat, fn_with_NUL) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_posix.py

示例11: test_readline

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_readline(self):
        with open(TESTFN, 'wb') as f:
            f.write('A\nB\r\nC\r')
            # Fill TextIOWrapper buffer.
            f.write('123456789\n' * 1000)
            # Issue #20501: readline() shouldn't read whole file.
            f.write('\x80')
        self.addCleanup(safe_unlink, TESTFN)

        fi = FileInput(files=TESTFN, openhook=hook_encoded('ascii'))
        # The most likely failure is a UnicodeDecodeError due to the entire
        # file being read when it shouldn't have been.
        self.assertEqual(fi.readline(), u'A\n')
        self.assertEqual(fi.readline(), u'B\r\n')
        self.assertEqual(fi.readline(), u'C\r')
        with self.assertRaises(UnicodeDecodeError):
            # Read to the end of file.
            list(fi)
        fi.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_fileinput.py

示例12: test_modes

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_modes(self):
        with open(TESTFN, 'wb') as f:
            # UTF-7 is a convenient, seldom used encoding
            f.write('A\nB\r\nC\rD+IKw-')
        self.addCleanup(safe_unlink, TESTFN)

        def check(mode, expected_lines):
            fi = FileInput(files=TESTFN, mode=mode,
                           openhook=hook_encoded('utf-7'))
            lines = list(fi)
            fi.close()
            self.assertEqual(lines, expected_lines)

        check('r', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac'])
        check('rU', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac'])
        check('U', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac'])
        check('rb', [u'A\n', u'B\r\n', u'C\r', u'D\u20ac']) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_fileinput.py

示例13: test_filewrite

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_filewrite(self):
        a = array.array(self.typecode, 2*self.example)
        f = open(test_support.TESTFN, 'wb')
        try:
            f.write(a)
            f.close()
            b = array.array(self.typecode)
            f = open(test_support.TESTFN, 'rb')
            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)
            f.close()
        finally:
            if not f.closed:
                f.close()
            test_support.unlink(test_support.TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_array.py

示例14: test_file_perms

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def test_file_perms(self):
        # From bug #3228, we want to verify that the mailbox file isn't executable,
        # even if the umask is set to something that would leave executable bits set.
        # We only run this test on platforms that support umask.
        try:
            old_umask = os.umask(0077)
            self._box.close()
            os.unlink(self._path)
            self._box = mailbox.mbox(self._path, create=True)
            self._box.add('')
            self._box.close()
        finally:
            os.umask(old_umask)

        st = os.stat(self._path)
        perms = st.st_mode
        self.assertFalse((perms & 0111)) # Execute bits should all be off. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_mailbox.py

示例15: run_pdb

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import unlink [as 别名]
def run_pdb(self, script, commands):
        """Run 'script' lines with pdb and the pdb 'commands'."""
        filename = 'main.py'
        with open(filename, 'w') as f:
            f.write(textwrap.dedent(script))
        self.addCleanup(test_support.unlink, filename)
        cmd = [sys.executable, '-m', 'pdb', filename]
        stdout = stderr = None
        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                   stdin=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   )
        stdout, stderr = proc.communicate(commands)
        proc.stdout.close()
        proc.stdin.close()
        return stdout, stderr 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_pdb.py


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