aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Kyle Stanley <[email protected]>2020-06-04 03:17:11 -0400
committerGravatar Kyle Stanley <[email protected]>2020-06-04 03:47:08 -0400
commit5f5a51b1715228ac5b401ef6bed8a83491e313de (patch)
tree1978b9ec451af26d0d3a8032a6fd8614fd9bdf07 /tests
parentMerge pull request #922 from python-discord/bug/info/914/user-animated-avatar (diff)
Improve LinePaginator to support long lines
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/test_pagination.py41
1 files changed, 34 insertions, 7 deletions
diff --git a/tests/bot/test_pagination.py b/tests/bot/test_pagination.py
index 0a734b505..f2e2c27ce 100644
--- a/tests/bot/test_pagination.py
+++ b/tests/bot/test_pagination.py
@@ -8,17 +8,44 @@ class LinePaginatorTests(TestCase):
def setUp(self):
"""Create a paginator for the test method."""
- self.paginator = pagination.LinePaginator(prefix='', suffix='', max_size=30)
-
- def test_add_line_raises_on_too_long_lines(self):
- """`add_line` should raise a `RuntimeError` for too long lines."""
- message = f"Line exceeds maximum page size {self.paginator.max_size - 2}"
- with self.assertRaises(RuntimeError, msg=message):
- self.paginator.add_line('x' * self.paginator.max_size)
+ self.paginator = pagination.LinePaginator(prefix='', suffix='', max_size=30,
+ scale_to_size=50)
def test_add_line_works_on_small_lines(self):
"""`add_line` should allow small lines to be added."""
self.paginator.add_line('x' * (self.paginator.max_size - 3))
+ # Note that the page isn't added to _pages until it's full.
+ self.assertEqual(len(self.paginator._pages), 0)
+
+ def test_add_line_works_on_long_lines(self):
+ """`add_line` should scale long lines up to `scale_to_size`."""
+ self.paginator.add_line('x' * self.paginator.scale_to_size)
+ self.assertEqual(len(self.paginator._pages), 1)
+
+ # Any additional lines should start a new page after `max_size` is exceeded.
+ self.paginator.add_line('x')
+ self.assertEqual(len(self.paginator._pages), 2)
+
+ def test_add_line_continuation(self):
+ """When `scale_to_size` is exceeded, remaining words should be split onto the next page."""
+ self.paginator.add_line('zyz ' * (self.paginator.scale_to_size//4 + 1))
+ self.assertEqual(len(self.paginator._pages), 2)
+
+ def test_add_line_no_continuation(self):
+ """If adding a new line to an existing page would exceed `max_size`, it should start a new
+ page rather than using continuation.
+ """
+ self.paginator.add_line('z' * (self.paginator.max_size - 3))
+ self.paginator.add_line('z')
+ self.assertEqual(len(self.paginator._pages), 1)
+
+ def test_add_line_raises_on_very_long_words(self):
+ """`add_line` should raise if a single long word is added that exceeds `scale_to_size`.
+
+ Note: truncation is also a potential option, but this should not occur from normal usage.
+ """
+ with self.assertRaises(RuntimeError):
+ self.paginator.add_line('x' * (self.paginator.scale_to_size + 1))
class ImagePaginatorTests(TestCase):