コード例 #1
0
    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())
コード例 #2
0
    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())
        )
コード例 #3
0
 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')
コード例 #4
0
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)
コード例 #5
0
ファイル: UPythonTestTask.py プロジェクト: paulondc/centipede
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)