Пример #1
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 = FsCrawler.createFromPath(
            BaseTestCase.dataTestsDirectory()).glob(['mov'])
        targetPaths = []
        for crawler in crawlers:
            target = '{}_target.mov'.format(crawler.var('name'))
            targetPath = os.path.join(BaseTestCase.dataTestsDirectory(),
                                      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()))
Пример #2
0
    def testTaskOutput(self):
        """
        Test that task output is returned properly.
        """
        class DummyTask(Task):
            pass

        Task.register("dummy", DummyTask)

        dummyTask = Task.create('dummy')
        crawlers = FsCrawler.createFromPath(
            BaseTestCase.dataTestsDirectory()).glob(['mov'])
        targetPaths = []
        for crawler in crawlers:
            target = '{}_target.mov'.format(crawler.var('name'))
            targetPath = os.path.join(BaseTestCase.dataTestsDirectory(),
                                      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())
Пример #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
 def testChecksumTask(self):
     """
     Test that the checksum task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     checksumTask = Task.create('checksum')
     checksumTask.add(crawler, self.__targetPath)
     result = checksumTask.output()
     self.assertEqual(len(result), 1)
     checksumTask = Task.create('checksum')
     checksumTask.add(crawler, self.__otherPath)
     self.assertRaises(ChecksumTaskMatchError, checksumTask.output)
Пример #5
0
    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)
Пример #6
0
    def testSymlink(self):
        """
        Test that symlink support in link task works properly.
        """
        crawler = FsCrawler.createFromPath(self.__targetPath)

        linkTask = Task.create('link')
        linkTask.setOption('type', 'symlink')
        linkTask.add(crawler, self.__targetSymlinkPath)

        result = None
        try:
            result = linkTask.output()
        except OSError as err:
            if str(err).startswith('[WinError 1314]'):
                sys.stderr.write('Current user has no privilege for creating symlinks')

        if result is None:
            return

        self.assertEqual(len(result), 1)
        self.assertTrue(os.path.exists(result[0].var('filePath')))

        if not platform.system() == "Windows":
            self.assertTrue(os.path.islink(result[0].var('filePath')))
Пример #7
0
    def testGlobAll(self):
        """
        Test that the glob task find all files & directories.
        """
        crawler = FsCrawler.createFromPath(
            os.path.join(BaseTestCase.dataTestsDirectory(), "glob",
                         "test.json"))

        globTask = Task.create('glob')
        globTask.add(
            crawler,
            Template("(dirname {filePath})/**/*").valueFromCrawler(crawler))
        result = globTask.output()
        self.assertEqual(
            len(result),
            len(self.__globFiles['exr']) + len(self.__globFiles['json']) +
            len(self.__globFiles['txt']) + len(self.__globFiles['directory']))

        for resultCrawler in result:
            baseType = 'directory' if 'ext' not in resultCrawler.varNames(
            ) else resultCrawler.var('ext')
            if baseType == 'exr':
                CrawlerType = ExrCrawler
            elif baseType == 'json':
                CrawlerType = JsonCrawler
            elif baseType == 'txt':
                CrawlerType = TxtCrawler
            else:
                baseType = 'directory'
                CrawlerType = DirectoryCrawler

            self.assertIsInstance(resultCrawler, CrawlerType)
            self.assertIn(resultCrawler.var('baseName'),
                          self.__globFiles[baseType])
Пример #8
0
    def testGlobSkipDuplicated(self):
        """
        Test that the glob task with the option skip duplicated enabled (default).
        """
        crawler1 = FsCrawler.createFromPath(
            os.path.join(BaseTestCase.dataTestsDirectory(), "glob",
                         "test.json"))

        crawler2 = FsCrawler.createFromPath(
            os.path.join(BaseTestCase.dataTestsDirectory(), "glob",
                         "text.txt"))

        globTask = Task.create('glob')
        globTask.add(
            crawler1,
            Template("(dirname {filePath})/**/*.exr").valueFromCrawler(
                crawler1))
        globTask.add(
            crawler2,
            Template("(dirname {filePath})/images/*.exr").valueFromCrawler(
                crawler2))
        result = globTask.output()
        self.assertEqual(len(result), len(self.__globFiles['exr']))

        for resultCrawler in result:
            self.assertIsInstance(resultCrawler, ExrCrawler)
            self.assertIn(resultCrawler.var('baseName'),
                          self.__globFiles['exr'])
Пример #9
0
 def testConvertImage(self):
     """
     Test that the ConvertImage task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     convertTask = Task.create('convertImage')
     convertTask.add(crawler, self.__targetPath)
     result = convertTask.output()
     self.assertEqual(len(result), 1)
     self.assertTrue(os.path.exists(result[0].var('filePath')))
