submodules: address pylint warnings
[git-cola.git] / test / dag_test.py
blobc517964794ec41748c480ee0475b57c9f7e2dfff
1 #!/usr/bin/env python
2 """Tests DAG functionality"""
3 from __future__ import absolute_import, division, unicode_literals
5 import mock
6 from cola.models import dag
8 from . import helper
11 LOG_LINES = """
12 ad454b189fe5785af397fd6067cf103268b6626e^A^A (tag: refs/tags/v0.0)^ADavid Aguilar^AFri Nov 30 00:03:28 2007 -0800^Adavvid@gmail.com^Afirst cut of ugit
13 1ba04ad185cf9f04c56c8482e9a73ef1bd35c695^Aad454b189fe5785af397fd6067cf103268b6626e^A^ADavid Aguilar^AFri Nov 30 05:07:47 2007 -0800^Adavvid@gmail.com^Aupdated model/view/controller api
14 fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A1ba04ad185cf9f04c56c8482e9a73ef1bd35c695^A^ADavid Aguilar^AFri Nov 30 05:19:05 2007 -0800^Adavvid@gmail.com^AAvoid multiple signoffs
15 103766573cd4e6799d3ee792bcd632b92cf7c6c0^Afa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A^ADavid Aguilar^ATue Dec 11 05:13:21 2007 -0800^Adavvid@gmail.com^AAdded TODO
16 e3f5a2d0248de6197d6e0e63c901810b8a9af2f8^Afa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A^ADavid Aguilar^AMon Dec 3 02:36:06 2007 -0800^Adavvid@gmail.com^AMerged qlistwidgets into main.
17 f4fb8fd5baaa55d9b41faca79be289bb4407281e^Ae3f5a2d0248de6197d6e0e63c901810b8a9af2f8^A^ADavid Aguilar^ATue Dec 4 03:14:56 2007 -0800^Adavvid@gmail.com^ASquashed commit of the following:
18 23e7eab4ba2c94e3155f5d261c693ccac1342eb9^Af4fb8fd5baaa55d9b41faca79be289bb4407281e^A^ADavid Aguilar^AThu Dec 6 18:59:20 2007 -0800^Adavvid@gmail.com^AMerged diffdisplay into main
19 """.strip().replace( # noqa
20 '^A', chr(0x01)
21 ).split(
22 '\n'
23 ) + [
25 ] # noqa
28 class DAGTestCase(helper.GitRepositoryTestCase):
29 def setUp(self):
30 helper.GitRepositoryTestCase.setUp(self)
31 self.params = dag.DAG('HEAD', 1000)
32 self.reader = dag.RepoReader(self.context, self.params)
34 @mock.patch('cola.models.dag.core')
35 def test_repo_reader(self, core):
36 expect = len(LOG_LINES) - 1
37 actual = 0
39 core.readline.return_value = LOG_LINES[0]
40 for idx, _ in enumerate(self.reader.get()):
41 core.readline.return_value = LOG_LINES[idx + 1]
42 actual += 1
44 self.assertEqual(expect, actual)
46 @mock.patch('cola.models.dag.core')
47 def test_repo_reader_order(self, core):
48 commits = [
49 'ad454b189fe5785af397fd6067cf103268b6626e',
50 '1ba04ad185cf9f04c56c8482e9a73ef1bd35c695',
51 'fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2',
52 '103766573cd4e6799d3ee792bcd632b92cf7c6c0',
53 'e3f5a2d0248de6197d6e0e63c901810b8a9af2f8',
54 'f4fb8fd5baaa55d9b41faca79be289bb4407281e',
55 '23e7eab4ba2c94e3155f5d261c693ccac1342eb9',
57 core.readline.return_value = LOG_LINES[0]
58 for idx, commit in enumerate(self.reader.get()):
59 core.readline.return_value = LOG_LINES[idx + 1]
61 self.assertEqual(commits[idx], commit.oid)
63 @mock.patch('cola.models.dag.core')
64 def test_repo_reader_parents(self, core):
65 parents = [
66 [],
67 ['ad454b189fe5785af397fd6067cf103268b6626e'],
68 ['1ba04ad185cf9f04c56c8482e9a73ef1bd35c695'],
69 ['fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2'],
70 ['fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2'],
71 ['e3f5a2d0248de6197d6e0e63c901810b8a9af2f8'],
72 ['f4fb8fd5baaa55d9b41faca79be289bb4407281e'],
74 core.readline.return_value = LOG_LINES[0]
75 for idx, commit in enumerate(self.reader.get()):
76 core.readline.return_value = LOG_LINES[idx + 1]
78 self.assertEqual(parents[idx], [p.oid for p in commit.parents])
80 @mock.patch('cola.models.dag.core')
81 def test_repo_reader_contract(self, core):
82 core.exists.return_value = True
83 core.readline.return_value = LOG_LINES[0]
85 for idx, _ in enumerate(self.reader.get()):
86 core.readline.return_value = LOG_LINES[idx + 1]
88 core.start_command.assert_called()
89 call_args = core.start_command.call_args
90 self.assertTrue('log.abbrevCommit=false' in call_args[0][0])
91 self.assertTrue('log.showSignature=false' in call_args[0][0])