示例#1
0
    def testStoredFiles(self):
        Environment.cleanupTestFolder()

        targetFolder = Environment.targetFolder()

        # Create some files in target folder
        if not os.path.exists(targetFolder):
            os.makedirs(targetFolder)

        filename = os.path.join(targetFolder, 'myName_20180304_1200.zip')
        filename2 = os.path.join(targetFolder, 'otherName_20180304_1200.zip')

        with open(filename, 'w') as f:
            f.write('Simple test file for BRIT')

        with open(filename2, 'w') as f:
            f.write('Simple test file for BRIT')

        newConfig = Configuration()
        newConfig.definitions.append(
            Definition('Name1', 'dir', Environment.examplesFolder(),
                       './C/temp1'))

        newTask = Task('myName', ['Name1'],
                       targetFolder=Environment.targetFolder())
        newConfig.addTask(newTask)

        fileNames = []

        for fName in newTask.storedFiles():
            fileNames.append(fName)

        self.assert_(len(fileNames) == 1, "Only one file should be found")
        self.assert_(fileNames[0] == filename, "Wrong file found")
示例#2
0
    def testfilesSize(self):
        Environment.cleanupTestFolder()
        exampleFile = Environment.setupExamplesDir()
        someFiles = Environment.extendExamplesDir()
        someFiles.append(exampleFile)

        myDef = Definition('Name1', 'dir', Environment.examplesFolder(),
                           'Test/Dir')
        self.assert_(myDef.filesSize() == 514, 'FilesSize not OK')

        Environment.cleanupTestFolder()
示例#3
0
    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()
示例#4
0
    def testWriteToReadFrom(self):
        newConfig = Configuration()
        newConfig.addTask(Task('TestTest1', ['config1', 'config2']))
        newConfig.addTask(Task('TestTest2', ['config1', 'config2']))
        newConfig.definitions.append(
            Definition('name1', 'dir', 'C:/temp1', './C/temp1'))
        newConfig.definitions.append(
            Definition('name2', 'dir', 'C:/temp2', './C/temp2'))
        newConfig.definitions.append(
            Definition('name3', 'dir', 'C:/temp3', './C/temp3'))
        newConfig.retainStrategies.append(RetainStrategy('reatinDefault'))
        newConfig.backupDirectory = 'c:/temp/backup'

        Environment.cleanupTestFolder()
        Environment.setupExamplesDir()
        testFile = os.path.join(Environment.examplesFolder(),
                                'test_config.brit')

        newConfig.writeTo(testFile)
        self.assert_(os.path.isfile(testFile), 'No config file written')

        newConfig2 = Configuration.readFrom(testFile)

        self.assert_(newConfig2 <> None,
                     'No configuration has been read from Json')
        self.assert_(
            len(newConfig2.tasks) == 2, 'Length of list of tasks not OK')
        self.assert_(newConfig2.tasks[0].name == 'TestTest1',
                     'Name of first task not OK')
        self.assert_(newConfig2.tasks[0].configuration == newConfig2,
                     'Configuration of task not set')

        self.assert_(
            len(newConfig2.definitions) == 3,
            'Length of list of Definitions not OK')
        self.assert_(
            len(newConfig2.retainStrategies) == 1,
            'Length of list of RetainStrategies not OK')

        self.assert_(newConfig2.backupDirectory == 'c:/temp/backup',
                     'backupDirectory not OK')

        Environment.cleanupTestFolder()
示例#5
0
    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()
示例#6
0
    def testSaveToReadFrom(self):
        newMapping = FileMapping()
        newMapping.addItem(u'c:/temp/x1.txt', u'Temp/x1.txt')
        newMapping.addItem(u'c:/temp/x2.txt', u'Temp/x2.txt')

        Environment.cleanupTestFolder()
        Environment.setupExamplesDir()
        testFile = os.path.join(Environment.examplesFolder(),
                                'test_mapping.json')

        newMapping.saveTo(testFile)

        self.assert_(os.path.isfile(testFile), 'No mapping file written')
        newMapping2 = FileMapping.readFrom(testFile)

        self.assert_(newMapping2 <> None, 'No mapping read')
        self.assert_(
            len(newMapping2.itemMappings) == 2, 'Nb of items mappings not OK')
        self.assert_(
            newMapping2.itemMappings[u'c:/temp/x1.txt'] == u'Temp/x1.txt',
            'Mapping item not added')

        Environment.cleanupTestFolder()