def test_doArchiveFileFail(self): filename = Environment.setupExamplesDir() zipTargetFile = 'dir/example' config = Configuration() config.backupDirectory = Environment.targetFolder() definition = Definition('name1', 'file', filename, zipTargetFile) config.definitions.append(definition) task = Task('myName', ['name1']) config.addTask(task) task._prepareTargetFolder() targetfile = task._getTargetFilename() archiveFile = task._prepareArchive(targetfile) # Now the actual test # I open and lock the example file to provoke an I/O error file_ = open(filename, 'a') if os.name == 'nt': msvcrt.locking(file_.fileno(), msvcrt.LK_LOCK, 0x7fffffff) with LogCapture(level=logging.WARNING) as l: task._doArchiveFile(archiveFile, filename, zipTargetFile) l.check(( 'root', 'WARNING', 'File could not be read: C:\\ProgramData\\brit_test\\examples\\example.txt Reason: I/O error(13): Permission denied' )) archiveFile.close() # Unlock and close the file if os.name == 'nt': msvcrt.locking(file_.fileno(), msvcrt.LK_UNLCK, 0x7fffffff) file_.close() self.assert_(not self.fileIsZipped(zipTargetFile, targetfile), 'File placed in zip file even though it was locked') Environment.cleanupTestFolder()
def test_doArchiveFile(self): filename = Environment.setupExamplesDir() zipTargetFile = 'dir/example' config = Configuration() config.backupDirectory = Environment.targetFolder() definition = Definition('name1', 'file', filename, zipTargetFile) config.definitions.append(definition) task = Task('myName', ['name1']) config.addTask(task) task._prepareTargetFolder() targetfile = task._getTargetFilename() archiveFile = task._prepareArchive(targetfile) # Now the actual test task._doArchiveFile(archiveFile, filename, zipTargetFile) archiveFile.close() self.assert_(self.fileIsZipped(zipTargetFile, targetfile), 'File not placed in zip file') Environment.cleanupTestFolder()