aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-04-28 15:56:15 -0700
committerGravatar MarkKoz <[email protected]>2020-04-28 15:57:30 -0700
commit96920935f9af6d325a2ff91d197285204b3221c9 (patch)
tree5f307dd4ecfcda57af9fbb81cb058a016561764c /tests
parentConverters: handle ValueError when year for duration is out of range (diff)
Test for out of range datetime in the Duration converter
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/test_converters.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/bot/test_converters.py b/tests/bot/test_converters.py
index ca8cb6825..e42bfc7ee 100644
--- a/tests/bot/test_converters.py
+++ b/tests/bot/test_converters.py
@@ -198,6 +198,17 @@ class ConverterTests(unittest.TestCase):
with self.assertRaises(BadArgument, msg=exception_message):
asyncio.run(converter.convert(self.context, invalid_duration))
+ @patch("bot.converters.datetime")
+ def test_duration_converter_out_of_range(self, mock_datetime):
+ """Duration converter should raise BadArgument if datetime raises a ValueError."""
+ mock_datetime.__add__.side_effect = ValueError
+ mock_datetime.utcnow.return_value = mock_datetime
+
+ duration = f"{datetime.MAXYEAR}y"
+ exception_message = f"`{duration}` results in a datetime outside the supported range."
+ with self.assertRaisesRegex(BadArgument, exception_message):
+ asyncio.run(Duration().convert(self.context, duration))
+
def test_isodatetime_converter_for_valid(self):
"""ISODateTime converter returns correct datetime for valid datetime string."""
test_values = (