• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python support.create_empty_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_package___file__

 def test_package___file__(self):
     try:
         m = __import__('pep3147')
     except ImportError:
         pass
     else:
         self.fail("pep3147 module already exists: %r" % (m,))
     # Test that a package's __file__ points to the right source directory.
     os.mkdir('pep3147')
     sys.path.insert(0, os.curdir)
     def cleanup():
         if sys.path[0] == os.curdir:
             del sys.path[0]
         shutil.rmtree('pep3147')
     self.addCleanup(cleanup)
     # Touch the __init__.py file.
     support.create_empty_file('pep3147/__init__.py')
     importlib.invalidate_caches()
     expected___file__ = os.sep.join(('.', 'pep3147', '__init__.py'))
     m = __import__('pep3147')
     self.assertEqual(m.__file__, expected___file__, (m.__file__, m.__path__, sys.path, sys.path_importer_cache))
     # Ensure we load the pyc file.
     support.unload('pep3147')
     m = __import__('pep3147')
     support.unload('pep3147')
     self.assertEqual(m.__file__, expected___file__, (m.__file__, m.__path__, sys.path, sys.path_importer_cache))
开发者ID:LPRD,项目名称:build_tools,代码行数:26,代码来源:test_imp.py


示例2: _add_pkg_dir

 def _add_pkg_dir(self, pkg_dir, namespace=False):
     os.mkdir(pkg_dir)
     if namespace:
         return None
     pkg_fname = os.path.join(pkg_dir, "__init__.py")
     create_empty_file(pkg_fname)
     return pkg_fname
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:7,代码来源:test_runpy.py


示例3: _add_relative_modules

 def _add_relative_modules(self, base_dir, source, depth):
     if depth <= 1:
         raise ValueError("Relative module test needs depth > 1")
     pkg_name = "__runpy_pkg__"
     module_dir = base_dir
     for i in range(depth):
         parent_dir = module_dir
         module_dir = os.path.join(module_dir, pkg_name)
     # Add sibling module
     sibling_fname = os.path.join(module_dir, "sibling.py")
     create_empty_file(sibling_fname)
     if verbose > 1:
         print("  Added sibling module:", sibling_fname)
     # Add nephew module
     uncle_dir = os.path.join(parent_dir, "uncle")
     self._add_pkg_dir(uncle_dir)
     if verbose > 1:
         print("  Added uncle package:", uncle_dir)
     cousin_dir = os.path.join(uncle_dir, "cousin")
     self._add_pkg_dir(cousin_dir)
     if verbose > 1:
         print("  Added cousin package:", cousin_dir)
     nephew_fname = os.path.join(cousin_dir, "nephew.py")
     create_empty_file(nephew_fname)
     if verbose > 1:
         print("  Added nephew module:", nephew_fname)
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:26,代码来源:test_runpy.py


示例4: setUp

 def setUp(self):
     self.test_dir = tempfile.mkdtemp()
     sys.path.append(self.test_dir)
     self.package_dir = os.path.join(self.test_dir, self.package_name)
     os.mkdir(self.package_dir)
     create_empty_file(os.path.join(self.package_dir, "__init__.py"))
     self.module_path = os.path.join(self.package_dir, "foo.py")
开发者ID:harveyqing,项目名称:read_cPython_source,代码行数:7,代码来源:test_pkgimport.py


示例5: test_module

 def test_module(self):
     self._check_path_limitations(self.pkgname)
     create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py'))
     importlib.invalidate_caches()
     from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
     module = areallylongpackageandmodulenametotestreprtruncation
     self.assertEqual(repr(module), "<module %r from %r>" % (module.__name__, module.__file__))
     self.assertEqual(repr(sys), "<module 'sys' (built-in)>")
开发者ID:timm,项目名称:timmnix,代码行数:8,代码来源:test_reprlib.py


示例6: test_chown

    def test_chown(self):
        # raise an OSError if the file does not exist
        os.unlink(support.TESTFN)
        self.assertRaises(OSError, posix.chown, support.TESTFN, -1, -1)

        # re-create the file
        support.create_empty_file(support.TESTFN)
        self._test_all_chown_common(posix.chown, support.TESTFN, getattr(posix, "stat", None))
