Show More
@@ -1,77 +1,85 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2017 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | from rhodecode.lib import graphmod |
|
21 | from rhodecode.lib import graphmod | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | # pylint: disable=protected-access |
|
24 | # pylint: disable=protected-access | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | def test_get_edge_color_multiple_parents(): |
|
27 | def test_get_edge_color_multiple_parents(): | |
28 | node_color = 1 |
|
28 | node_color = 1 | |
29 | parent_color = 2 |
|
29 | parent_color = 2 | |
30 | assert graphmod._get_edge_color( |
|
30 | assert graphmod._get_edge_color( | |
31 | 'parent', 2, node_color, {'parent': parent_color}) == parent_color |
|
31 | 'parent', 2, node_color, {'parent': parent_color}) == parent_color | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | def test_get_edge_color_multiple_unknown_parent(): |
|
34 | def test_get_edge_color_multiple_unknown_parent(): | |
35 | node_color = 1 |
|
35 | node_color = 1 | |
36 | assert graphmod._get_edge_color('parent', 2, node_color, {}) == node_color |
|
36 | assert graphmod._get_edge_color('parent', 2, node_color, {}) == node_color | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | def test_get_edge_color_single_parent(): |
|
39 | def test_get_edge_color_single_parent(): | |
40 | node_color = 1 |
|
40 | node_color = 1 | |
41 | assert graphmod._get_edge_color('parent', 1, node_color, {}) == node_color |
|
41 | assert graphmod._get_edge_color('parent', 1, node_color, {}) == node_color | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def test_colored_linear(): |
|
44 | def test_colored_linear(): | |
45 | dag = [('node3', ['node2']), ('node2', ['node1']), ('node1', [])] |
|
45 | dag = [ | |
|
46 | ('hash', 'node3', ['node2'], 'master'), | |||
|
47 | ('hash', 'node2', ['node1'], 'master'), | |||
|
48 | ('hash', 'node1', [], 'master') | |||
|
49 | ] | |||
46 | expected_result = [ |
|
50 | expected_result = [ | |
47 | ((0, 1), [(0, 0, 1)]), |
|
51 | ('hash', (0, 1), [(0, 0, 1)], 'master'), | |
48 | ((0, 1), [(0, 0, 1)]), |
|
52 | ('hash', (0, 1), [(0, 0, 1)], 'master'), | |
49 | ((0, 1), []), |
|
53 | ('hash', (0, 1), [], 'master'), | |
50 | ] |
|
54 | ] | |
51 | assert list(graphmod._colored(dag)) == expected_result |
|
55 | assert list(graphmod._colored(dag)) == expected_result | |
52 |
|
56 | |||
53 |
|
57 | |||
54 | def test_colored_diverging_branch(): |
|
58 | def test_colored_diverging_branch(): | |
55 | dag = [('node3', ['node1']), ('node2', ['node1']), ('node1', [])] |
|
59 | dag = [ | |
|
60 | ('hash', 'node3', ['node1'], 'stable'), | |||
|
61 | ('hash', 'node2', ['node1'], 'stable'), | |||
|
62 | ('hash', 'node1', [], 'stable') | |||
|
63 | ] | |||
56 | expected_result = [ |
|
64 | expected_result = [ | |
57 | ((0, 1), [(0, 0, 1)]), |
|
65 | ('hash', (0, 1), [(0, 0, 1)], 'stable'), | |
58 | ((1, 2), [(0, 0, 1), (1, 0, 2)]), |
|
66 | ('hash', (1, 2), [(0, 0, 1), (1, 0, 2)], 'stable'), | |
59 | ((0, 1), []), |
|
67 | ('hash', (0, 1), [], 'stable'), | |
60 | ] |
|
68 | ] | |
61 | assert list(graphmod._colored(dag)) == expected_result |
|
69 | assert list(graphmod._colored(dag)) == expected_result | |
62 |
|
70 | |||
63 |
|
71 | |||
64 | def test_colored_merged_branch(): |
|
72 | def test_colored_merged_branch(): | |
65 | dag = [ |
|
73 | dag = [ | |
66 | ('node4', ['node2', 'node3']), |
|
74 | ('hash', 'node4', ['node2', 'node3'], 'stable'), | |
67 | ('node3', ['node1']), |
|
75 | ('hash', 'node3', ['node1'], 'stable'), | |
68 | ('node2', ['node1']), |
|
76 | ('hash', 'node2', ['node1'], 'stable'), | |
69 | ('node1', []), |
|
77 | ('hash', 'node1', [], 'stable'), | |
70 | ] |
|
78 | ] | |
71 | expected_result = [ |
|
79 | expected_result = [ | |
72 | ((0, 1), [(0, 0, 1), (0, 1, 2)]), |
|
80 | ('hash', (0, 1), [(0, 0, 1), (0, 1, 2)], 'stable'), | |
73 | ((1, 2), [(0, 0, 1), (1, 1, 2)]), |
|
81 | ('hash', (1, 2), [(0, 0, 1), (1, 1, 2)], 'stable'), | |
74 | ((0, 1), [(0, 0, 1), (1, 0, 2)]), |
|
82 | ('hash', (0, 1), [(0, 0, 1), (1, 0, 2)], 'stable'), | |
75 | ((0, 2), []), |
|
83 | ('hash', (0, 2), [], 'stable'), | |
76 | ] |
|
84 | ] | |
77 | assert list(graphmod._colored(dag)) == expected_result |
|
85 | assert list(graphmod._colored(dag)) == expected_result |
General Comments 0
You need to be logged in to leave comments.
Login now