Skip to content

Commit

Permalink
black: Simple spacing changes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Oct 30, 2024
1 parent cd5f2b4 commit e62d330
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
45 changes: 25 additions & 20 deletions src/croniter/tests/test_croniter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class CroniterTest(base.TestCase):

def testSecondSec(self):
base = datetime(2012, 4, 6, 13, 26, 10)
itr = croniter("* * * * * 15,25", base)
Expand Down Expand Up @@ -73,7 +72,7 @@ def testMinute(self):
# minute asterisk
base = datetime(2010, 1, 23, 12, 18)
itr = croniter("*/1 * * * *", base)
n1 = itr.get_next(datetime) # 19
n1 = itr.get_next(datetime) # 19
self.assertEqual(base.year, n1.year)
self.assertEqual(base.month, n1.month)
self.assertEqual(base.day, n1.day)
Expand Down Expand Up @@ -223,17 +222,17 @@ def testDomDowVixieCronBug(self):

# UNION OF "every odd-numbered day" and "every Saturday"
itr = croniter(expr, start_time=datetime(2023, 5, 2), ret_type=datetime)
self.assertEqual(itr.get_next(), datetime(2023, 5, 3, 16, 0, 0)) # Wed May 3 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 5, 16, 0, 0)) # Fri May 5 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 6, 16, 0, 0)) # Sat May 6 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 7, 16, 0, 0)) # Sun May 7 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 3, 16, 0, 0)) # Wed May 3 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 5, 16, 0, 0)) # Fri May 5 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 6, 16, 0, 0)) # Sat May 6 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 7, 16, 0, 0)) # Sun May 7 2023

# INTERSECTION OF "every odd-numbered day" and "every Saturday"
itr = croniter(expr, start_time=datetime(2023, 5, 2), ret_type=datetime, implement_cron_bug=True)
self.assertEqual(itr.get_next(), datetime(2023, 5, 13, 16, 0, 0)) # Sat May 13 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 27, 16, 0, 0)) # Sat May 27 2023
self.assertEqual(itr.get_next(), datetime(2023, 6, 3, 16, 0, 0)) # Sat June 3 2023
self.assertEqual(itr.get_next(), datetime(2023, 6, 17, 16, 0, 0)) # Sun June 17 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 13, 16, 0, 0)) # Sat May 13 2023
self.assertEqual(itr.get_next(), datetime(2023, 5, 27, 16, 0, 0)) # Sat May 27 2023
self.assertEqual(itr.get_next(), datetime(2023, 6, 3, 16, 0, 0)) # Sat June 3 2023
self.assertEqual(itr.get_next(), datetime(2023, 6, 17, 16, 0, 0)) # Sun June 17 2023

def testMonth(self):
base = datetime(2010, 1, 25)
Expand Down Expand Up @@ -347,7 +346,7 @@ def testSundayToThursdayWithAlphaConversion(self):
self.assertEqual(30, next.minute)

def testOptimizeCronExpressions(self):
""" Non-optimal cron expressions that can be simplified."""
"""Non-optimal cron expressions that can be simplified."""
wildcard = ["*"]
m, h, d, mon, dow, s = range(6)
# Test each field individually
Expand All @@ -368,7 +367,7 @@ def testOptimizeCronExpressions(self):
self.assertEqual(croniter("30 1-23,0 15-21 * fri").expanded[h], wildcard)

def testBlockDupRanges(self):
""" Ensure that duplicate/overlapping ranges are squashed """
"""Ensure that duplicate/overlapping ranges are squashed"""
m, h, d, mon, dow, s = range(6)
self.assertEqual(croniter("* 5,5,1-6 * * *").expanded[h], [1,2,3,4,5,6])
self.assertEqual(croniter("* * * * 2-3,4-5,3,3,3").expanded[dow], [2,3,4,5])
Expand Down Expand Up @@ -886,7 +885,7 @@ def test_std_dst3(self):

tz = pytz.timezone("Australia/Adelaide")

