Skip to content

Commit 4b1b4e5

Browse files
Sebastian WagnerWagner
authored andcommitted
ENH+TST: utils/parse_relative: seconds and minutes
parse_relative in utils: Add support for parsing seconds and minutes
1 parent 70eb396 commit 4b1b4e5

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CHANGELOG
2828
- New function `list_all_bots` to list all available/installed bots as replacement for the BOTS file (#368, #552, #644, #757, #1069, #1750, PR#1751 by Sebastian Waldbauer).
2929
- New function `get_bots_settings` to return the effective bot parameters, with global parameters applied.
3030
- Removed deprecated function `create_request_session_from_bot` (PR#1997 by Sebastian Wagner, #1404).
31+
- `parse_relative`: Add support for parsing minutes and seconds (PR#1857 by Sebastian Wagner).
3132
- `intelmq.lib.bot_debugger`:
3233
- Set bot's `logging_level` directly in `__init__` before the bot's initialization by changing the default value (by Sebastian Wagner).
3334
- Rewrite `load_configuration_patch` by adapting it to the parameter and configuration rewrite (by Sebastian Wagner).

intelmq/lib/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def error_message_from_exc(exc: Exception) -> str:
481481

482482

483483
# number of minutes in time units
484-
TIMESPANS = {'hour': 60, 'day': 24 * 60, 'week': 7 * 24 * 60,
484+
TIMESPANS = {'second': 1 / 60, 'minute': 1,
485+
'hour': 60, 'day': 24 * 60, 'week': 7 * 24 * 60,
485486
'month': 30 * 24 * 60, 'year': 365 * 24 * 60}
486487

487488

intelmq/tests/lib/test_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,15 @@ def test_parse_relative(self):
210210
"""Tests if parse_reltive returns the correct timespan."""
211211
self.assertEqual(utils.parse_relative('1 hour'), 60)
212212
self.assertEqual(utils.parse_relative('2\tyears'), 1051200)
213+
self.assertEqual(utils.parse_relative('5 minutes'), 5)
214+
self.assertEqual(utils.parse_relative('10 seconds'), 1 / 60 * 10)
213215

214216
def test_parse_relative_raises(self):
215217
"""Tests if parse_reltive correctly raises ValueError."""
216218
with self.assertRaises(ValueError):
217219
utils.parse_relative('1 hou')
218220
with self.assertRaises(ValueError):
219-
utils.parse_relative('1 minute')
221+
utils.parse_relative('1 µs')
220222

221223
def test_seconds_to_human(self):
222224
""" Test seconds_to_human """

0 commit comments

Comments
 (0)