From a9ad147eb566a548fdca1055388dfa1f87cd4b2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Hu=C5=A1ek?= <husek@iuuk.mff.cuni.cz>
Date: Sat, 22 Jul 2017 20:26:24 +0200
Subject: [PATCH] parmap.py: add doctests

---
 parmap.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/parmap.py b/parmap.py
index f5ae309..8637460 100644
--- a/parmap.py
+++ b/parmap.py
@@ -6,7 +6,15 @@ import multiprocessing
 from itertools import chain
 
 def chunkme(X, chunksize):
-  """Return items generated by X in chunks (lists) of size chunksize."""
+  """Return items generated by X in chunks (lists) of size chunksize.
+
+  EXAMPLE:
+
+  >>> list(chunkme(range(20), 7))
+  [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19]]
+  >>> list(chunkme(range(0), 2))
+  []
+  """
   chunk = []
   for x in X:
     chunk.append(x)
@@ -62,6 +70,11 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
     in_order -- if True, input sequence may be reordered during processing
     multimap -- if True, f is expected to return an Iterable and flattening is done
     out_chunksize -- size of chunks send from workers to consumer
+
+    EXAMPLES:
+
+    >>> list(parmap(lambda x: x+1, range(10)))
+    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     """
     if nprocs is None:
       nprocs = multiprocessing.cpu_count()
@@ -127,3 +140,11 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
 
     return chain.from_iterable(get_chunk())
 
+
+if __name__ == "__main__":
+  import doctest
+  (f, t) = doctest.testmod()
+  print "%s: %i tests of %i failed." % (__file__, f, t)
+  if f > 0:
+    exit(1)
+
-- 
GitLab