schedule = croniter("0 0 24 * *", tz.localize(datetime(2020, 4,15)))
schedule = croniter("0 0 24 * *", tz.localize(datetime(2020, 4, 15)))
val1 = schedule.get_prev(datetime)
dt1 = tz.localize(datetime(2020, 3, 24))
self.assertEqual(val1, dt1)
Expand Down Expand Up @@ -1252,18 +1251,18 @@ def test_dst_iter(self):
"2022-03-28T00:00:00+03:00"])

def test_nth_wday_simple(self):
f = lambda y,m,w: croniter._get_nth_weekday_of_month(y,m,w)
f = lambda y, m, w: croniter._get_nth_weekday_of_month(y, m, w)
sun, mon, tue, wed, thu, fri, sat = range(7)

self.assertEqual(f(2000, 1, mon), (3, 10, 17, 24, 31))
self.assertEqual(f(2000, 2, tue), (1, 8, 15, 22, 29)) # Leap year
self.assertEqual(f(2000, 2, tue), (1, 8, 15, 22, 29)) # Leap year
self.assertEqual(f(2000, 3, wed), (1, 8, 15, 22, 29))
self.assertEqual(f(2000, 4, thu), (6, 13, 20, 27))
self.assertEqual(f(2000, 2, fri), (4, 11, 18, 25))
self.assertEqual(f(2000, 2, sat), (5, 12, 19, 26))

def test_nth_as_last_wday_simple(self):
f = lambda y,m,w: croniter._get_nth_weekday_of_month(y,m,w)[-1]
f = lambda y, m, w: croniter._get_nth_weekday_of_month(y, m, w)[-1]
sun, mon, tue, wed, thu, fri, sat = range(7)
self.assertEqual(f(2000, 2, tue), 29)
self.assertEqual(f(2000, 2, sun), 27)
Expand All @@ -1274,7 +1273,7 @@ def test_nth_as_last_wday_simple(self):
self.assertEqual(f(2000, 2, sat), 26)

def test_wdom_core_leap_year(self):
f = lambda y,m,w: croniter._get_nth_weekday_of_month(y,m,w)[-1]
f = lambda y, m, w: croniter._get_nth_weekday_of_month(y, m, w)[-1]
sun, mon, tue, wed, thu, fri, sat = range(7)
self.assertEqual(f(2000, 2, tue), 29)
self.assertEqual(f(2000, 2, sun), 27)
Expand Down Expand Up @@ -1379,17 +1378,19 @@ def test_hash_mixup_all_fri_3rd_sat(self):
cron_b = "0 0 * * 5"
cron_c = "0 0 * * 5,6#3"
start = datetime(2021, 3, 1)
expect_a = [ datetime(2021, 3, 20) ]
expect_a = [datetime(2021, 3, 20)]
expect_b = [
datetime(2021, 3, 5),
datetime(2021, 3, 12),
datetime(2021, 3, 19),
datetime(2021, 3, 26),
]
expect_c = sorted(set(expect_a) & set(expect_b))

def getn(expr, n):
it = croniter(expr, start, ret_type=datetime)
return [next(it) for i in range(n)]

self.assertListEqual(getn(cron_a, 1), expect_a)
self.assertListEqual(getn(cron_b, 4), expect_b)
with self.assertRaises(CroniterUnsupportedSyntaxError):
Expand All @@ -1401,17 +1402,19 @@ def test_lwom_mixup_all_fri_last_sat(self):
cron_b = "0 0 * * 5"
cron_c = "0 0 * * 5,L6"
start = datetime(2021, 3, 1)
expect_a = [ datetime(2021, 3, 27) ]
expect_a = [datetime(2021, 3, 27)]
expect_b = [
datetime(2021, 3, 5),
datetime(2021, 3, 12),
datetime(2021, 3, 19),
datetime(2021, 3, 26),
]
expect_c = sorted(set(expect_a) | set(expect_b))

def getn(expr, n):
it = croniter(expr, start, ret_type=datetime)
return [next(it) for i in range(n)]

self.assertListEqual(getn(cron_a, 1), expect_a)
self.assertListEqual(getn(cron_b, 4), expect_b)
with self.assertRaises(CroniterUnsupportedSyntaxError):
Expand All @@ -1434,9 +1437,11 @@ def test_lwom_mixup_firstlast_sat(self):
datetime(2021, 5, 29),
]
expect_c = sorted(expect_a + expect_b)

