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


Python platform.open_file函数代码示例

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


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

示例1: _create_paths

    def _create_paths(self):
        """Create the paths for the tests.

        The following structure will be created:

            self.basedir/
            |-> self.testfile
            |-> dir0/
                |-> file0
                |-> link
            |-> dir1/
                |-> file1
                |-> dir11/
            |-> dir2/
                |-> file2
            |-> dir3/

        """
        open_file(self.testfile, 'w').close()

        for i in xrange(3):
            dir_name = 'dir%i' % i
            dir_path = os.path.join(self.basedir, dir_name)
            make_dir(dir_path, recursive=True)

            file_name = 'file%i' % i
            file_path = os.path.join(dir_path, file_name)
            open_file(file_path, "w").close()

        make_link(os.path.devnull,
                  os.path.join(self.basedir, 'dir0', 'link'))
        make_dir(os.path.join(self.basedir, 'dir1', 'dir11'))
        make_dir(os.path.join(self.basedir, 'dir3'), recursive=True)
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:33,代码来源:test_os_helper.py

示例2: test_broken_metadata_with_backup

    def test_broken_metadata_with_backup(self):
        """test that each time a metadata file is updated a .old is kept"""
        self.shelf['bad_file'] = {'value': 'old'}
        path = self.shelf.key_file('bad_file')
        self.assertFalse(path_exists(path+'.old'))
        self.assertEqual({'value': 'old'}, self.shelf['bad_file'])
        # force the creation of the .old file
        self.shelf['bad_file'] = {'value': 'new'}
        self.assertTrue(path_exists(path+'.old'))
        # check that the new value is there
        self.assertEqual({'value': 'new'}, self.shelf['bad_file'])
        # write the current md file fwith 0 bytes
        open_file(path, 'w').close()
        # test that the old value is retrieved
        self.assertEqual({'value': 'old'}, self.shelf['bad_file'])

        self.shelf['broken_pickle'] = {'value': 'old'}
        path = self.shelf.key_file('broken_pickle')
        # check that .old don't exist
        self.assertFalse(path_exists(path+'.old'))
        # force the creation of the .old file
        self.shelf['broken_pickle'] = {'value': 'new'}
        # check that .old exists
        self.assertTrue(path_exists(path+'.old'))
        # check that the new value is there
        self.assertEqual({'value': 'new'}, self.shelf['broken_pickle'])
        # write random bytes to the md file
        with open_file(path, 'w') as f:
            f.write(BROKEN_PICKLE)
        # check that the old value is retrieved
        self.assertEqual({'value': 'old'}, self.shelf['broken_pickle'])
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:31,代码来源:test_fileshelf.py

示例3: test_open_file_write

    def test_open_file_write(self):
        """Open a file, and write."""
        fh = open_file(self.testfile, 'w')
        fh.write("foo")
        fh.close()

        f = open_file(self.testfile)
        self.assertTrue(f.read(), "foo")
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:8,代码来源:test_os_helper.py

示例4: test_set_file_readwrite

    def test_set_file_readwrite(self):
        """Test for set_file_readwrite."""
        set_file_readonly(self.testfile)
        self.addCleanup(set_dir_readwrite, self.testfile)

        set_file_readwrite(self.testfile)
        open_file(self.testfile, 'w')
        self.assertTrue(can_write(self.testfile))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:8,代码来源:test_os_helper.py

示例5: setUp

 def setUp(self, test_dir_name=None, test_file_name=None,
           valid_file_path_builder=None):
     """Setup for the tests."""
     yield super(OSWrapperTests, self).setUp(
         test_dir_name=test_dir_name, test_file_name=test_file_name,
         valid_file_path_builder=valid_file_path_builder)
     # make sure the file exists
     open_file(self.testfile, 'w').close()
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:8,代码来源:test_os_helper.py

示例6: test_bad_path

 def test_bad_path(self):
     """Test that the shelf removes the previous shelve file and create a
     directory for the new file based shelf at creation time.
     """
     path = os.path.join(self.path, 'shelf_file')
     open_file(path, 'w').close()
     self.fileshelf_class(path)
     self.assertTrue(os.path.isdir(path))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:8,代码来源:test_fileshelf.py

示例7: _check_move_file

 def _check_move_file(self, src, dst, real_dst):
     """Check that a file was indeed moved."""
     with open_file(src, "rb") as f:
         contents = f.read()
     recursive_move(src, dst)
     with open_file(real_dst, "rb") as f:
         self.assertEqual(contents, f.read())
     self.assertFalse(path_exists(src))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:8,代码来源:test_os_helper.py

