예제 #1
0
    def test__sync_filechange(self):
        # build up filesystem with our test file and sync it.
        fs = FileSystem(path=self.rootpath())
        file = File(lines=['line 0'])
        fs.rootdirectory().add(name='file', entry=file)
        file.add_lines(['line 1', 'line 2', 'line 3'])
        fs.sync()

        # re-read our file and see if everything is there
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        lines = file.lines()
        self.failUnlessEqual(lines[0], 'line 0')
        self.failUnlessEqual(lines[1], 'line 1')
        self.failUnlessEqual(lines[2], 'line 2')
        self.failUnlessEqual(lines[3], 'line 3')
        file.add_lines(['line 4'])
        fs.sync()

        # append to our file without explicitly reading it.
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        file.add_lines(['line 5'])
        fs.sync()

        # see if there's still everything there.
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        lines = file.lines()
        self.failUnlessEqual(lines[0], 'line 0')
        self.failUnlessEqual(lines[1], 'line 1')
        self.failUnlessEqual(lines[2], 'line 2')
        self.failUnlessEqual(lines[3], 'line 3')
        self.failUnlessEqual(lines[4], 'line 4')
        self.failUnlessEqual(lines[5], 'line 5')
        pass
예제 #2
0
    def test__sync_file_truncate_persistent(self):

        fs = FileSystem(path=self.rootpath())
        file = File(lines=['line'])
        fs.rootdirectory().add(name='file', entry=file)
        fs.sync()

        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        file.truncate()
        fs.sync()

        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        self.failUnless(file.lines() == [])
        pass