开发者ID:collinanderson,项目名称:ensurepip,代码行数:8,代码来源:test_posix.py


示例7: test_fchownat

    def test_fchownat(self):
        support.unlink(support.TESTFN)
        support.create_empty_file(support.TESTFN)

        f = posix.open(posix.getcwd(), posix.O_RDONLY)
        try:
            posix.fchownat(f, support.TESTFN, os.getuid(), os.getgid())
        finally:
            posix.close(f)
开发者ID:Naddiseo,项目名称:cpython,代码行数:9,代码来源:test_posix.py


示例8: test_chown_dir_fd

    def test_chown_dir_fd(self):
        support.unlink(support.TESTFN)
        support.create_empty_file(support.TESTFN)

        f = posix.open(posix.getcwd(), posix.O_RDONLY)
        try:
            posix.chown(support.TESTFN, os.getuid(), os.getgid(), dir_fd=f)
        finally:
            posix.close(f)
开发者ID:NitikaAgarwal,项目名称:cpython,代码行数:9,代码来源:test_posix.py


示例9: test_reload_location_changed

    def test_reload_location_changed(self):
        name = "spam"
        with support.temp_cwd(None) as cwd:
            with test_util.uncache("spam"):
                with support.DirsOnSysPath(cwd):
                    # Start as a plain module.
                    self.init.invalidate_caches()
                    path = os.path.join(cwd, name + ".py")
                    cached = self.util.cache_from_source(path)
                    expected = {
                        "__name__": name,
                        "__package__": "",
                        "__file__": path,
                        "__cached__": cached,
                        "__doc__": None,
                    }
                    support.create_empty_file(path)
                    module = self.init.import_module(name)
                    ns = vars(module).copy()
                    loader = ns.pop("__loader__")
                    spec = ns.pop("__spec__")
                    ns.pop("__builtins__", None)  # An implementation detail.
                    self.assertEqual(spec.name, name)
                    self.assertEqual(spec.loader, loader)
                    self.assertEqual(loader.path, path)
                    self.assertEqual(ns, expected)

                    # Change to a package.
                    self.init.invalidate_caches()
                    init_path = os.path.join(cwd, name, "__init__.py")
                    cached = self.util.cache_from_source(init_path)
                    expected = {
                        "__name__": name,
                        "__package__": name,
                        "__file__": init_path,
                        "__cached__": cached,
                        "__path__": [os.path.dirname(init_path)],
                        "__doc__": None,
                    }
                    os.mkdir(name)
                    os.rename(path, init_path)
                    reloaded = self.init.reload(module)
                    ns = vars(reloaded).copy()
                    loader = ns.pop("__loader__")
                    spec = ns.pop("__spec__")
                    ns.pop("__builtins__", None)  # An implementation detail.
                    self.assertEqual(spec.name, name)
                    self.assertEqual(spec.loader, loader)
                    self.assertIs(reloaded, module)
                    self.assertEqual(loader.path, init_path)
                    self.maxDiff = None
                    self.assertEqual(ns, expected)
开发者ID:ChanChiChoi,项目名称:cpython,代码行数:52,代码来源:test_api.py


示例10: test_unlink_dir_fd

 def test_unlink_dir_fd(self):
     f = posix.open(posix.getcwd(), posix.O_RDONLY)
     support.create_empty_file(support.TESTFN + 'del')
     posix.stat(support.TESTFN + 'del') # should not raise exception
     try:
         posix.unlink(support.TESTFN + 'del', dir_fd=f)
     except:
         support.unlink(support.TESTFN + 'del')
         raise
     else:
         self.assertRaises(OSError, posix.stat, support.TESTFN + 'link')
     finally:
         posix.close(f)
开发者ID:NitikaAgarwal,项目名称:cpython,代码行数:13,代码来源:test_posix.py


示例11: test_rename_dir_fd

 def test_rename_dir_fd(self):
     support.unlink(support.TESTFN)
     support.create_empty_file(support.TESTFN + 'ren')
     f = posix.open(posix.getcwd(), posix.O_RDONLY)
     try:
         posix.rename(support.TESTFN + 'ren', support.TESTFN, src_dir_fd=f, dst_dir_fd=f)
     except:
         posix.rename(support.TESTFN + 'ren', support.TESTFN)
         raise
     else:
         posix.stat(support.TESTFN) # should not raise exception
     finally:
         posix.close(f)
