def test_fileIsExcluded(self): myDef = Definition('myName', 'dir', 'C:/temp', './C/temp', [], [], [], []) self.assert_(not myDef._fileIsExcluded('Test.txt'), 'File excluded on empty exclude list') myDef.excludeFilePattern = ['*Test*', '*all*'] self.assert_(myDef._fileIsExcluded('Test.txt'), 'File not excluded on matching exclude list') self.assert_(myDef._fileIsExcluded('fileOnCall.txt'), 'File not excluded on matching exclude list, item2') self.assert_(not myDef._fileIsExcluded('Bad.file'), 'File excluded on not matching exclude list')
def test_dirIsExcluded(self): myDef = Definition('myName', 'dir', 'C:/temp', './C/temp', [], [], [], []) self.assert_(not myDef._dirIsExcluded('c:/temp/anydir'), 'Dir excluded on empty exclude list') myDef.excludeDirPattern = ['*/asd*', '*/path/*'] self.assert_(myDef._dirIsExcluded('c:/temp/path/anydir'), 'Dir not excluded that is in include list') self.assert_(myDef._dirIsExcluded('c:/temp/asd_whatEverDir'), 'Dir not excluded that is in include list2') self.assert_(not myDef._dirIsExcluded('c:/temp/anydir'), 'Dir excluded when not in include list')
def test_dirIsIncluded(self): myDef = Definition('myName', 'dir', 'C:/temp', './C/temp', [], [], [], []) self.assert_(myDef._dirIsIncluded('anydir'), 'Dir not included on empty include list') myDef.includeDirPattern = ['asd*', 'path'] self.assert_(myDef._dirIsIncluded('path'), 'Dir not included that is in include list') self.assert_(myDef._dirIsIncluded('asd_whatEverDir'), 'Dir not included that is in include list2') self.assert_(not myDef._dirIsIncluded('anydir'), 'Dir included when not in include list')
def testCreate(self): myDef = Definition('myName', 'dir', 'C:/temp', './C/temp', ['*.txt'], ['old*', 'bad*'], ['wanted_dir*'], ['bad_dir*']) self.assert_(myDef <> None, 'No definition created') self.assert_(myDef.name == 'myName', 'name not OK') self.assert_(myDef.backupType == 'dir', 'backupType not OK') self.assert_(myDef.fromPlace == 'C:/temp', 'fromPlace not OK') self.assert_(myDef.toPlace == './C/temp', 'toPlace not OK') self.assert_(myDef.includeFilePattern[0] == '*.txt', 'includeFilePattern not OK') self.assert_(myDef.excludeFilePattern[1] == 'bad*', 'excludeFilePattern not OK') self.assert_(myDef.includeDirPattern[0] == 'wanted_dir*', 'includeDirPattern not OK') self.assert_(myDef.excludeDirPattern[0] == 'bad_dir*', 'excludeDirPattern not OK')
def testRun(self): Environment.cleanupTestFolder() Environment.setupExamplesDir() newConfig = Configuration() newConfig.definitions.append( Definition('Name1', 'dir', Environment.examplesFolder(), './C/temp1')) newTask = Task('myName', ['Name1'], targetFolder=Environment.targetFolder()) newConfig.addTask(newTask) filename = newTask.run() self.assert_(os.path.exists(Environment.targetFolder()), 'Target folder not created') self.assert_(filename <> None and filename <> '', 'No file name returned on run') Environment.cleanupTestFolder()
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()
def testfileInfos(self): Environment.cleanupTestFolder() exampleFile = Environment.setupExamplesDir() myDef = Definition('Name1', 'dir', Environment.examplesFolder(), 'Test/Dir') infos = [] for info in myDef.fileInfos(): infos.append(info) self.assert_(infos <> None, 'No fileInfos created') self.assert_( infos[0]['source'] == os.path.join(Environment.examplesFolder(), 'example.txt'), 'Example source file not OK') self.assert_( infos[0]['target'] == os.path.join('Test/Dir', 'examples', 'example.txt'), 'Example source file not OK') someFiles = Environment.extendExamplesDir() someFiles.append(exampleFile) infos = [] for info in myDef.fileInfos(): infos.append(info) self.assert_(len(infos) == len(someFiles), 'Not all files found') myDef.includeDirPattern = ['subfolder'] infos = [] for info in myDef.fileInfos(): infos.append(info) # Note that I get all files of the base dir, independent if that matches included dirrs! self.assert_(len(infos) == 4, 'Nb of files not OK for include dirs') Environment.cleanupTestFolder()
def setUp(self): self.app = QtGui.QApplication([]) self.definition = Definition('name', 'dir', 'from', 'to') self.dlg = DefinitionDialog(None, self.definition) self.dlg.show()