widgets: flake8 and pylint fixes
[git-cola.git] / test / dag_test.py
blob85df8b502bb56bf1cce6b50de8b1e7243e81b942
1 """Tests DAG functionality"""
2 # pylint: disable=redefined-outer-name
3 from __future__ import absolute_import, division, print_function, unicode_literals
5 import pytest
7 from cola.models import dag
9 from .helper import app_context
10 from .helper import patch
13 assert app_context is not None
16 LOG_LINES = """
17 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
18 1ba04ad185cf9f04c56c8482e9a73ef1bd35c695^Aad454b189fe5785af397fd6067cf103268b6626e^A^ADavid Aguilar^AFri Nov 30 05:07:47 2007 -0800^Adavvid@gmail.com^Aupdated model/view/controller api
19 fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A1ba04ad185cf9f04c56c8482e9a73ef1bd35c695^A^ADavid Aguilar^AFri Nov 30 05:19:05 2007 -0800^Adavvid@gmail.com^AAvoid multiple signoffs
20 103766573cd4e6799d3ee792bcd632b92cf7c6c0^Afa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A^ADavid Aguilar^ATue Dec 11 05:13:21 2007 -0800^Adavvid@gmail.com^AAdded TODO
21 e3f5a2d0248de6197d6e0e63c901810b8a9af2f8^Afa5ad6c38be603e2ffd1f9b722a3a5c675f63de2^A^ADavid Aguilar^AMon Dec 3 02:36:06 2007 -0800^Adavvid@gmail.com^AMerged qlistwidgets into main.
22 f4fb8fd5baaa55d9b41faca79be289bb4407281e^Ae3f5a2d0248de6197d6e0e63c901810b8a9af2f8^A^ADavid Aguilar^ATue Dec 4 03:14:56 2007 -0800^Adavvid@gmail.com^ASquashed commit of the following:
23 23e7eab4ba2c94e3155f5d261c693ccac1342eb9^Af4fb8fd5baaa55d9b41faca79be289bb4407281e^A^ADavid Aguilar^AThu Dec 6 18:59:20 2007 -0800^Adavvid@gmail.com^AMerged diffdisplay into main
24 """.strip().replace( # noqa
25 '^A', chr(0x01)
26 ).split(
27 '\n'
28 ) + [
30 ] # noqa
33 class DAGTestData(object):
34 """Test data provided by the dag_context fixture"""
36 def __init__(self, app_context, head='HEAD', count=1000):
37 self.context = app_context
38 self.params = dag.DAG(head, count)
39 self.reader = dag.RepoReader(app_context, self.params)
42 @pytest.fixture
43 def dag_context(app_context):
44 """Provide DAGTestData for use by tests"""
45 return DAGTestData(app_context)
48 @patch('cola.models.dag.core')
49 def test_repo_reader(core, dag_context):
50 expect = len(LOG_LINES) - 1
52 actual = 0
53 core.readline.return_value = LOG_LINES[0]
54 for idx, _ in enumerate(dag_context.reader.get()):
55 core.readline.return_value = LOG_LINES[idx + 1]
56 actual += 1
58 assert expect == actual
61 @patch('cola.models.dag.core')
62 def test_repo_reader_order(core, dag_context):
63 commits = [
64 'ad454b189fe5785af397fd6067cf103268b6626e',
65 '1ba04ad185cf9f04c56c8482e9a73ef1bd35c695',
66 'fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2',
67 '103766573cd4e6799d3ee792bcd632b92cf7c6c0',
68 'e3f5a2d0248de6197d6e0e63c901810b8a9af2f8',
69 'f4fb8fd5baaa55d9b41faca79be289bb4407281e',
70 '23e7eab4ba2c94e3155f5d261c693ccac1342eb9',
72 core.readline.return_value = LOG_LINES[0]
73 for idx, commit in enumerate(dag_context.reader.get()):
74 assert commits[idx] == commit.oid
75 core.readline.return_value = LOG_LINES[idx + 1]
78 @patch('cola.models.dag.core')
79 def test_repo_reader_parents(core, dag_context):
80 parents = [
81 [],
82 ['ad454b189fe5785af397fd6067cf103268b6626e'],
83 ['1ba04ad185cf9f04c56c8482e9a73ef1bd35c695'],
84 ['fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2'],
85 ['fa5ad6c38be603e2ffd1f9b722a3a5c675f63de2'],
86 ['e3f5a2d0248de6197d6e0e63c901810b8a9af2f8'],
87 ['f4fb8fd5baaa55d9b41faca79be289bb4407281e'],
89 core.readline.return_value = LOG_LINES[0]
90 for idx, commit in enumerate(dag_context.reader.get()):
91 assert parents[idx] == [p.oid for p in commit.parents]
92 core.readline.return_value = LOG_LINES[idx + 1]
95 @patch('cola.models.dag.core')
96 def test_repo_reader_contract(core, dag_context):
97 core.exists.return_value = True
98 core.readline.return_value = LOG_LINES[0]
100 for idx, _ in enumerate(dag_context.reader.get()):
101 core.readline.return_value = LOG_LINES[idx + 1]
103 core.start_command.assert_called()
104 call_args = core.start_command.call_args
106 assert 'log.abbrevCommit=false' in call_args[0][0]
107 assert 'log.showSignature=false' in call_args[0][0]