Patchwork [7,of,8,py3] drawdag: add a couple of doctests to help with python3 porting

login
register
mail settings
Submitter Augie Fackler
Date Sept. 15, 2017, 11:14 p.m.
Message ID <962f6b24541c419fc135.1505517250@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/23927/
State Accepted
Headers show

Comments

Augie Fackler - Sept. 15, 2017, 11:14 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1503499886 14400
#      Wed Aug 23 10:51:26 2017 -0400
# Node ID 962f6b24541c419fc135ebd75de8529344d85d31
# Parent  6780213e5a48edeef40d6fa24ef5cb939de8abdc
drawdag: add a couple of doctests to help with python3 porting

Patch

diff --git a/tests/drawdag.py b/tests/drawdag.py
--- a/tests/drawdag.py
+++ b/tests/drawdag.py
@@ -110,7 +110,52 @@  def _isname(ch):
     return ch in _nonpipechars
 
 def _parseasciigraph(text):
-    """str -> {str : [str]}. convert the ASCII graph to edges"""
+    r"""str -> {str : [str]}. convert the ASCII graph to edges
+
+    >>> import pprint
+    >>> pprint.pprint({k: [vv for vv in v]
+    ...  for k, v in _parseasciigraph(b'''
+    ...        G
+    ...        |
+    ...  I D C F   # split: B -> E, F, G
+    ...   \ \| |   # replace: C -> D -> H
+    ...    H B E   # prune: F, I
+    ...     \|/
+    ...      A
+    ... ''').items()})
+    {'A': [],
+     'B': ['A'],
+     'C': ['B'],
+     'D': ['B'],
+     'E': ['A'],
+     'F': ['E'],
+     'G': ['F'],
+     'H': ['A'],
+     'I': ['H']}
+    >>> pprint.pprint({k: [vv for vv in v]
+    ...  for k, v in _parseasciigraph(br'''
+    ...  o    foo
+    ...  |\
+    ...  +---o  bar
+    ...  | | |
+    ...  | o |  baz
+    ...  |  /
+    ...  +---o  d
+    ...  | |
+    ...  +---o  c
+    ...  | |
+    ...  o |  b
+    ...  |/
+    ...  o  a
+    ... ''').items()})
+    {'a': [],
+     'b': ['a'],
+     'bar': ['b', 'a'],
+     'baz': [],
+     'c': ['b'],
+     'd': ['b'],
+     'foo': ['baz', 'b']}
+    """
     lines = text.splitlines()
     edges = collections.defaultdict(list)  # {node: []}
 
@@ -277,6 +322,18 @@  def _walkgraph(edges):
                     v.remove(leaf)
 
 def _getcomments(text):
+    """
+    >>> [s for s in _getcomments(b'''
+    ...        G
+    ...        |
+    ...  I D C F   # split: B -> E, F, G
+    ...   \ \| |   # replace: C -> D -> H
+    ...    H B E   # prune: F, I
+    ...     \|/
+    ...      A
+    ... ''')]
+    ['split: B -> E, F, G', 'replace: C -> D -> H', 'prune: F, I']
+    """
     for line in text.splitlines():
         if ' # ' not in line:
             continue
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -78,3 +78,5 @@  testmod('hgext.convert.filemap')
 testmod('hgext.convert.p4')
 testmod('hgext.convert.subversion')
 testmod('hgext.mq')
+# Helper scripts in tests/ that have doctests:
+testmod('drawdag')