开发者ID:NitikaAgarwal,项目名称:cpython,代码行数:13,代码来源:test_posix.py


示例12: test_reload_location_changed

    def test_reload_location_changed(self):
        name = 'spam'
        with support.temp_cwd(None) as cwd:
            with util.uncache('spam'):
                with support.DirsOnSysPath(cwd):
                    # Start as a plain module.
                    self.init.invalidate_caches()
                    path = os.path.join(cwd, name + '.py')
                    cached = self.util.cache_from_source(path)
                    expected = {'__name__': name,
                                '__package__': '',
                                '__file__': path,
                                '__cached__': cached,
                                '__doc__': None,
                                '__builtins__': __builtins__,
                                }
                    support.create_empty_file(path)
                    module = self.init.import_module(name)
                    ns = vars(module)
                    loader = ns.pop('__loader__')
                    spec = ns.pop('__spec__')
                    self.assertEqual(spec.name, name)
                    self.assertEqual(spec.loader, loader)
                    self.assertEqual(loader.path, path)
                    self.assertEqual(ns, expected)

                    # Change to a package.
                    self.init.invalidate_caches()
                    init_path = os.path.join(cwd, name, '__init__.py')
                    cached = self.util.cache_from_source(init_path)
                    expected = {'__name__': name,
                                '__package__': name,
                                '__file__': init_path,
                                '__cached__': cached,
                                '__path__': [os.path.dirname(init_path)],
                                '__doc__': None,
                                '__builtins__': __builtins__,
                                }
                    os.mkdir(name)
                    os.rename(path, init_path)
                    reloaded = self.init.reload(module)
                    ns = vars(reloaded)
                    loader = ns.pop('__loader__')
                    spec = ns.pop('__spec__')
                    self.assertEqual(spec.name, name)
                    self.assertEqual(spec.loader, loader)
                    self.assertIs(reloaded, module)
                    self.assertEqual(loader.path, init_path)
                    self.maxDiff = None
                    self.assertEqual(ns, expected)
开发者ID:LesyaMazurevich,项目名称:python-1,代码行数:50,代码来源:test_api.py


示例13: _test_single

 def _test_single(self, filename):
     remove_if_exists(filename)
     create_empty_file(filename)
     try:
         self._do_single(filename)
     finally:
         os.unlink(filename)
     self.assertTrue(not os.path.exists(filename))
     # and again with os.open.
     f = os.open(filename, os.O_CREAT)
     os.close(f)
     try:
         self._do_single(filename)
     finally:
         os.unlink(filename)
开发者ID:3lnc,项目名称:cpython,代码行数:15,代码来源:test_unicode_file.py


示例14: setUp

 def setUp(self):
     self.pkgname = os.path.join(self.longname)
     self.subpkgname = os.path.join(self.longname, self.longname)
     # Make the package and subpackage
     shutil.rmtree(self.pkgname, ignore_errors=True)
     os.mkdir(self.pkgname)
     create_empty_file(os.path.join(self.pkgname, '__init__.py'))
     shutil.rmtree(self.subpkgname, ignore_errors=True)
     os.mkdir(self.subpkgname)
     create_empty_file(os.path.join(self.subpkgname, '__init__.py'))
     # Remember where we are
     self.here = os.getcwd()
     sys.path.insert(0, self.here)
     # When regrtest is run with its -j option, this command alone is not
     # enough.
     importlib.invalidate_caches()
开发者ID:timm,项目名称:timmnix,代码行数:16,代码来源:test_reprlib.py


示例15: test_selflink

    def test_selflink(self):
        tempdir = TESTFN + "_dir"
        os.makedirs(tempdir)
        self.addCleanup(shutil.rmtree, tempdir)
        with change_cwd(tempdir):
            os.makedirs("dir")
            create_empty_file(os.path.join("dir", "file"))
            os.symlink(os.curdir, os.path.join("dir", "link"))

            results = glob.glob("**", recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(["dir"] + ["link"] * depth))
                self.assertIn(path, results)
                results.remove(path)
                if not results:
                    break
                path = os.path.join(path, "file")
                self.assertIn(path, results)
                results.remove(path)
                depth += 1

            results = glob.glob(os.path.join("**", "file"), recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(["dir"] + ["link"] * depth + ["file"]))
                self.assertIn(path, results)
                results.remove(path)
                depth += 1

            results = glob.glob(os.path.join("**", ""), recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(["dir"] + ["link"] * depth + [""]))
                self.assertIn(path, results)
                results.remove(path)
                depth += 1
