diff options
author | Lowell Alleman <lowell@kintyre.co> | 2021-03-23 14:55:22 -0400 |
---|---|---|
committer | Lowell Alleman <lowell@kintyre.co> | 2021-03-23 14:55:22 -0400 |
commit | d0ed29433a4a8b2685bc6428055476dddc082730 (patch) | |
tree | 00aaa57d3aa0dada21abc7f2c16a9d05f1b4b187 | |
parent | 48efd7a0f2ad85b355c068f755b5d84ebd724387 (diff) | |
download | croniter-d0ed29433a4a8b2685bc6428055476dddc082730.tar.gz |
Remove natsort
- Remove external requirement for 'natsort' and replace it with sorted() using
a custom lambda as the 'key'.
- Added unit test checking that 'expanded' values are sorted as expected.
-rw-r--r-- | docs/CHANGES.rst | 7 | ||||
-rw-r--r-- | requirements/base.txt | 1 | ||||
-rw-r--r-- | src/croniter/croniter.py | 4 | ||||
-rwxr-xr-x | src/croniter/tests/test_croniter.py | 7 |
4 files changed, 14 insertions, 5 deletions
diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index d735083..34dec96 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 1.0.9 (unreleased) ------------------ -- Nothing changed yet. +- Remove external library ``natsort``. + Sorting of cron expression components now handled with ``sorted()`` with a custom ``key`` function. + [Kintyre] + 1.0.8 (2021-03-06) @@ -107,7 +110,7 @@ Changelog ------------------- - Make dateutil tz support more official - [lowell80] + [Kintyre] - Feat/support for day or [田口信元] diff --git a/requirements/base.txt b/requirements/base.txt index 56d1bf5..7ff05fa 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,4 +1,3 @@ python_dateutil future -natsort -e . diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py index e5b8318..3d1001b 100644 --- a/src/croniter/croniter.py +++ b/src/croniter/croniter.py @@ -11,7 +11,6 @@ import datetime from dateutil.relativedelta import relativedelta from dateutil.tz import tzutc import calendar -import natsort from future.utils import raise_from @@ -642,7 +641,8 @@ class croniter(object): nth_weekday_of_month[t].add(int(nth)) res = set(res) - res = natsort.natsorted(res) + res = sorted(res, key=lambda i: "{:02}".format(i) if isinstance(i, int) else i) + # res = sorted(res) if len(res) == cls.LEN_MEANS_ALL[i]: res = ['*'] diff --git a/src/croniter/tests/test_croniter.py b/src/croniter/tests/test_croniter.py index 2bdd0c3..6eb5991 100755 --- a/src/croniter/tests/test_croniter.py +++ b/src/croniter/tests/test_croniter.py @@ -1313,6 +1313,13 @@ class CroniterRangeTest(base.TestCase): dt = croniter("0 0 * * *,sat#3", datetime(2019, 1, 14, 11, 0, 59, 999999)).get_next() self.assertEqual(1547856000.0, dt) + def test_confirm_sort(self): + m, h, d, mon, dow, s = range(6) + self.assertListEqual(croniter('0 8,22,10,23 0 0 0').expanded[h], [8, 10, 22, 23]) + self.assertListEqual(croniter('0 0 25-L 0 0').expanded[d], [25, 26, 27, 28, 29, 30, 31]) + self.assertListEqual(croniter("1 1 7,14,21,L * *").expanded[d], [7, 14, 21, "l"]) + self.assertListEqual(croniter("0 0 * * *,sat#3").expanded[dow], ["*", 6]) + if __name__ == '__main__': unittest.main() |