Exemplo n.º 1
0
 def check_exceptions(self):
     """ wrong lines - test exceptions """
     d = datetime.datetime(2003, 10, 25, 15, 35)
     line = "0-60 * * * * every minute, wrong format"
     cronline = pycron.Cronline(line, 1)
     self.assertRaises(pycron.InvalidLineException, cronline.checktime, d,
                       d)
     line = "* 24 * * * wrong format"
     cronline = pycron.Cronline(line, 1)
     self.assertRaises(pycron.InvalidLineException, cronline.checktime, d,
                       d)
     line = "* * * * 7 wrong dow"
     cronline = pycron.Cronline(line, 1)
     self.assertRaises(pycron.InvalidLineException, cronline.checktime, d,
                       d)
Exemplo n.º 2
0
 def check_missed_task_parser(self):
     """ command with ! or * """
     line = '* * * * * !"a command" "123"'
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.command, "a command")
     self.assertEqual(cronline.parameters, ["123"])
     line = '* * * * * *"a command" "123"'
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.command, "a command")
     self.assertEqual(cronline.parameters, ["123"])
     line = '* * * * * !acommand "123"'
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.command, "acommand")
     self.assertEqual(cronline.parameters, ["123"])
     line = '* * * * * *acommand "123"'
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.command, "acommand")
     self.assertEqual(cronline.parameters, ["123"])
Exemplo n.º 3
0
 def check_longfilename(self):
     """ long file name with "..." """
     line = '* * * * * "this is a long line" foo bar'
     cronline = pycron.Cronline(line, 1)
     assert cronline.command == "this is a long line"
     assert cronline.parameters == ["foo", "bar"]
     line = '* * * * * "this is a long line" abc def "foo bar"'
     cronline = pycron.Cronline(line, 1)
     assert cronline.command == "this is a long line"
     assert cronline.parameters == ["abc", "def", '"foo bar"']
     line = '* * * * * command "this is a long line" foo bar'
     cronline = pycron.Cronline(line, 1)
     assert cronline.command == "command"
     assert cronline.parameters == ['"this is a long line"', "foo", "bar"]
     line = '* * * * * command'
     cronline = pycron.Cronline(line, 1)
     assert cronline.command == "command"
     assert cronline.parameters is None
Exemplo n.º 4
0
 def check_parameter_with_and(self):
     """ parameter with '&' """
     line = '* * * * * "C:\\Program Files\\Mozilla Firefox\\firefox.exe" http://something.com:8000/admin.cgi?pass=password&mode=updinfo&song=something'
     cronline = pycron.Cronline(line, 1)
     self.assertEquals(cronline.command,
                       "C:\\Program Files\\Mozilla Firefox\\firefox.exe")
     self.assertEquals(cronline.parameters, [
         "http://something.com:8000/admin.cgi?pass=password&mode=updinfo&song=something"
     ])
Exemplo n.º 5
0
 def check_alphanumeric_values(self):
     d = datetime.datetime(2004, 11, 24, 22, 35)
     line = "* * * Oct-December Wednesday xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     self.assertEqual(pycron.replace_alphanumerics("Septem"), 9)
     self.assertRaises(ValueError, pycron.replace_alphanumerics, "Sepptem")
     self.assertEqual(pycron.replace_alphanumerics("Sunday"), 0)
     self.assertEqual(pycron.replace_alphanumerics("Monday"), 1)
     self.assertEqual(pycron.replace_alphanumerics("Saturday"), 6)
     self.assertEqual(pycron.replace_alphanumerics("Fri"), 5)
Exemplo n.º 6
0
 def check_env_vars(self):
     d = datetime.datetime(2003, 10, 25, 22, 35)
     os.environ["TEST1"] = "this is environment variable no 1"
     os.environ["TEST2"] = "env_variable_2"
     line = "* 22-2 * * * %TEST1%\\%TEST2% %TEST2% %TEST1% %NOTFOUND%"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.command,
                      "this is environment variable no 1\\env_variable_2")
     assert "this is environment variable no 1" in cronline.parameters
     assert "env_variable_2" in cronline.parameters
     assert "%NOTFOUND%" in cronline.parameters
     self.assertEqual(len(cronline.parameters), 3)