开发者ID:ChanChiChoi,项目名称:cpython,代码行数:43,代码来源:test_glob.py


示例16: test_selflink

    def test_selflink(self):
        tempdir = TESTFN + "_dir"
        os.makedirs(tempdir)
        self.addCleanup(shutil.rmtree, tempdir)
        with change_cwd(tempdir):
            os.makedirs('dir')
            create_empty_file(os.path.join('dir', 'file'))
            os.symlink(os.curdir, os.path.join('dir', 'link'))

            results = glob.glob('**', recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(['dir'] + ['link'] * depth))
                self.assertIn(path, results)
                results.remove(path)
                if not results:
                    break
                path = os.path.join(path, 'file')
                self.assertIn(path, results)
                results.remove(path)
                depth += 1

            results = glob.glob(os.path.join('**', 'file'), recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(['dir'] + ['link'] * depth + ['file']))
                self.assertIn(path, results)
                results.remove(path)
                depth += 1

            results = glob.glob(os.path.join('**', ''), recursive=True)
            self.assertEqual(len(results), len(set(results)))
            results = set(results)
            depth = 0
            while results:
                path = os.path.join(*(['dir'] + ['link'] * depth + ['']))
                self.assertIn(path, results)
                results.remove(path)
                depth += 1
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:43,代码来源:test_glob.py


示例17: test_creation_mode

 def test_creation_mode(self):
     mask = 0o022
     with temp_umask(mask):
         sys.path.insert(0, os.curdir)
         try:
             fname = TESTFN + os.extsep + "py"
             create_empty_file(fname)
             fn = imp.cache_from_source(fname)
             unlink(fn)
             importlib.invalidate_caches()
             __import__(TESTFN)
             if not os.path.exists(fn):
                 self.fail("__import__ did not result in creation of " "either a .pyc or .pyo file")
             s = os.stat(fn)
             # Check that the umask is respected, and the executable bits
             # aren't set.
             self.assertEqual(stat.S_IMODE(s.st_mode), 0o666 & ~mask)
         finally:
             del sys.path[0]
             remove_files(TESTFN)
             unload(TESTFN)
开发者ID:certik,项目名称:python-3.3,代码行数:21,代码来源:test_import.py


示例18: test_on_error

        def test_on_error(self):
            self.errorState = 0
            os.mkdir(TESTFN)
            self.childpath = os.path.join(TESTFN, 'a')
            support.create_empty_file(self.childpath)
            old_dir_mode = os.stat(TESTFN).st_mode
            old_child_mode = os.stat(self.childpath).st_mode
            # Make unwritable.
            os.chmod(self.childpath, stat.S_IREAD)
            os.chmod(TESTFN, stat.S_IREAD)

            shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
            # Test whether onerror has actually been called.
            self.assertEqual(self.errorState, 2,
                             "Expected call to onerror function did not happen.")

            # Make writable again.
            os.chmod(TESTFN, old_dir_mode)
            os.chmod(self.childpath, old_child_mode)

            # Clean up.
            shutil.rmtree(TESTFN)
开发者ID:Naddiseo,项目名称:cpython,代码行数:22,代码来源:test_shutil.py


示例19: testEmptyFile

 def testEmptyFile(self):
     support.unlink(TESTMOD)
     support.create_empty_file(TESTMOD)
     self.assertZipFailure(TESTMOD)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:4,代码来源:test_zipimport.py


示例20: mktemp

 def mktemp(self, *parts):
     filename = self.norm(*parts)
     base, file = os.path.split(filename)
     if not os.path.exists(base):
         os.makedirs(base)
     create_empty_file(filename)
开发者ID:0jpq0,项目名称:kbengine,代码行数:6,代码来源:test_glob.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python support.find_unused_port函数代码示例发布时间:2022-05-27
下一篇:
Python support.check_warnings函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap