annotate tests/test-annotate.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
children 2e32c6a31cc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
1 from __future__ import absolute_import
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
2 from __future__ import print_function
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
3
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
4 import unittest
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
5
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
6 from mercurial import (
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
7 mdiff,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
8 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
9 from mercurial.context import (
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
10 _annotatepair,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
11 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
12
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
13 class AnnotateTests(unittest.TestCase):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
14 """Unit tests for annotate code."""
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
15
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
16 def testannotatepair(self):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
17 self.maxDiff = None # camelcase-required
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
18
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
19 oldfctx = b'old'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
20 p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
21 olddata = b'a\nb\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
22 p1data = b'a\nb\nc\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
23 p2data = b'a\nc\nd\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
24 childdata = b'a\nb2\nc\nc2\nd\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
25 diffopts = mdiff.diffopts()
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
26
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
27 def decorate(text, rev):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
28 return ([(rev, i) for i in xrange(1, text.count(b'\n') + 1)], text)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
29
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
30 # Basic usage
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
31
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
32 oldann = decorate(olddata, oldfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
33 p1ann = decorate(p1data, p1fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
34 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
35 self.assertEqual(p1ann[0], [('old', 1), ('old', 2), ('p1', 3)])
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
36
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
37 p2ann = decorate(p2data, p2fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
38 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
39 self.assertEqual(p2ann[0], [('old', 1), ('p2', 2), ('p2', 3)])
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
40
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
41 # Test with multiple parents (note the difference caused by ordering)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
42
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
43 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
44 childann = _annotatepair([p1ann, p2ann], childfctx, childann, False,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
45 diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
46 self.assertEqual(childann[0],
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
47 [('old', 1), ('c', 2), ('p2', 2), ('c', 4), ('p2', 3)]
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
48 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
49
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
50 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
51 childann = _annotatepair([p2ann, p1ann], childfctx, childann, False,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
52 diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
53 self.assertEqual(childann[0],
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
54 [('old', 1), ('c', 2), ('p1', 3), ('c', 4), ('p2', 3)]
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
55 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
56
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
57 # Test with skipchild (note the difference caused by ordering)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
58
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
59 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
60 childann = _annotatepair([p1ann, p2ann], childfctx, childann, True,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
61 diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
62 self.assertEqual(childann[0],
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
63 [('old', 1), ('old', 2), ('p2', 2), ('p2', 2), ('p2', 3)]
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
64 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
65
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
66 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
67 childann = _annotatepair([p2ann, p1ann], childfctx, childann, True,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
68 diffopts)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
69 self.assertEqual(childann[0],
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
70 [('old', 1), ('old', 2), ('p1', 3), ('p1', 3), ('p2', 3)]
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
71 )
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
72
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
73 if __name__ == '__main__':
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
74 import silenttestrunner
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
75 silenttestrunner.main(__name__)