Пример #10
0
 def cleanup(self, crawlers):
     """
     Remove the data that was copied.
     """
     removeTask = Task.create('remove')
     for crawler in crawlers:
         removeTask.add(crawler, crawler.var("filePath"))
     wrapper = TaskWrapper.create('python')
     wrapper.setOption('user', '')
     wrapper.run(removeTask)
Пример #11
0
 def testRemove(self):
     """
     Test that the remove task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__path)
     removeTask = Task.create('remove')
     removeTask.add(crawler, self.__path)
     result = removeTask.output()
     self.assertEqual(len(result), 1)
     crawler = result[0]
     self.assertFalse(os.path.isfile(crawler.var("filePath")))
Пример #12
0
    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)
Пример #13
0
 def testImageThumbnail(self):
     """
     Test that the ImageThumbnail task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     thumbnailTask = Task.create('imageThumbnail')
     thumbnailTask.add(crawler, self.__targetPath)
     result = thumbnailTask.output()
     self.assertEqual(len(result), 1)
     crawler = result[0]
     self.assertEqual(crawler.var("width"), 640)
     self.assertEqual(crawler.var("height"), 360)
Пример #14
0
 def testTaskOptions(self):
     """
     Test that task options are working properly.
     """
     dummyTask = Task.create('copy')
     dummyTask.setOption('boolOption', True)
     self.assertEqual(dummyTask.option('boolOption'), True)
     dummyTask.setOption('floatOption', 1.0)
     self.assertEqual(dummyTask.option('floatOption'), 1.0)
     dummyTask.setOption('intOption', 1)
     self.assertEqual(dummyTask.option('intOption'), 1)
     self.assertRaises(TaskInvalidOptionError, dummyTask.option,
                       'badOption')
Пример #15
0
 def testSequenceThumbnail(self):
     """
     Test that the SequenceThumbnail task works properly.
     """
     thumbnailTask = Task.create('sequenceThumbnail')
     sourceFiles = sorted(glob.glob(self.__sourcePath))
     for i in map(FsCrawler.createFromPath, sourceFiles):
         thumbnailTask.add(i, self.__targetPath)
     result = thumbnailTask.output()
     self.assertEqual(len(result), 1)
     crawler = result[0]
     self.assertEqual(crawler.var("width"), 640)
     self.assertEqual(crawler.var("height"), 360)
Пример #16
0
    def testConvertTexture(self):
        """
        Test that the ConvertTexture task works properly.
        """
        crawler = FsCrawler.createFromPath(self.__sourcePath)
        convertTask = Task.create('convertTexture')
        convertTask.setOption('maketxArgs', '-u --unpremult --oiio')
        convertTask.add(crawler, self.__targetPath)
        result = convertTask.output()

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].var('filePath'), self.__targetPath)
        self.assertTrue(os.path.exists(self.__targetPath))
Пример #17
0
    def testUpdateImageMetadata(self):
        """
        Test that the UpdateImageMetadata task works properly.
        """
        crawler = FsCrawler.createFromPath(self.__sourcePath)
        updateTask = Task.create('updateImageMetadata')
        updateTask.add(crawler, self.__targetPath)
        result = updateTask.output()
        self.assertEqual(len(result), 1)
        crawler = result[0]

        import OpenImageIO as oiio
        inputSpec = oiio.ImageInput.open(self.__targetPath).spec()
        self.assertEqual(inputSpec.get_string_attribute("kombi:sourceFile"), self.__sourcePath)
        checkTask = Task.create('checksum')
        checkTask.add(crawler, self.__sourcePath)
        self.assertRaises(ChecksumTaskMatchError, checkTask.output)

        customMetadata = {"testInt": 0, "testStr": "True"}
        UpdateImageMetadataTask.updateDefaultMetadata(inputSpec, crawler, customMetadata)
        self.assertEqual(inputSpec.get_int_attribute("kombi:testInt"), 0)
        self.assertEqual(inputSpec.get_string_attribute("kombi:testStr"), "True")
