# HG changeset patch # User Augie Fackler # Date 1503499886 14400 # Node ID 1e71dddc10a24f195a46c4a4d513145ef37f4142 # Parent 6c408bfa2dab260d237b926f717ef78bbbf2af87 drawdag: add a couple of doctests to help with python3 porting diff -r 6c408bfa2dab -r 1e71dddc10a2 tests/drawdag.py --- a/tests/drawdag.py Wed Aug 23 01:24:01 2017 -0400 +++ b/tests/drawdag.py Wed Aug 23 10:51:26 2017 -0400 @@ -110,7 +110,52 @@ 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(br''' + ... 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 @@ v.remove(leaf) def _getcomments(text): + """ + >>> [s for s in _getcomments(br''' + ... 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 -r 6c408bfa2dab -r 1e71dddc10a2 tests/test-doctest.py --- a/tests/test-doctest.py Wed Aug 23 01:24:01 2017 -0400 +++ b/tests/test-doctest.py Wed Aug 23 10:51:26 2017 -0400 @@ -78,3 +78,5 @@ testmod('hgext.convert.p4') testmod('hgext.convert.subversion') testmod('hgext.mq') +# Helper scripts in tests/ that have doctests: +testmod('drawdag')