From 7eb04165fe93dd2582c8861c17e1038ddb2d7aa4 Mon Sep 17 00:00:00 2001 From: MeGaGiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Thu, 10 Apr 2025 17:29:46 -0700 Subject: Add step to zen command slicing --- tests/bot/exts/utils/test_utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/bot/exts/utils/test_utils.py b/tests/bot/exts/utils/test_utils.py index 5392e3512..17cfe05b8 100644 --- a/tests/bot/exts/utils/test_utils.py +++ b/tests/bot/exts/utils/test_utils.py @@ -65,11 +65,15 @@ class ZenTests(unittest.IsolatedAsyncioTestCase): """ Tests if the `!zen` command reacts properly to valid slices for indexing as an argument. """ expected_results = { - "0:19": ("The Zen of Python (lines 0-18):", "\n".join(self.zen_list[0:19])), - "0:": ("The Zen of Python (lines 0-18):", "\n".join(self.zen_list[0:])), - "-2:-1": ("The Zen of Python (lines 17-17):", self.zen_list[17]), + "0:19": ("The Zen of Python, by Tim Peters", "\n".join(self.zen_list)), + ":": ("The Zen of Python, by Tim Peters", "\n".join(self.zen_list)), + "::": ("The Zen of Python, by Tim Peters", "\n".join(self.zen_list)), + "1:": ("The Zen of Python (lines 1-18):", "\n".join(self.zen_list[1:])), + "-2:-1": ("The Zen of Python (line 17):", self.zen_list[17]), "0:-1": ("The Zen of Python (lines 0-17):", "\n".join(self.zen_list[0:-1])), - "10:13": ("The Zen of Python (lines 10-12):", "\n".join(self.zen_list[10:13])) + "10:13": ("The Zen of Python (lines 10-12):", "\n".join(self.zen_list[10:13])), + "::-1": ("The Zen of Python (step size -1):", "\n".join(self.zen_list[::-1])), + "10:5:-1": ("The Zen of Python (lines 6-10, step size -1):", "\n".join(self.zen_list[10:5:-1])), } for input_slice, (title, description) in expected_results.items(): @@ -83,8 +87,8 @@ class ZenTests(unittest.IsolatedAsyncioTestCase): async def test_zen_with_invalid_slices(self): """ Tests if the `!zen` command reacts properly to invalid slices for indexing as an argument. """ - slices= ["19:", "10:9", "-1:-2", "0:20", "-100:", "0:-100"] + slices= ["19:18", "10:9", "-1:-2", "0:-100", "::0", "1:2:-1", "-5:-4:-1"] for input_slice in slices: with self.subTest(input_slice = input_slice), self.assertRaises(BadArgument): - await self.cog.zen.callback(self.cog, self.ctx, search_value=input_slice) + await self.cog.zen.callback(self.cog, self.ctx, search_value=input_slice) \ No newline at end of file -- cgit v1.2.3 From 794663f74ea3d5113c2229b5cbd07e301f7248e4 Mon Sep 17 00:00:00 2001 From: MeGaGiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Thu, 10 Apr 2025 17:59:45 -0700 Subject: fix whitespace and file end lints --- bot/exts/utils/utils.py | 4 ++-- tests/bot/exts/utils/test_utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index 9bd4b1757..d83dbc2ce 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -125,10 +125,10 @@ class Utils(Cog): start_index = int(match.group("start")) if match.group("start") else None end_index = int(match.group("end")) if match.group("end") else None step_size = int(match.group("step")) if match.group("step") else 1 - + if step_size == 0: raise BadArgument(f"Step size must not be 0.") - + lines = zen_lines[start_index:end_index:step_size] if not lines: raise BadArgument(f"Slice returned 0 lines.") diff --git a/tests/bot/exts/utils/test_utils.py b/tests/bot/exts/utils/test_utils.py index 17cfe05b8..9b8ea4ade 100644 --- a/tests/bot/exts/utils/test_utils.py +++ b/tests/bot/exts/utils/test_utils.py @@ -91,4 +91,4 @@ class ZenTests(unittest.IsolatedAsyncioTestCase): for input_slice in slices: with self.subTest(input_slice = input_slice), self.assertRaises(BadArgument): - await self.cog.zen.callback(self.cog, self.ctx, search_value=input_slice) \ No newline at end of file + await self.cog.zen.callback(self.cog, self.ctx, search_value=input_slice) -- cgit v1.2.3