Пример #18
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))
Пример #19
0
    def testHardlink(self):
        """
        Test that hardlink support in link task works properly.
        """
        crawler = FsCrawler.createFromPath(self.__targetPath)

        linkTask = Task.create('link')
        linkTask.setOption('type', 'hardlink')
        linkTask.add(crawler, self.__targetHardlinkPath)
        result = linkTask.output()
        self.assertEqual(len(result), 1)
        self.assertTrue(os.path.exists(result[0].var('filePath')))
        self.assertFalse(os.path.islink(result[0].var('filePath')))
Пример #20
0
    def testPython2(self):
        """
        Test that the python3 subprocess works properly.
        """
        resource = Resource.get()
        resource.load(self.__taskPath)
        crawler = FsCrawler.createFromPath(self.__sourcePath)
        dummyTask = Task.create('pythonMajorVerTestTask')
        dummyTask.add(crawler)

        wrapper = TaskWrapper.create("python2")
        result = wrapper.run(dummyTask)
        self.assertTrue(len(result), 1)
        self.assertEqual(result[0].var("majorVer"), 2)
Пример #21
0
    def _perform(self):
        sourceCrawler = self.crawlers()[0]
        if self.option('runPython'):
            dummyTask = Task.create('pythonTestTask')
            dummyTask.setOption("runPython", False)
            dummyTask.add(sourceCrawler)
            wrapper = TaskWrapper.create('python')
            result = wrapper.run(dummyTask)
        else:
            import OpenImageIO
            sourceCrawler.setVar("testPython", OpenImageIO.VERSION)
            result = [sourceCrawler.clone()]

        return result
