def testFilterTemplateCrawlers(self): """ Test that filter template in task holder. """ crawlers = [FsCrawler.createFromPath(self.__jsonConfig)] for filterOption in ['0', 'false', 'False']: dummyTask = Task.create('checksum') taskHolder = TaskHolder(dummyTask, Template(), Template(filterOption)) result = taskHolder.run(crawlers) self.assertEqual(len(result), 0)
def testFilterTemplateNotApplied(self): """ Test that filter template should not be applied. """ crawlers = [FsCrawler.createFromPath(self.__jsonConfig)] for filterOption in ['randomStr', '']: dummyTask = Task.create('checksum') taskHolder = TaskHolder(dummyTask, Template("{filePath}"), Template('randomStr')) result = taskHolder.run(crawlers) self.assertEqual(len(result), len(crawlers))
def testExecuteStatus(self): """ Test execute status in the task holder. """ dummyTask = Task.create('checksum') crawlers = [FsCrawler.createFromPath(self.__jsonConfig)] taskHolder = TaskHolder(dummyTask, Template("{filePath}")) dummyTask2 = Task.create('checksum') taskHolder2 = TaskHolder(dummyTask2, Template("{filePath}")) taskHolder2.setStatus("execute") taskHolder.addSubTaskHolder(taskHolder2) self.assertEqual(len(taskHolder.run(crawlers)), len(crawlers) * 2)
def __run(data): """ Execute the taskHolder. """ # loading task holder and running it with open(data) as f: taskHolder = TaskHolder.createFromJson(f.read()) # executing run taskHolder.run()
def __run(dataJsonFile, rangeStart=None, rangeEnd=None): """ Execute the taskHolder. """ data = {} with open(dataJsonFile) as jsonFile: data = json.load(jsonFile) # loading task holder taskHolder = TaskHolder.createFromJson(data['taskHolder']) if data['jobType'] == "collapsed": __runCollapsed(data, taskHolder, dataJsonFile) elif data['jobType'] == "expanded": __runExpanded(data, taskHolder, rangeStart, rangeEnd) else: raise Exception("Invalid execution type: {}".format(data['jobType']))