1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
|
# The MIT License (MIT)
#
# Copyright (c) 2016 Adam Schubert
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import tests.TestCase as TestCase
from cron_descriptor import get_description
class TestFormats(TestCase.TestCase):
"""
Tests formatted cron expressions
"""
def test_every_minute(self):
self.assertEqual("Every minute", get_description("* * * * *", self.options))
def test_every1_minute(self):
self.assertEqual("Every minute", get_description("*/1 * * * *", self.options))
self.assertEqual("Every minute", get_description("0 0/1 * * * ?", self.options))
def test_every_hour(self):
self.assertEqual("Every hour", get_description("0 0 * * * ?", self.options))
self.assertEqual("Every hour", get_description("0 0 0/1 * * ?", self.options))
def test_time_of_day_certain_days_of_week(self):
self.assertEqual(
"At 11:00 PM, Monday through Friday",
get_description("0 23 ? * MON-FRI", self.options))
def test_every_second(self):
self.assertEqual("Every second", get_description("* * * * * *", self.options))
def test_every45_seconds(self):
self.assertEqual("Every 45 seconds", get_description("*/45 * * * * *", self.options))
def test_every5_minutes(self):
self.assertEqual("Every 5 minutes", get_description("*/5 * * * *", self.options))
self.assertEqual("Every 10 minutes", get_description("0 0/10 * * * ?", self.options))
def test_every5_minutes_on_the_second(self):
self.assertEqual("Every 5 minutes", get_description("0 */5 * * * *", self.options))
def test_weekdays_at_time(self):
self.assertEqual(
"At 11:30 AM, Monday through Friday",
get_description("30 11 * * 1-5", self.options))
def test_daily_at_time(self):
self.assertEqual("At 11:30 AM", get_description("30 11 * * *", self.options))
def test_minute_span(self):
self.assertEqual(
"Every minute between 11:00 AM and 11:10 AM", get_description("0-10 11 * * *", self.options))
def test_one_month_only(self):
self.assertEqual(
"Every minute, only in March",
get_description("* * * 3 *", self.options))
def test_two_months_only(self):
self.assertEqual(
"Every minute, only in March and June",
get_description("* * * 3,6 *", self.options))
def test_two_times_each_afternoon(self):
self.assertEqual(
"At 02:30 PM and 04:30 PM",
get_description("30 14,16 * * *", self.options))
def test_three_times_daily(self):
self.assertEqual(
"At 06:30 AM, 02:30 PM and 04:30 PM",
get_description("30 6,14,16 * * *", self.options))
def test_once_a_week(self):
self.assertEqual(
"At 09:46 AM, only on Monday",
get_description("46 9 * * 1", self.options))
def test_day_of_month(self):
self.assertEqual(
"At 12:23 PM, on day 15 of the month",
get_description("23 12 15 * *", self.options))
def test_month_name(self):
self.assertEqual(
"At 12:23 PM, only in January",
get_description("23 12 * JAN *", self.options))
def test_lowercase_month_name(self):
self.assertEqual(
"At 12:23 PM, only in January",
get_description("23 12 * jan *", self.options))
def test_day_of_month_with_question_mark(self):
self.assertEqual(
"At 12:23 PM, only in January",
get_description("23 12 ? JAN *", self.options))
def test_month_name_range2(self):
self.assertEqual(
"At 12:23 PM, January through February", get_description("23 12 * JAN-FEB *", self.options))
def test_month_name_range3(self):
self.assertEqual(
"At 12:23 PM, January through March",
get_description("23 12 * JAN-MAR *", self.options))
def test_day_of_week_name(self):
self.assertEqual(
"At 12:23 PM, only on Sunday",
get_description("23 12 * * SUN", self.options))
def test_day_of_week_name_lowercase(self):
self.assertEqual(
"At 12:23 PM, only on Sunday",
get_description("23 12 * * sun", self.options))
def test_day_of_week_range(self):
self.assertEqual(
"Every 5 minutes, between 03:00 PM and 03:59 PM, Monday through Friday", get_description("*/5 15 * * MON-FRI", self.options))
def test_day_of_week_range_lowercase(self):
self.assertEqual(
"Every 5 minutes, between 03:00 PM and 03:59 PM, Monday through Friday", get_description("*/5 15 * * MoN-fri", self.options))
def test_day_of_week_once_in_month(self):
self.assertEqual(
"Every minute, on the third Monday of the month", get_description("* * * * MON#3", self.options))
def test_last_day_of_the_week_of_the_month(self):
self.assertEqual(
"Every minute, on the last Thursday of the month", get_description("* * * * 4L", self.options))
def test_last_day_of_the_month(self):
self.assertEqual(
"Every 5 minutes, on the last day of the month, only in January", get_description(
"*/5 * L JAN *",
self.options
)
)
def test_last_day_offset(self):
self.assertEqual(
"At 12:00 AM, 5 days before the last day of the month", get_description(
"0 0 0 L-5 * ?",
self.options
)
)
def test_last_weekday_of_the_month(self):
self.assertEqual(
"Every minute, on the last weekday of the month", get_description("* * LW * *", self.options))
def test_last_weekday_of_the_month2(self):
self.assertEqual(
"Every minute, on the last weekday of the month", get_description("* * WL * *", self.options))
def test_first_weekday_of_the_month(self):
self.assertEqual(
"Every minute, on the first weekday of the month", get_description("* * 1W * *", self.options))
def test_thirteenth_weekday_of_the_month(self):
self.assertEqual(
"Every minute, on the weekday nearest day 13 of the month", get_description("* * 13W * *", self.options))
def test_first_weekday_of_the_month2(self):
self.assertEqual(
"Every minute, on the first weekday of the month", get_description("* * W1 * *", self.options))
def test_particular_weekday_of_the_month(self):
self.assertEqual(
"Every minute, on the weekday nearest day 5 of the month", get_description("* * 5W * *", self.options))
def test_particular_weekday_of_the_month2(self):
self.assertEqual(
"Every minute, on the weekday nearest day 5 of the month", get_description("* * W5 * *", self.options))
def test_time_of_day_with_seconds(self):
self.assertEqual("At 02:02:30 PM", get_description("30 02 14 * * *", self.options))
def test_second_intervals(self):
self.assertEqual(
"Seconds 5 through 10 past the minute",
get_description("5-10 * * * * *", self.options))
def test_multi_part_second(self):
self.assertEqual(
"At 15 and 45 seconds past the minute",
get_description("15,45 * * * * *", self.options)
)
def test_second_minutes_hours_intervals(self):
self.assertEqual((
"Seconds 5 through 10 past the minute, "
"minutes 30 through 35 past the hour, "
"between 10:00 AM and 12:59 PM"), get_description("5-10 30-35 10-12 * * *", self.options))
def test_every5_minutes_at30_seconds(self):
self.assertEqual(
"At 30 seconds past the minute, every 5 minutes", get_description("30 */5 * * * *", self.options))
def test_minutes_past_the_hour_range(self):
self.assertEqual((
"At 30 minutes past the hour, "
"between 10:00 AM and 01:59 PM, "
"only on Wednesday and Friday"), get_description("0 30 10-13 ? * WED,FRI", self.options))
def test_seconds_past_the_minute_interval(self):
self.assertEqual(
"At 10 seconds past the minute, every 5 minutes",
get_description("10 0/5 * * * ?", self.options)
)
def test_between_with_interval(self):
self.assertEqual(
("Every 3 minutes, minutes 2 through 59 past the hour, "
"at 01:00 AM, 09:00 AM, and 10:00 PM, between day 11 and 26 of the month, "
"January through June"), get_description("2-59/3 1,9,22 11-26 1-6 ?", self.options))
def test_recurring_first_of_month(self):
self.assertEqual("At 06:00 AM", get_description("0 0 6 1/1 * ?", self.options))
def test_minutes_past_the_hour(self):
self.assertEqual(
"At 5 minutes past the hour",
get_description("0 5 0/1 * * ?", self.options)
)
def test_one_year_only_with_seconds(self):
self.assertEqual(
"Every second, only in 2013",
get_description("* * * * * * 2013", self.options))
def test_one_year_only_without_seconds(self):
self.assertEqual(
"Every minute, only in 2013",
get_description("* * * * * 2013", self.options))
def test_two_years_only(self):
self.assertEqual(
"Every minute, only in 2013 and 2014", get_description("* * * * * 2013,2014", self.options))
def test_year_range2(self):
self.assertEqual(
"At 12:23 PM, January through February, 2013 through 2014", get_description(
"23 12 * JAN-FEB * 2013-2014",
self.options
)
)
def test_year_range3(self):
self.assertEqual(
"At 12:23 PM, January through March, 2013 through 2015", get_description(
"23 12 * JAN-MAR * 2013-2015",
self.options
)
)
def test_hour_range(self):
self.assertEqual((
"Every 30 minutes, between 08:00 AM and 09:59 AM, "
"on day 5 and 20 of the month"), get_description("0 0/30 8-9 5,20 * ?", self.options))
def test_day_of_week_modifier(self):
self.assertEqual(
"At 12:23 PM, on the second Sunday of the month", get_description("23 12 * * SUN#2", self.options))
def test_day_of_week_modifier_with_sunday_start_one(self):
self.options.day_of_week_start_index_zero = False
self.assertEqual(
"At 12:23 PM, on the second Sunday of the month", get_description("23 12 * * 1#2", self.options))
def test_hour_range_with_every_portion(self):
self.assertEqual((
"At 25 minutes past the hour, every 8 hours, "
"between 07:00 AM and 07:59 PM"), get_description("0 25 7-19/8 ? * *", self.options))
def test_hour_range_with_trailing_zero_with_every_portion(self):
self.assertEqual((
"At 25 minutes past the hour, every 13 hours, "
"between 07:00 AM and 08:59 PM"), get_description("0 25 7-20/13 ? * *", self.options))
def test_every3_day(self):
self.assertEqual(
"At 08:00 AM, every 3 days",
get_description("0 0 8 1/3 * ? *", self.options))
def tests_every3_day_of_the_week(self):
self.assertEqual(
"At 10:15 AM, every 3 days of the week",
get_description("0 15 10 ? * */3", self.options))
def test_every_2_day_of_the_week_in_range(self):
self.assertEqual(
"Every second, every 2 days of the week, Monday through Friday",
get_description("* * * ? * 1-5/2", self.options))
def test_every_2_day_of_the_week_in_range_with_sunday_start_one(self):
self.options.day_of_week_start_index_zero = False
self.assertEqual(
"Every second, every 2 days of the week, Monday through Friday",
get_description("* * * ? * 2-6/2", self.options))
def test_multi_with_day_of_week_start_index_zero_false(self):
self.options.day_of_week_start_index_zero = False
self.assertEqual(
"Every second, only on Sunday, Monday, and Tuesday",
get_description("* * * ? * 1,2,3", self.options)
)
def test_every3_month(self):
self.assertEqual(
"At 07:05 AM, on day 2 of the month, every 3 months", get_description("0 5 7 2 1/3 ? *", self.options))
def test_every2_years(self):
self.assertEqual(
"At 06:15 AM, on day 1 of the month, only in January, every 2 years", get_description(
"0 15 6 1 1 ? 1/2",
self.options
)
)
def test_multi_part_range_minutes(self):
self.assertEqual(
"At 2 and 4 through 5 minutes past the hour, at 01:00 AM", get_description("2,4-5 1 * * *", self.options))
def test_multi_part_range_minutes_2(self):
self.assertEqual(
"At 2 and 26 through 28 minutes past the hour, at 06:00 PM", get_description(
"2,26-28 18 * * *",
self.options
)
)
def test_trailing_space_does_not_cause_a_wrong_description(self):
self.assertEqual(
"At 07:00 AM", get_description("0 7 * * * ", self.options))
def test_multi_part_day_of_the_week(self):
self.assertEqual(
"At 10:00 AM, only on Monday through Thursday and Sunday",
get_description("0 00 10 ? * MON-THU,SUN *")
)
def test_day_of_week_with_day_of_month(self):
self.assertEqual(
"At 12:00 AM, on day 1, 2, and 3 of the month, only on Wednesday and Friday",
get_description("0 0 0 1,2,3 * WED,FRI", self.options)
)
def test_seconds_interval_with_step_value(self):
self.assertEqual(
"Every 30 seconds, starting at 5 seconds past the minute",
get_description("5/30 * * * * ?", self.options))
def test_minutes_interval_with_step_value(self):
self.assertEqual(
"Every 30 minutes, starting at 5 minutes past the hour",
get_description("0 5/30 * * * ?", self.options))
def test_hours_interval_with_step_value(self):
self.assertEqual(
"Every second, every 8 hours, starting at 05:00 AM",
get_description("* * 5/8 * * ?", self.options))
def test_day_of_month_interval_with_step_value(self):
self.assertEqual(
"At 07:05 AM, every 3 days, starting on day 2 of the month",
get_description("0 5 7 2/3 * ? *", self.options))
def test_month_interval_with_step_value(self):
self.assertEqual(
"At 07:05 AM, every 2 months, March through December",
get_description("0 5 7 ? 3/2 ? *", self.options))
def test_day_of_week_interval_with_step_value(self):
self.assertEqual(
"At 07:05 AM, every 3 days of the week, Tuesday through Saturday",
get_description("0 5 7 ? * 2/3 *", self.options))
def test_year_interval_with_step_value(self):
self.assertEqual(
"At 07:05 AM, every 4 years, 2016 through 9999",
get_description("0 5 7 ? * ? 2016/4", self.options))
def test_minutes_combined_with_multiple_hour_ranges(self):
self.assertEqual(
"At 1 minutes past the hour, at 01:00 AM and 03:00 AM through 04:59 AM",
get_description("1 1,3-4 * * *", self.options))
def test_minute_range_conbined_with_second_range(self):
self.assertEqual(
"Seconds 12 through 50 past the minute, minutes 0 through 10 past the hour, at 06:00 AM, only in 2022",
get_description("12-50 0-10 6 * * * 2022", self.options)
)
def test_seconds_expression_combined_with_hours_list_and_single_minute(self):
self.assertEqual(
"At 5 seconds past the minute, at 30 minutes past the hour, at 06:00 AM, 02:00 PM, and 04:00 PM, on day 5 of the month",
get_description("5 30 6,14,16 5 * *", self.options)
)
def test_minute_range_with_interval(self):
self.assertEqual(
"Every 3 minutes, minutes 0 through 20 past the hour, between 09:00 AM and 09:59 AM",
get_description("0-20/3 9 * * *", self.options)
)
def minutes_zero_1(self):
self.assertEqual(
"Every second, at 0 minutes past the hour, every 4 hours",
get_description("* 0 */4 * * *", self.options)
)
def minutes_zero_2(self):
self.assertEqual(
"Every 10 seconds, at 0 minutes past the hour",
get_description("*/10 0 * * * *", self.options)
)
def minutes_zero_3(self):
self.assertEqual(
"Every second, at 0 minutes past the hour, between 12:00 AM and 12:59 AM",
get_description("* 0 0 * * *", self.options)
)
def minutes_zero_4(self):
self.assertEqual(
"Every minute, between 12:00 AM and 12:59 AM",
get_description("* 0 * * *", self.options)
)
def minutes_zero_5(self):
self.assertEqual(
"Every second, at 0 minutes past the hour",
get_description("* 0 * * * *", self.options)
)
def sunday_7(self):
self.assertEqual(
"At 09:00 AM, only on Sunday",
get_description("0 0 9 ? * 7", self.options)
)
def every_year(self):
self.assertEqual(
"Every 10 minutes, Monday through Friday",
get_description("0/10 * ? * MON-FRI *", self.options)
)
|