comparison mercurial/context.py @ 34430:80215865d154

annotate: move annotatepair unit tests to a separate file In upcoming patches the output is going to be significantly longer than it is today, and doctests don't allow wrapping the output. Differential Revision: https://phab.mercurial-scm.org/D896
author Siddharth Agarwal <sid0@fb.com>
date Mon, 02 Oct 2017 02:34:47 -0700
parents ac0cd81e2f83
children 52e9310626a8
comparison
equal deleted inserted replaced
34429:b332c01247d8 34430:80215865d154
1110 data. 1110 data.
1111 1111
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]
1168 1119
1169 if skipchild: 1120 if skipchild: