def testTaskOutput(self): """ Test that task output is returned properly. """ class DummyTask(Task): pass Task.register("dummy", DummyTask) dummyTask = Task.create('dummy') crawlers = FsPath.createFromPath(BaseTestCase.dataDirectory()).glob(['mov']) targetPaths = [] for crawler in crawlers: target = '{}_target.mov'.format(crawler.var('name')) targetPath = os.path.join(BaseTestCase.dataDirectory(), target) targetPaths.append(targetPath) crawler.setVar('contextVarTest', 1, True) dummyTask.add(crawler, targetPath) result = dummyTask.output() self.assertEqual(len(result), len(crawlers)) self.assertCountEqual( map(lambda x: x.var('filePath'), result), targetPaths ) self.assertEqual( list(map(lambda x: x.var('contextVarTest'), result)), [1]*len(crawlers) ) for crawler in result: self.assertIn('contextVarTest', crawler.contextVarNames())
def testTaskJson(self): """ Test that you can convert a Task to json and back. """ class DummyTask(Task): pass Task.register("dummy", DummyTask) dummyTask = Task.create('dummy') crawlers = FsPath.createFromPath(BaseTestCase.dataDirectory()).glob(['mov']) targetPaths = [] for crawler in crawlers: target = '{}_target.mov'.format(crawler.var('name')) targetPath = os.path.join(BaseTestCase.dataDirectory(), target) targetPaths.append(targetPath) dummyTask.add(crawler, targetPath) jsonResult = dummyTask.toJson() resultTask = Task.createFromJson(jsonResult) self.assertCountEqual(dummyTask.optionNames(), resultTask.optionNames()) self.assertCountEqual(dummyTask.metadataNames(), resultTask.metadataNames()) self.assertCountEqual( map(lambda x: x.var('filePath'), dummyTask.crawlers()), map(lambda x: x.var('filePath'), resultTask.crawlers()) ) self.assertCountEqual( map(dummyTask.target, dummyTask.crawlers()), map(resultTask.target, resultTask.crawlers()) )
def testTaskRegistration(self): """ Test that you can register a new Task. """ class DummyTask(Task): pass Task.register("dummy", DummyTask) self.assertIn("dummy", Task.registeredNames()) self.assertRaises(TaskTypeNotFoundError, Task.create, 'badTask')
import sys from centipede.Task import Task class UPythonMajorVerTestTask(Task): """ Dummy task for testing python 2 subprocess. """ def _perform(self): sourceCrawler = self.crawlers()[0] sourceCrawler.setVar("majorVer", sys.version_info[0]) return [sourceCrawler.clone()] Task.register('uPythonMajorVerTestTask', UPythonMajorVerTestTask)
from centipede.Task import Task from centipede.TaskWrapper import TaskWrapper class UPythonTestTask(Task): """ Dummy task for testing UPython subprocess. """ def _perform(self): sourceCrawler = self.crawlers()[0] if self.option('runUPython'): dummyTask = Task.create('uPythonTestTask') dummyTask.setOption("runUPython", False) dummyTask.add(sourceCrawler) wrapper = TaskWrapper.create('upython') result = wrapper.run(dummyTask) else: import OpenImageIO sourceCrawler.setVar("testUPython", OpenImageIO.VERSION) result = [sourceCrawler.clone()] return result Task.register('uPythonTestTask', UPythonTestTask)