Пример #22
0
 def testCopy(self):
     """
     Test that the copy task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     copyTask = Task.create('copy')
     copyTask.add(crawler, self.__targetPath)
     result = copyTask.output()
     self.assertEqual(len(result), 1)
     crawler = result[0]
     self.assertEqual(crawler.var("filePath"), self.__targetPath)
     self.assertTrue(os.path.isfile(crawler.var("filePath")))
     self.assertIsInstance(crawler, ExrCrawler)
     self.assertEqual(crawler.var("width"), crawler.var("width"))
     self.assertEqual(crawler.var("height"), crawler.var("height"))
Пример #23
0
 def testChmodFile(self):
     """
     Test that the chmod task works properly on a file.
     """
     crawler = FsCrawler.createFromPath(self.__path)
     chmodTask = Task.create('chmod')
     chmodTask.add(crawler, self.__path)
     for permission in ["644", "444", "744", "664"]:
         chmodTask.setOption('directoryMode', permission)
         chmodTask.setOption('fileMode', permission)
         result = chmodTask.output()
         self.assertEqual(len(result), 1)
         crawler = result[0]
         self.assertEqual(self.__getPermission(crawler.var('filePath')),
                          permission)
Пример #24
0
 def testPython(self):
     """
     Test that the Python subprocess works properly.
     """
     resource = Resource.get()
     resource.load(self.__taskPath)
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     dummyTask = Task.create('pythonTestTask')
     dummyTask.add(crawler)
     dummyTask.setOption("runPython", False)
     wrapper = TaskWrapper.create('python')
     result = wrapper.run(dummyTask)
     self.assertTrue(len(result), 1)
     self.assertIn("testPython", result[0].varNames())
     self.assertEqual(result[0].var("testPython"), OpenImageIO.VERSION)
Пример #25
0
 def testResizeImage(self):
     """
     Test that the ResizeImage task works properly.
     """
     crawler = FsCrawler.createFromPath(self.__sourcePath)
     resizeTask = Task.create('resizeImage')
     resizeTask.add(crawler, self.__targetPath)
     resizeTask.setOption("width", "480")
     resizeTask.setOption("height", "270")
     for convertToRGBA in [False, True]:
         resizeTask.setOption("convertToRGBA", convertToRGBA)
         result = resizeTask.output()
         self.assertEqual(len(result), 1)
         crawler = result[0]
         self.assertEqual(crawler.var("width"), 480)
         self.assertEqual(crawler.var("height"), 270)
Пример #26
0
 def testSymlink(self):
     """
     Test that hardlinks are skipped when running the chmod task.
     """
     link = os.path.join(self.dataTestsDirectory(), 'symlink.exr')
     os.symlink(self.__path, link)
     self.assertEqual(self.__getPermission(link), '664')
     self.assertTrue(os.path.islink(link))
     crawler = FsCrawler.createFromPath(link)
     chmodTask = Task.create('chmod')
     chmodTask.add(crawler, link)
     chmodTask.setOption('directoryMode', '775')
     chmodTask.setOption('fileMode', '775')
     chmodTask.output()
     self.assertEqual(self.__getPermission(link), '664')
     self.addCleanup(self.cleanup, link)
Пример #27
0
    def testConvertVideo(self):
        """
        Test that the Convert Video task works properly.
        """
        crawler = FsCrawler.createFromPath(self.__sourcePath)
        convertTask = Task.create('convertVideo')
        convertTask.add(crawler, self.__targetPath)
        result = convertTask.output()
        self.assertEqual(len(result), 1)

        # the check is currently done through an approximation
        # from the expected size rather than a hash due metadata
        # that can vary the file size
        convertedSize = os.path.getsize(result[0].var('filePath'))
        self.assertGreaterEqual(convertedSize, 1450000)
        self.assertLessEqual(convertedSize, 1600000)
Пример #28
0
 def testChmodDir(self):
     """
     Test that the chmod task works properly on a directory.
     """
     crawler = FsCrawler.createFromPath(self.__dir)
     fileCrawler = FsCrawler.createFromPath(self.__path)
     chmodTask = Task.create('chmod')
     chmodTask.add(crawler, self.__dir)
     chmodTask.add(fileCrawler, self.__dir)
     dirPerm = "775"
     filePerm = "664"
     chmodTask.setOption('directoryMode', dirPerm)
     chmodTask.setOption('fileMode', filePerm)
     result = chmodTask.output()
     self.assertEqual(len(result), 1)
     self.assertEqual(self.__getPermission(self.__dir), dirPerm)
     self.assertEqual(self.__getPermission(self.__path), filePerm)
Пример #29
0
 def testTaskClone(self):
     """
     Test that cloning tasks works properly.
     """
     dummyTask = Task.create('sequenceThumbnail')
     crawlers = FsCrawler.createFromPath(
         BaseTestCase.dataTestsDirectory()).glob(['exr'])
     for crawler in crawlers:
         target = '{}_target'.format(crawler.var('name'))
         dummyTask.add(crawler, target)
     clone = dummyTask.clone()
     self.assertCountEqual(dummyTask.optionNames(), clone.optionNames())
     self.assertCountEqual(dummyTask.metadataNames(), clone.metadataNames())
     self.assertCountEqual(map(dummyTask.target, dummyTask.crawlers()),
                           map(clone.target, clone.crawlers()))
     self.assertCountEqual(
         map(lambda x: x.var('filePath'), dummyTask.crawlers()),
         map(lambda x: x.var('filePath'), clone.crawlers()))
Пример #30
0
    def testGlobSpecficFiles(self):
        """
        Test that the glob task looking for specific exr files.
        """
        crawler = FsCrawler.createFromPath(
            os.path.join(BaseTestCase.dataTestsDirectory(), "glob",
                         "test.json"))

        globTask = Task.create('glob')
        globTask.add(
            crawler,
            Template("(dirname {filePath})/**/*.exr").valueFromCrawler(
                crawler))
        result = globTask.output()
        self.assertEqual(len(result), len(self.__globFiles['exr']))

        for resultCrawler in result:
            self.assertIsInstance(resultCrawler, ExrCrawler)
            self.assertIn(resultCrawler.var('baseName'),
                          self.__globFiles['exr'])