Пример #1
0
 def testAtomicWriteGroup(self):
   self.mox.StubOutWithMock(os, 'chown')
   os.chown(self.temp_filename, -1, self.gid)
   os.rename(self.temp_filename, self.file_path)
   self.mox.ReplayAll()
   file_util.AtomicWrite(self.file_path, self.sample_contents,
                         mode=self.mode, gid=self.gid)
   self.mox.VerifyAll()
Пример #2
0
 def testRenamingErrorWithRemoveError(self):
   extra_error = OSError('A problem removing!')
   os.rename(self.temp_filename, self.file_path).AndRaise(self.os_error)
   os.remove(self.temp_filename).AndRaise(extra_error)
   self.mox.ReplayAll()
   try:
     file_util.AtomicWrite(self.file_path, self.sample_contents,
                           mode=self.mode)
   except OSError as e:
     self.assertEquals(str(e),
                       'A problem renaming!. Additional errors cleaning up: '
                       'A problem removing!')
   else:
     raise self.failureException('OSError not raised by AtomicWrite')
   self.mox.VerifyAll()
Пример #3
0
 def testAtomicWriteMode(self):
   mode = 0745
   file_util.AtomicWrite(self.file_path, self.sample_contents, mode=mode)
   s = os.stat(self.file_path)
   self.assertEqual(stat.S_IMODE(s.st_mode), mode)
Пример #4
0
 def testAtomicWriteSuccessful(self):
   file_util.AtomicWrite(self.file_path, self.sample_contents)
   with open(self.file_path) as fp:
     self.assertEquals(fp.read(), self.sample_contents)