def testRetimePadding(self): """ Test that the retime padding expression works properly. """ padding = ExpressionEvaluator.run("retimepad", 1, 5, 4) self.assertEqual(padding, "0006") padding = ExpressionEvaluator.run("retimepad", 100, -99, 6) self.assertEqual(padding, "000001")
def testLatestVersion(self): """ Test that the latest version is found properly. """ result = ExpressionEvaluator.run("latestver", BaseTestCase.dataDirectory()) self.assertEqual(result, "v002") result = ExpressionEvaluator.run("latestver", os.path.join(BaseTestCase.dataDirectory(), "glob")) self.assertEqual(result, "v000")
def testYear(self): """ Test that the year expressions work properly. """ yyyy = ExpressionEvaluator.run("yyyy") self.assertGreaterEqual(int(yyyy), 2018) yy = ExpressionEvaluator.run("yy") self.assertEqual(yyyy[-2:], yy)
def testPadding(self): """ Test that the padding expression works properly. """ padding = ExpressionEvaluator.run("pad", 1, 4) self.assertEqual(padding, "0001") padding = ExpressionEvaluator.run("pad", 100, 6) self.assertEqual(padding, "000100")
def testRegistration(self): """ Test that the expression registration works properly. """ def myDummyExpression(a, b): return '{}-{}'.format(a, b) self.assertRaises(ExpressionNotFoundError, ExpressionEvaluator.run, "dummy") ExpressionEvaluator.register("dummy", myDummyExpression) self.assertIn("dummy", ExpressionEvaluator.registeredNames())
def testMonth(self): """ Test that the month expression works properly. """ mm = ExpressionEvaluator.run("mm") self.assertGreaterEqual(int(mm), 1) self.assertLessEqual(int(mm), 12)
def testMinute(self): """ Test that the minute expression works properly. """ minute = ExpressionEvaluator.run("minute") self.assertGreaterEqual(int(minute), 0) self.assertLessEqual(int(minute), 59)
def testSecond(self): """ Test that the second expression works properly. """ second = ExpressionEvaluator.run("second") self.assertGreaterEqual(int(second), 0) self.assertLessEqual(int(second), 59)
def testParseRun(self): """ Test that running an expression through string parsing works. """ result = ExpressionEvaluator.parseRun("dirname {}".format(self.__path)) self.assertEqual(result, "/test/path") self.assertRaises(AssertionError, ExpressionEvaluator.parseRun, True)
def testDay(self): """ Test that the day expression works properly. """ dd = ExpressionEvaluator.run("dd") self.assertGreaterEqual(int(dd), 1) self.assertLessEqual(int(dd), 31)
def testHour(self): """ Test that the hour expression works properly. """ hour = ExpressionEvaluator.run("hour") self.assertGreaterEqual(int(hour), 0) self.assertLessEqual(int(hour), 23)
def testRFindPath(self): """ Test that the rfind expression works properly. """ result = ExpressionEvaluator.run('rfindpath', 'test.txt', self.__testRFindPath) testPath = os.path.join(BaseTestCase.dataDirectory(), 'test.txt') self.assertEqual(result, testPath)
def testFindPath(self): """ Test that the find expression works properly. """ result = ExpressionEvaluator.run("findpath", 'TestCrawler.py', BaseTestCase.dataDirectory()) testPath = os.path.join(BaseTestCase.dataDirectory(), 'config', 'crawlers', 'TestCrawler.py') self.assertEqual(result, testPath)
def testMax(self): """ Test that the max expression works properly. """ result = ExpressionEvaluator.run("max", 6, 2) self.assertEqual(result, "6")
def testSum(self): """ Test that the sum expression works properly. """ result = ExpressionEvaluator.run("sum", 1, 2) self.assertEqual(result, "3")
def testDiv(self): """ Test that the div expression works properly. """ result = ExpressionEvaluator.run("div", 6, 2) self.assertEqual(result, "3")
def testMin(self): """ Test that the min expression works properly. """ result = ExpressionEvaluator.run("min", 6, 2) self.assertEqual(result, "2")
def testUpper(self): """ Test that the upper expression works properly. """ result = ExpressionEvaluator.run("upper", "boop") self.assertEqual(result, "BOOP")
def testMult(self): """ Test that the mult expression works properly. """ result = ExpressionEvaluator.run("mult", 2, 3) self.assertEqual(result, "6")
def testEnv(self): """ Test that the env expression works properly. """ result = ExpressionEvaluator.run("env", "USERNAME") self.assertEqual(result, os.environ.get("USERNAME"))
def testTmpdir(self): """ Test that the tmpdir expression works properly. """ result = ExpressionEvaluator.run("tmpdir") self.assertFalse(os.path.exists(result))
def testBasename(self): """ Test that the basename expression works properly. """ result = ExpressionEvaluator.run("basename", self.__path) self.assertEqual(result, "example.ext")
def testParentDirname(self): """ Test that the parentdirname expression works properly. """ result = ExpressionEvaluator.run("parentdirname", self.__path) self.assertEqual(result, "/test")
def testRemove(self): """ Test that the remove expression works properly. """ result = ExpressionEvaluator.run("remove", "boop", "p") self.assertEqual(result, "boo")
def testNewVersion(self): """ Test that the new expression works properly. """ result = ExpressionEvaluator.run("newver", BaseTestCase.dataDirectory()) self.assertEqual(result, "v003")
def testReplace(self): """ Test that the replace expression works properly. """ result = ExpressionEvaluator.run("replace", "Boop", "o", "e") self.assertEqual(result, "Beep")