def getn(expr, n):
it = croniter(expr, start, ret_type=datetime)
return [next(it) for i in range(n)]

self.assertListEqual(getn(cron_a, 3), expect_a)
self.assertListEqual(getn(cron_b, 3), expect_b)
self.assertListEqual(getn(cron_c, 6), expect_c)
Expand Down Expand Up @@ -1743,7 +1748,7 @@ def test_issue_k12(self):
base = datetime(2010, 1, 23, 12, 18, tzinfo=tz)
itr = croniter("* * * * *")
itr.set_current(start_time=base)
n1 = itr.get_next() # 19
n1 = itr.get_next() # 19

self.assertEqual(n1, datetime_to_timestamp(base) + 60)

Expand Down
2 changes: 1 addition & 1 deletion src/croniter/tests/test_croniter_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_expand_hours_range_10_hours(self):
for hash_id in self.HASH_IDS:
expanded = croniter.expand(expression, hash_id=hash_id)
_hours = expanded[0][1]
assert len(_hours) in {2,3}
assert len(_hours) in {2, 3}
hours.update(_hours)
assert len(hours) == self.TOTAL
assert min(hours) == self.MIN_VALUE
Expand Down
13 changes: 7 additions & 6 deletions src/croniter/tests/test_croniter_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class mydatetime(datetime):


class CroniterRangeTest(base.TestCase):

def test_1day_step(self):
start = datetime(2016, 12, 2)
stop = datetime(2016, 12, 10)
Expand Down Expand Up @@ -59,7 +58,7 @@ def test_1month_step(self):

def test_1minute_step_float(self):
start = datetime(2000, 1, 1, 0, 0)
stop = datetime(2000, 1, 1, 0, 1)
stop = datetime(2000, 1, 1, 0, 1)
res = list(croniter_range(start, stop, "* * * * *", ret_type=float))
self.assertEqual(len(res), 2)
self.assertEqual(res[0], 946684800.0)
Expand All @@ -86,19 +85,20 @@ def test_input_type_exceptions(self):
list(croniter_range(f_start1, dt_stop1, "0 * * * *"))

def test_timezone_dst(self):
""" Test across DST transition, which technically is a timzone change. """
"""Test across DST transition, which technically is a timzone change."""
tz = pytz.timezone("US/Eastern")
start = tz.localize(datetime(2020, 10, 30))
stop = tz.localize(datetime(2020, 11, 10))
stop = tz.localize(datetime(2020, 11, 10))
res = list(croniter_range(start, stop, "0 0 * * *"))
self.assertNotEqual(res[0].tzinfo, res[-1].tzinfo)
self.assertEqual(len(res), 12)

def test_extra_hour_day_prio(self):
def datetime_tz(*args, **kw):
""" Defined this in another branch. single-use-version """
"""Defined this in another branch. single-use-version"""
tzinfo = kw.pop("tzinfo")
return tzinfo.localize(datetime(*args))

tz = pytz.timezone("US/Eastern")
cron = "0 3 * * *"
start = datetime_tz(2020, 3, 7, tzinfo=tz)
Expand Down Expand Up @@ -137,7 +137,8 @@ def test_croniter_range_derived_class(self):
# trivial example extending croniter

class croniter_nosec(croniter):
""" Like croniter, but it forbids second-level cron expressions. """
"""Like croniter, but it forbids second-level cron expressions."""

@classmethod
def expand(cls, expr_format, *args, **kwargs):
if len(expr_format.split()) == 6:
Expand Down
3 changes: 2 additions & 1 deletion src/croniter/tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def testMinute(self):
# minute asterisk
base = datetime(2010, 1, 23, 12, 18)
itr = croniter("*/1 * * * *", base)
n1 = itr.get_next(datetime) # 19
n1 = itr.get_next(datetime) # 19
base.year == n1.year
base.month == n1.month
base.day == n1.day
Expand Down Expand Up @@ -221,5 +221,6 @@ def test_Noop(self):

if __name__ == "__main__":
from timeit import Timer

t = Timer("c=CroniterTest();c.run()", "from __main__ import CroniterTest")
print(t.timeit(200))

0 comments on commit e62d330

Please sign in to comment.