##// END OF EJS Templates
annotate: move annotatepair unit tests to a separate file...
Siddharth Agarwal -
r34431:80215865 default
parent child Browse files
Show More
@@ -0,0 +1,75 b''
1 from __future__ import absolute_import
2 from __future__ import print_function
3
4 import unittest
5
6 from mercurial import (
7 mdiff,
8 )
9 from mercurial.context import (
10 _annotatepair,
11 )
12
13 class AnnotateTests(unittest.TestCase):
14 """Unit tests for annotate code."""
15
16 def testannotatepair(self):
17 self.maxDiff = None # camelcase-required
18
19 oldfctx = b'old'
20 p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
21 olddata = b'a\nb\n'
22 p1data = b'a\nb\nc\n'
23 p2data = b'a\nc\nd\n'
24 childdata = b'a\nb2\nc\nc2\nd\n'
25 diffopts = mdiff.diffopts()
26
27 def decorate(text, rev):
28 return ([(rev, i) for i in xrange(1, text.count(b'\n') + 1)], text)
29
30 # Basic usage
31
32 oldann = decorate(olddata, oldfctx)
33 p1ann = decorate(p1data, p1fctx)
34 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
35 self.assertEqual(p1ann[0], [('old', 1), ('old', 2), ('p1', 3)])
36
37 p2ann = decorate(p2data, p2fctx)
38 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
39 self.assertEqual(p2ann[0], [('old', 1), ('p2', 2), ('p2', 3)])
40
41 # Test with multiple parents (note the difference caused by ordering)
42
43 childann = decorate(childdata, childfctx)
44 childann = _annotatepair([p1ann, p2ann], childfctx, childann, False,
45 diffopts)
46 self.assertEqual(childann[0],
47 [('old', 1), ('c', 2), ('p2', 2), ('c', 4), ('p2', 3)]
48 )
49
50 childann = decorate(childdata, childfctx)
51 childann = _annotatepair([p2ann, p1ann], childfctx, childann, False,
52 diffopts)
53 self.assertEqual(childann[0],
54 [('old', 1), ('c', 2), ('p1', 3), ('c', 4), ('p2', 3)]
55 )
56
57 # Test with skipchild (note the difference caused by ordering)
58
59 childann = decorate(childdata, childfctx)
60 childann = _annotatepair([p1ann, p2ann], childfctx, childann, True,
61 diffopts)
62 self.assertEqual(childann[0],
63 [('old', 1), ('old', 2), ('p2', 2), ('p2', 2), ('p2', 3)]
64 )
65
66 childann = decorate(childdata, childfctx)
67 childann = _annotatepair([p2ann, p1ann], childfctx, childann, True,
68 diffopts)
69 self.assertEqual(childann[0],
70 [('old', 1), ('old', 2), ('p1', 3), ('p1', 3), ('p2', 3)]
71 )
72
73 if __name__ == '__main__':
74 import silenttestrunner
75 silenttestrunner.main(__name__)
@@ -1112,56 +1112,7 b' def _annotatepair(parents, childfctx, ch'
1112 Additionally, if `skipchild` is True, replace all other lines with parent
1112 Additionally, if `skipchild` is True, replace all other lines with parent
1113 annotate data as well such that child is never blamed for any lines.
1113 annotate data as well such that child is never blamed for any lines.
1114
1114
1115 >>> oldfctx = b'old'
1115 See test-annotate.py for unit tests.
1116 >>> p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
1117 >>> olddata = b'a\nb\n'
1118 >>> p1data = b'a\nb\nc\n'
1119 >>> p2data = b'a\nc\nd\n'
1120 >>> childdata = b'a\nb2\nc\nc2\nd\n'
1121 >>> diffopts = mdiff.diffopts()
1122
1123 >>> def decorate(text, rev):
1124 ... return ([(rev, i) for i in xrange(1, text.count(b'\n') + 1)], text)
1125
1126 Basic usage:
1127
1128 >>> oldann = decorate(olddata, oldfctx)
1129 >>> p1ann = decorate(p1data, p1fctx)
1130 >>> p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
1131 >>> p1ann[0]
1132 [('old', 1), ('old', 2), ('p1', 3)]
1133 >>> p2ann = decorate(p2data, p2fctx)
1134 >>> p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
1135 >>> p2ann[0]
1136 [('old', 1), ('p2', 2), ('p2', 3)]
1137
1138 Test with multiple parents (note the difference caused by ordering):
1139
1140 >>> childann = decorate(childdata, childfctx)
1141 >>> childann = _annotatepair([p1ann, p2ann], childfctx, childann, False,
1142 ... diffopts)
1143 >>> childann[0]
1144 [('old', 1), ('c', 2), ('p2', 2), ('c', 4), ('p2', 3)]
1145
1146 >>> childann = decorate(childdata, childfctx)
1147 >>> childann = _annotatepair([p2ann, p1ann], childfctx, childann, False,
1148 ... diffopts)
1149 >>> childann[0]
1150 [('old', 1), ('c', 2), ('p1', 3), ('c', 4), ('p2', 3)]
1151
1152 Test with skipchild (note the difference caused by ordering):
1153
1154 >>> childann = decorate(childdata, childfctx)
1155 >>> childann = _annotatepair([p1ann, p2ann], childfctx, childann, True,
1156 ... diffopts)
1157 >>> childann[0]
1158 [('old', 1), ('old', 2), ('p2', 2), ('p2', 2), ('p2', 3)]
1159
1160 >>> childann = decorate(childdata, childfctx)
1161 >>> childann = _annotatepair([p2ann, p1ann], childfctx, childann, True,
1162 ... diffopts)
1163 >>> childann[0]
1164 [('old', 1), ('old', 2), ('p1', 3), ('p1', 3), ('p2', 3)]
1165 '''
1116 '''
1166 pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts))
1117 pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts))
1167 for parent in parents]
1118 for parent in parents]
General Comments 0
You need to be logged in to leave comments. Login now