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'])
def testRetimePadding(self): """ Test that the retime padding procedure works properly. """ padding = Template.runProcedure("retimepad", 1, 5, 4) self.assertEqual(padding, "0006") padding = Template.runProcedure("retimepad", 100, -99, 6) self.assertEqual(padding, "000001")
def testPadding(self): """ Test that the padding procedure works properly. """ padding = Template.runProcedure("pad", 1, 4) self.assertEqual(padding, "0001") padding = Template.runProcedure("pad", 100, 6) self.assertEqual(padding, "000100")
def testYear(self): """ Test that the year template procedures work properly. """ yyyy = Template.runProcedure("yyyy") self.assertGreaterEqual(int(yyyy), 2018) yy = Template.runProcedure("yy") self.assertEqual(yyyy[-2:], yy)
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')
def testLatestVersion(self): """ Test that the latest version is found properly. """ result = Template.runProcedure('latestver', BaseTestCase.dataTestsDirectory()) self.assertEqual(result, 'v002') result = Template.runProcedure( 'latestver', os.path.join(BaseTestCase.dataTestsDirectory(), 'glob')) self.assertEqual(result, 'v000')
def testRegistration(self): """ Test that the procedure registration works properly. """ def myDummyTemplate(a, b): return '{}-{}'.format(a, b) with self.assertRaises(TemplateProcedureNotFoundError): Template.runProcedure("dummyRegistration") Template.registerProcedure("dummyRegistration", myDummyTemplate) self.assertIn("dummyRegistration", Template.registeredProcedureNames())
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'))
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 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 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 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")
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))
def testVersionSuffixCustomPattern(self): """ Test that the version suffix procedure works with a custom version. """ customPattern = 'd#####abc' result = Template.runProcedure('versuffix', 'd00005abc', customPattern) self.assertEqual(result, 'abc')
def testVersionEmptyPrefixCustomPattern(self): """ Test that the version prefix procedure works with a custom version without prefix. """ customPattern = '#####d' result = Template.runProcedure('verprefix', '00005d', customPattern) self.assertEqual(result, '')
def testVersionNumberCustomPattern(self): """ Test that the version number procedure works with a custom version. """ customPattern = 'abc#####d' result = Template.runProcedure('vernumber', 'abc00005d', customPattern) self.assertEqual(result, '00005')
def testLabelVersionCustomPattern(self): """ Test that the label procedure works with a custom version pattern using only digits. """ customPattern = '#####' result = Template.runProcedure('labelver', 5, customPattern) self.assertEqual(result, '00005')
def testNewVersion(self): """ Test that the new procedure works properly. """ result = Template.runProcedure('newver', BaseTestCase.dataTestsDirectory()) self.assertEqual(result, 'v003')
def testLabelVersionCustomFullPattern(self): """ Test that the label procedure works with a custom version using full pattern. """ customPattern = 'ab#####_cd' result = Template.runProcedure('labelver', 5, customPattern) self.assertEqual(result, 'ab00005_cd')
def testVersionEmptySuffixCustomPattern(self): """ Test that the version suffix procedure works with a custom version without suffix. """ customPattern = 'abc#####' result = Template.runProcedure('versuffix', 'abc00005', customPattern) self.assertEqual(result, '')
def testParseRun(self): """ Test that running a procedure through string parsing works. """ result = Template.evalProcedure("(dirname {})".format(self.__path)) self.assertEqual(result, "/test/path") self.assertRaises(AssertionError, Template.evalProcedure, True)
def testSecond(self): """ Test that the second procedure works properly. """ second = Template.runProcedure("second") self.assertGreaterEqual(int(second), 0) self.assertLessEqual(int(second), 59)
def testLabelVersionCustomSuffixPattern(self): """ Test that the label procedure works with a custom version pattern with suffix. """ customPattern = '#####b' result = Template.runProcedure('labelver', 5, customPattern) self.assertEqual(result, '00005b')
def testHour(self): """ Test that the hour procedure works properly. """ hour = Template.runProcedure("hour") self.assertGreaterEqual(int(hour), 0) self.assertLessEqual(int(hour), 23)
def testMinute(self): """ Test that the minute procedure works properly. """ minute = Template.runProcedure("minute") self.assertGreaterEqual(int(minute), 0) self.assertLessEqual(int(minute), 59)
def testDay(self): """ Test that the day procedure works properly. """ dd = Template.runProcedure("dd") self.assertGreaterEqual(int(dd), 1) self.assertLessEqual(int(dd), 31)
def testMonth(self): """ Test that the month procedure works properly. """ mm = Template.runProcedure("mm") self.assertGreaterEqual(int(mm), 1) self.assertLessEqual(int(mm), 12)
def testVersionNumberOnlyDigitsCustomPattern(self): """ Test that the version number procedure works with a custom version that contains only the digits. """ customPattern = '#####' result = Template.runProcedure('vernumber', '00005', customPattern) self.assertEqual(result, '00005')
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])
def testEnv(self): """ Test that the env procedure works properly. """ userEnvironment = 'USER' if 'USER' in os.environ else 'USERNAME' result = Template.runProcedure("env", userEnvironment) self.assertEqual(result, getpass.getuser())