Esempio n. 1
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'])
Esempio n. 2
0
 def testTemplateVariable(self):
     """
     Test that you can pass variables to the template properly.
     """
     variables = {'otherVar': 'value'}
     self.assertRaises(TemplateVarNotFoundError,
                       Template('{var}').value, variables)
     variables['var'] = 'test'
     self.assertEqual(Template('{var}').value(variables), 'test')
Esempio n. 3
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)
Esempio n. 4
0
 def testTemplateRequiredPath(self):
     """
     Test that the required path check works.
     """
     value = '{}/!badPath/test.exr'.format(
         BaseTestCase.dataTestsDirectory())
     self.assertRaises(TemplateRequiredPathNotFoundError,
                       Template(value).value)
     value = '{}/!glob'.format(BaseTestCase.dataTestsDirectory())
     result = Template(value).value()
     self.assertEqual(
         result, os.path.join(BaseTestCase.dataTestsDirectory(), 'glob'))
Esempio n. 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)
Esempio n. 6
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))
Esempio n. 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])
Esempio n. 8
0
 def testTemplate(self):
     """
     Test that the Template works properly.
     """
     crawler = FsCrawler.createFromPath(self.__file)
     value = '(dirname {filePath})/(newver <parent>)/{name}.(pad {frame} 6).{ext}'
     result = Template(value).valueFromCrawler(crawler)
     self.assertEqual(
         os.path.normpath(result),
         os.path.join(BaseTestCase.dataTestsDirectory(), 'v003',
                      'RND-TST-SHT_lighting_beauty_sr.001001.exr'))
Esempio n. 9
0
 def testNestProcedureTemplateSimple(self):
     """
     Test simple nested procedures in the template.
     """
     crawler = FsCrawler.createFromPath(self.__file)
     value = "/a/b/c/(dirname(dirname '/d/e/f'))/(newver <parent>)/{name}.(pad {frame} 6).{ext}"
     result = Template(value).valueFromCrawler(crawler)
     self.assertEqual(
         os.path.normpath(result),
         os.path.normpath(
             '/a/b/c/d/v001/RND-TST-SHT_lighting_beauty_sr.001001.exr'))
Esempio n. 10
0
 def testArithmeticOperations(self):
     """
     Test support for arithmetic operations.
     """
     self.assertEqual(
         Template(
             "/({x} + 10 as <result>)/(<result> - 10)/(4.0 / {y})").value({
                 'x':
                 5,
                 'y':
                 2
             }), "/15/5/2")
Esempio n. 11
0
 def testNestProcedureTemplateMultiple(self):
     """
     Test multiple nested procedures in the template.
     """
     crawler = FsCrawler.createFromPath(self.__file)
     value = "/a/b/c/(concat (dirname(dirname (dirname '/d/e/f/g'))) '_' (dirname (dirname {var})))/(newver <parent>)/{name}.(pad {frame} 6).{ext}"
     result = Template(value).valueFromCrawler(crawler,
                                               extraVars={'var': 'h/j/l'})
     self.assertEqual(
         os.path.normpath(result),
         os.path.normpath(
             '/a/b/c/d_h/v001/RND-TST-SHT_lighting_beauty_sr.001001.exr'))
Esempio n. 12
0
    def testAssignToToken(self):
        """
        Test that the template can assign the return of procedure to a token.
        """
        def __assignTokenResult(*args):
            return ' '.join(args)

        Template.registerProcedure('assigntokenresult', __assignTokenResult)

        self.assertEqual(
            Template(
                "/(assigntokenresult foo as <test>)/a/{someVar}/(assigntokenresult foo2 as <test2>)_<test>_x_{someVar}_x_<test2>/b/<test>/c/<test2>_{someVar}"
            ).value({'someVar': 'var'}),
            "/foo/a/var/foo2_foo_x_var_x_foo2/b/foo/c/foo2_var")
Esempio n. 13
0
    def testSingleQuote(self):
        """
        Test that the template can return a value with single quote.
        """
        def __testSingleQuoteProcedure(*args):
            return ' '.join(args)

        Template.registerProcedure('testsinglequote',
                                   __testSingleQuoteProcedure)

        inputValue = "my 'random\' value'"
        self.assertEqual(
            Template("/(testsinglequote {foo} '2' 3)/").value(
                {'foo': inputValue}), "/{} 2 3/".format(inputValue))
Esempio n. 14
0
 def testNestProcedureTemplateArithmetic(self):
     """
     Test arithmetic nested procedures in the template.
     """
     crawler = FsCrawler.createFromPath(self.__file)
     value = "/a/b/c/({a} + (sum {b} 2))/(newver <parent>)/{name}.(pad {frame} 6).{ext}"
     result = Template(value).valueFromCrawler(crawler,
                                               extraVars={
                                                   'a': 2,
                                                   'b': 3
                                               })
     self.assertEqual(
         os.path.normpath(result),
         os.path.normpath(
             '/a/b/c/7/v001/RND-TST-SHT_lighting_beauty_sr.001001.exr'))
Esempio n. 15
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'])