Commits

Hidetaka Iwata committed 0ea9c6b

graph_test: add tests about graph topology

tests about follow/start_rev/stop_rev options are not included
because these options are unused and will be removed soon.

Comments (0)

Files changed (1)

tests/graph_test.py

     setup_straightenedbyrevset()
     setup_bulkgraft()
     setup_commonedge()
+    setup_manyheads()
 
 def openrepo(name):
     return hg.repository(ui.ui(), os.path.join(_tmpdir, name))
 def buildlinecolortable(grapher):
     return buildlinetable(grapher, lambda p, e: e.color)
 
+def buildlinecolumntable(grapher):
+    linktypetags = {
+        graph.LINE_TYPE_PARENT: '',
+        graph.LINE_TYPE_GRAFT: 'G',
+        graph.LINE_TYPE_OBSOLETE: 'O',
+    }
+    def predicate(p, e):
+        return '%d-%d%s' % (p[0], p[1], linktypetags[e.linktype])
+    return buildlinetable(grapher, predicate)
+
 def setup_namedbranch():
     buildrepo('named-branch', r"""
         8
         0: [],
         }
     assert_equal(expectedtable, actualtable)
+
+def setup_manyheads():
+    buildrepo('manyheads', r"""
+    7
+    |\  6
+    | |/
+    | 5 [branch=foo]
+    |/| 4 [branch=foo]
+    3 |/
+    | 2
+    |/
+    1
+    0
+    """)
+
+def test_grapher_noopt():
+    repo = openrepo('manyheads')
+    grapher = graph.revision_grapher(repo, {})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                        # wt
+        None : ['0-0'],                 # |
+                                        # 7
+        7 : ['0-0', '0-1'],             # |\
+                                        # | | 6
+        6 : ['0-0', '1-1', '2-1'],      # | |/
+                                        # | 5
+        5 : ['0-0', '1-0', '1-1'],      # |/|
+                                        # | | 4
+        4 : ['0-0', '1-1', '2-1'],      # | |/
+                                        # 3 |
+        3 : ['0-0', '1-1'],             # | |
+                                        # | 2
+        2 : ['0-0', '1-0'],             # |/
+                                        # 1
+        1 : ['0-0'],                    # |
+                                        # 0
+        0 : [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_branch_1():
+    repo = openrepo('manyheads')
+    grapher = graph.revision_grapher(repo, {'branch': 'default'})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                # wt
+        None: ['0-0'],          # |
+                                # 7
+        7: ['0-0'],             # |
+                                # 3
+        3: ['0-0'],             # |
+                                # | 2
+        2: ['0-0', '1-0'],      # |/
+                                # 1
+        1: ['0-0'],             # |
+                                # 0
+        0: [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_branch_2():
+    repo = openrepo('manyheads')
+    grapher = graph.revision_grapher(repo, {'branch': 'foo'})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                        # 6
+        6 :['0-0'],     # |
+                        # 5
+        5 :[],          #
+                        # 4
+        4 :[],          #
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_branch_allparents_1():
+    repo = openrepo('manyheads')
+    grapher = graph.revision_grapher(
+            repo, {'branch': 'default', 'allparents': True})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                     # wt
+        None: ['0-0'],               # |
+                                     # 7
+        7: ['0-0', '0-1'],           # |\
+                                     # | 5
+        5: ['0-0', '1-0', '1-1'],    # |/|
+                                     # 3 |
+        3: ['0-0', '1-1'],           # | |
+                                     # | 2
+        2: ['0-0', '1-0'],           # |/
+                                     # 1
+        1: ['0-0'],                  # |
+                                     # 0
+        0: [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_branch_allparents_2():
+    repo = openrepo('manyheads')
+    grapher = graph.revision_grapher(
+            repo, {'branch': 'foo', 'allparents': True})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                     # 6
+        6: ['0-0'],                  # |
+                                     # 5
+        5: ['0-0', '0-1'],           # |\
+                                     # +---4
+        4: ['0-0', '1-1', '2-0'],    # | |
+                                     # | 3
+        3: ['0-0', '1-1'],           # | |
+                                     # 2 |
+        2: ['0-0', '1-0'],           # |/
+                                     # 1
+        1: ['0-0'],                  # |
+                                     # 0
+        0: [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_revset_1():
+    repo = openrepo('manyheads')
+    revset = set([7, 6, 5, 4, 3])
+    grapher = graph.revision_grapher(repo, {'revset': revset})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                    # 7
+        7: ['0-0', '0-1'],          # |\
+                                    # | | 6
+        6: ['0-0', '1-1', '2-1'],   # | |/
+                                    # | 5
+        5: ['0-0', '1-0'],          # |/
+                                    # | 4
+        4: ['0-0'],                 # |
+                                    # 3
+        3: [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_revset_2():
+    repo = openrepo('manyheads')
+    revset = set([5, 4, 3, 2, 1])
+    grapher = graph.revision_grapher(repo, {'revset': revset})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                    # 5
+        5: ['0-0', '0-1'],          # |\
+                                    # +---4
+        4: ['0-0', '1-1', '2-0'],   # | |
+                                    # | 3
+        3: ['0-0', '1-1'],          # | |
+                                    # 2 |
+        2: ['0-0', '1-0'],          # |/
+                                    # 1
+        1: [],
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_revset_3():
+    repo = openrepo('manyheads')
+    revset = set([7, 5, 3])
+    grapher = graph.revision_grapher(repo, {'revset': revset})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                    # 7
+        7: ['0-0', '0-1'],          # |\
+                                    # | 5
+        5: ['0-0', '1-0'],          # |/
+                                    # 3
+        3: [],                      #
+        }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_showgraftsource():
+    repo = openrepo('bulkgraft')
+    grapher = graph.revision_grapher(repo, {"showgraftsource": True})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                                            # wt
+        None: ['0-0'],                      # |
+                                            # 7
+        7: ['0-0', '0-1G'],                 # |\
+                                            # 6 .
+        6: ['0-0', '0-1G', '1-2G'],         # |\ \
+                                            # 5 . .
+        5: ['0-0', '0-1G', '1-2G', '2-3G'], # |\ \ \
+                                            # 4 : : :
+        4: ['0-0', '1-1G', '2-2G', '3-3G'], # | : : :
+                                            # | : : 3
+        3: ['0-0', '1-1G', '2-2G', '3-2'],  # | : :/
+                                            # | : 2
+        2: ['0-0', '1-1G', '2-1'],          # | :/
+                                            # | 1
+        1: ['0-0', '1-0'],                  # |/
+                                            # 0
+        0: [],
+    }
+    assert_equal(expectedtable, actualtable)
+
+def test_grapher_hidegraftsource():
+    repo = openrepo('bulkgraft')
+    grapher = graph.revision_grapher(repo, {})
+    actualtable = buildlinecolumntable(grapher)
+    expectedtable = {
+                            # wt
+        None: ['0-0'],      # |
+                            # 7
+        7: ['0-0'],         # |
+                            # 6
+        6: ['0-0'],         # |
+                            # 5
+        5: ['0-0'],         # |
+                            # 4
+        4: ['0-0'],         # |
+                            # | 3
+        3: ['0-0', '1-1'],  # | |
+                            # | 2
+        2: ['0-0', '1-1'],  # | |
+                            # | 1
+        1: ['0-0', '1-0'],  # |/
+                            # 0
+        0: [],
+    }
+    assert_equal(expectedtable, actualtable)