示例8: test_movetotrash_file_bad

 def test_movetotrash_file_bad(self):
     """Something bad happen when moving to trash, removed anyway."""
     path = os.path.join(self.basedir, 'foo')
     open_file(path, 'w').close()
     move_to_trash(path)
     self.assertFalse(os.path.exists(path))
     self.assertTrue(self.handler.check_warning("Problems moving to trash!",
                                                "Removing anyway", "foo"))
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:8,代码来源:test_darwin.py

示例9: test_corrupted_backup

 def test_corrupted_backup(self):
     """test getitem if also the .old file is corrupted"""
     self.shelf["foo"] = "bar"
     # create the .old backup
     self.shelf["foo"] = "bar1"
     # write 0 bytes to both
     open_file(self.shelf.key_file('foo')+'.old', 'w').close()
     open_file(self.shelf.key_file('foo'), 'w').close()
     self.assertRaises(KeyError, self.shelf.__getitem__, 'foo')
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:9,代码来源:test_fileshelf.py

示例10: test_endless_borken_backups

 def test_endless_borken_backups(self):
     """test getitem  with a lot of files named .old.old.....old"""
     self.shelf["foo"] = "bar"
     path = self.shelf.key_file('foo')
     open_file(self.shelf.key_file('foo'), 'w').close()
     for _ in xrange(20):
         open_file(path + '.old', 'w').close()
         path += '.old'
     self.assertRaises(KeyError, self.shelf.__getitem__, 'foo')
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:9,代码来源:test_fileshelf.py

示例11: test_movetotrash_file_systemnotcapable

 def test_movetotrash_file_systemnotcapable(self):
     """The system is not capable of moving into trash."""
     FakeGIOFile._bad_trash_call = GIO_NOT_SUPPORTED
     self.patch(gio, "File", FakeGIOFile)
     path = os.path.join(self.basedir, 'foo')
     open_file(path, 'w').close()
     move_to_trash(path)
     self.assertFalse(os.path.exists(path))
     self.assertTrue(self.handler.check_warning("Problems moving to trash!",
                                                "Removing anyway", "foo",
                                                "ERROR_NOT_SUPPORTED"))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:11,代码来源:test_linux.py

示例12: test_movetotrash_dir_bad

 def test_movetotrash_dir_bad(self):
     """Something bad happen when moving to trash, removed anyway."""
     FakeGIOFile._bad_trash_call = False   # error
     self.patch(gio, "File", FakeGIOFile)
     path = os.path.join(self.basedir, 'foo')
     os.mkdir(path)
     open_file(os.path.join(path, 'file inside directory'), 'w').close()
     move_to_trash(path)
     self.assertFalse(os.path.exists(path))
     self.assertTrue(self.handler.check_warning("Problems moving to trash!",
                                                "Removing anyway", "foo"))
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:11,代码来源:test_linux.py

示例13: __init__

 def __init__(self, path):
     """Create the instance."""
     self.path = path
     self.tempfile = None
     if path_exists(self.path) and stat_path(self.path).st_size > 0:
         # if it's there and size > 0, open only for read
         self.fd = open_file(self.path, "rb")
     else:
         # this is a new hint file, lets create it as a tempfile.
         self.tempfile = tempfile.mktemp(dir=os.path.dirname(self.path))
         self.fd = open_file(self.tempfile, "w+b")
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:11,代码来源:tritcask.py

示例14: test_delete_backups_too

 def test_delete_backups_too(self):
     """test that delitem also deletes the .old/.new files left around"""
     self.shelf["foo"] = "bar"
     # create the .old backup
     self.shelf["foo"] = "bar1"
     path = self.shelf.key_file('foo')
     # create a .new file (a hard reboot during the rename dance)
     open_file(path+'.new', 'w').close()
     # write 0 bytes to both
     del self.shelf['foo']
     self.assertFalse(path_exists(path))
     self.assertFalse(path_exists(path+'.old'), 'there is a .old file!')
     self.assertFalse(path_exists(path+'.new'), 'there is a .new file!')
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:13,代码来源:test_fileshelf.py

示例15: test_broken_metadata_without_backup

    def test_broken_metadata_without_backup(self):
        """test the shelf behavior when it hit a broken metadata file without
        backup.
        """
        self.shelf['bad_file'] = {}
        path = self.shelf.key_file('bad_file')
        open_file(path, 'w').close()
        self.assertRaises(KeyError, self.shelf.__getitem__, 'bad_file')

        self.shelf['broken_pickle'] = {}
        path = self.shelf.key_file('broken_pickle')
        with open_file(path, 'w') as f:
            f.write(BROKEN_PICKLE)
        self.assertRaises(KeyError, self.shelf.__getitem__, 'broken_pickle')
开发者ID:magicicada-bot,项目名称:magicicada-client,代码行数:14,代码来源:test_fileshelf.py


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