Exemplo n.º 7
0
 def check_startuptime(self):
     d = datetime.datetime(2003, 10, 25, 15, 3)
     d2 = datetime.datetime(2003, 10, 26, 15, 4)
     line = "? ? ? ? ? time of startup"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     self.assertEqual(cronline.checktime(d, d2), False)
     line = "* ? * ? ? time of startup"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     self.assertEqual(cronline.checktime(d, d2), False)
     line = "* ? * ? * time of startup"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d2), True)
     line = "*/2 ? * ? * time of startup"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d2), False)
     line = "*/3 ? * ? * time of startup"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d2), True)
     line = "* 22-2 * * * xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertRaises(pycron.InvalidLineException, cronline.checktime, d,
                       d)
Exemplo n.º 8
0
 def check_lines(self):
     """ lines with different matching symbols """
     d = datetime.datetime(2003, 10, 25, 15, 35)  # Saturday
     line = "* * * * * xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "*/5 * * * * every 5 minutes"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "*/4 * * * * every 4 minutes"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), False)
     line = "*/5 15 * * * xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "0-59/5 */3 * * * every 5 minutes, every 3 hours"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "0-59/5 */4 * * * every 5 minutes, every 4 hours"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), False)
     line = "1,2,3,4-7,9,10-19/2,20-59/2 * * * * xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), False)
     line = "1,2,3,4-7,9,10-19/2,20-59/3 * * * * xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "* * * * 6 xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     line = "* * * * 5 xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), False)
     d = datetime.datetime(2003, 10, 26, 15, 35)  # Sunday
     line = "* * * * 0 xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
     # XXX: this should work too:
     #line = "* * * * 7 xxx" # sunday, too
     #cronline = pycron.Cronline(line, 1)
     #self.assertEqual(cronline.checktime(d, d), True)
     d = datetime.datetime(2003, 10, 27, 15, 35)  # Monday
     line = "* * * * 1 xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)
Exemplo n.º 9
0
 def check_no_missed_task(self):
     startup = datetime.datetime(2004, 11, 24, 21, 45)
     line = "*/15 * * Oct-December Wednesday !no missed tasks"
     cronline = pycron.Cronline(line, 1)
     shutdown = datetime.datetime(2004, 11, 24, 21, 30)
     self.assertEqual(cronline.missed_tasks(shutdown, startup, False), 0)
Exemplo n.º 10
0
 def check_missed_task_questionmark(self):
     startup = datetime.datetime(2004, 11, 24, 22, 45)
     line = "? ? * Oct-December wed *missed tasks - should not work with question marks"
     cronline = pycron.Cronline(line, 1)
     shutdown = datetime.datetime(2004, 11, 24, 21, 30)
     self.assertEqual(cronline.missed_tasks(shutdown, startup, False), 0)
Exemplo n.º 11
0
 def check_missed_task3(self):
     startup = datetime.datetime(2006, 01, 15, 9, 0)
     line = "0 2 * * * !'missed task'"
     cronline = pycron.Cronline(line, 1)
     shutdown = datetime.datetime(2006, 01, 15, 10, 0)
     self.assertEqual(cronline.missed_tasks(shutdown, startup, False), 0)
Exemplo n.º 12
0
 def check_missed_task2(self):
     startup = datetime.datetime(2004, 11, 24, 22, 45)
     line = "*/15 * * Oct-December wed !'missed tasks'"
     cronline = pycron.Cronline(line, 1)
     shutdown = datetime.datetime(2004, 11, 24, 21, 30)
     self.assertEqual(cronline.missed_tasks(shutdown, startup, False), 1)
Exemplo n.º 13
0
 def check_spaces(self):
     d = datetime.datetime(2003, 10, 25, 15, 35)  # Saturday
     line = "* *       * *      6 xxx"
     cronline = pycron.Cronline(line, 1)
     self.assertEqual(cronline.checktime(d, d), True)