Rename shortened to head_and_tail
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 7 Dec 2016 15:10:10 +0000 (16:10 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 7 Dec 2016 15:10:10 +0000 (16:10 +0100)
src/text_helpers.py
test/test_text_helpers.py

index d5e208f..206e016 100644 (file)
@@ -32,7 +32,7 @@ from itertools import islice
 from type_helpers import isstr
 
 
-def shortened(iterable, n_head=20, n_tail=20, n_elems=None,
+def head_and_tail(iterable, n_head=20, n_tail=20, n_elems=None,
               skip_elem="...(skipping {n_skipped} elements)..."):
     """ convenient way to shorten a possibly very long iterable before printing
 
index 1641cf0..0b618ad 100644 (file)
@@ -46,42 +46,42 @@ class TextHelpersTester(unittest.TestCase):
             exec('{0}("{0}")'.format(style))
 
     def test_shortening(self):
-        """ test function shortened """
+        """ test function head_and_tail """
 
-        # test iterating over shortened works
+        # test iterating over head_and_tail works
         orig = tuple(range(10))
-        for elem in shortened(orig):
+        for elem in head_and_tail(orig):
             pass
 
         # test non-shortening
-        self.assertEqual(list(shortened(range(3))), list(range(3)))
+        self.assertEqual(list(head_and_tail(range(3))), list(range(3)))
 
         # test shortening with indexable iter
-        short = tuple(shortened(tuple(range(100)), skip_elem=None))
+        short = tuple(head_and_tail(tuple(range(100)), skip_elem=None))
         expect = tuple(range(20)) + tuple(range(80,100))
         self.assertEqual(short, expect)
         self.assertEqual(len(short), 40)
 
         # test strange cases: no head, no tail, no skip
-        short = tuple(shortened(orig, n_head=2, n_tail=0, skip_elem=None))
+        short = tuple(head_and_tail(orig, n_head=2, n_tail=0, skip_elem=None))
         self.assertEqual(short, (0, 1))
-        short = tuple(shortened(orig, n_head=0, n_tail=2, skip_elem=None))
+        short = tuple(head_and_tail(orig, n_head=0, n_tail=2, skip_elem=None))
         self.assertEqual(short, (8, 9))
-        short = tuple(shortened(orig, n_head=0, n_tail=0, skip_elem=None))
+        short = tuple(head_and_tail(orig, n_head=0, n_tail=0, skip_elem=None))
         self.assertEqual(len(short), 0)
-        short = tuple(shortened(orig, n_head=0, n_tail=0, skip_elem="Hi!"))
+        short = tuple(head_and_tail(orig, n_head=0, n_tail=0, skip_elem="Hi!"))
         self.assertEqual(short, ("Hi!",))
 
         # test n_head + n_tail == n_elems
-        short = tuple(shortened(orig, n_head=5, n_tail=5))
+        short = tuple(head_and_tail(orig, n_head=5, n_tail=5))
         self.assertEqual(short, orig)
-        short = tuple(shortened(orig, n_head=10, n_tail=0))
+        short = tuple(head_and_tail(orig, n_head=10, n_tail=0))
         self.assertEqual(short, orig)
-        short = tuple(shortened(orig, n_head=9, n_tail=1))
+        short = tuple(head_and_tail(orig, n_head=9, n_tail=1))
         self.assertEqual(short, orig)
-        short = tuple(shortened(orig, n_head=1, n_tail=9))
+        short = tuple(head_and_tail(orig, n_head=1, n_tail=9))
         self.assertEqual(short, orig)
-        short = tuple(shortened(orig, n_head=0, n_tail=10))
+        short = tuple(head_and_tail(orig, n_head=0, n_tail=10))
         self.assertEqual(short, orig)
 
         # test shortening with non-indexable iter without len()
@@ -89,7 +89,7 @@ class TextHelpersTester(unittest.TestCase):
             for elem in range(100):
                 yield elem
 
-        short = tuple(shortened(my_iter(), n_elems=100, skip_elem=None))
+        short = tuple(head_and_tail(my_iter(), n_elems=100, skip_elem=None))
         expect = tuple(range(20)) + tuple(range(80,100))
         self.assertEqual(short, expect)