annotate tests/test-annotate.py @ 36265:b44fac3a49fb

py3: factor out byterepr() which returns an asciified value on py3
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Feb 2018 18:09:56 +0900
parents a36d3c8a0e41
children 7affcabf561e
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 (
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
10 annotateline,
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
11 _annotatepair,
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
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
14 class AnnotateTests(unittest.TestCase):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
15 """Unit tests for annotate code."""
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
16
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
17 def testannotatepair(self):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
18 self.maxDiff = None # camelcase-required
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
19
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
20 oldfctx = b'old'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
21 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
22 olddata = b'a\nb\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
23 p1data = b'a\nb\nc\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
24 p2data = b'a\nc\nd\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
25 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
26 diffopts = mdiff.diffopts()
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
27
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
28 def decorate(text, rev):
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
29 return ([annotateline(fctx=rev, lineno=i)
35946
cf887d601014 py3: use range instead of xrange
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34433
diff changeset
30 for i in range(1, text.count(b'\n') + 1)],
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
31 text)
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
32
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
33 # Basic usage
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
34
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
35 oldann = decorate(olddata, oldfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
36 p1ann = decorate(p1data, p1fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
37 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
38 self.assertEqual(p1ann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
39 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
40 annotateline(b'old', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
41 annotateline(b'p1', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
42 ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
43
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
44 p2ann = decorate(p2data, p2fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
45 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
46 self.assertEqual(p2ann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
47 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
48 annotateline(b'p2', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
49 annotateline(b'p2', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
50 ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
51
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
52 # 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
53
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
54 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
55 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
56 diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
57 self.assertEqual(childann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
58 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
59 annotateline(b'c', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
60 annotateline(b'p2', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
61 annotateline(b'c', 4),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
62 annotateline(b'p2', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
63 ])
34430
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 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
66 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
67 diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
68 self.assertEqual(childann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
69 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
70 annotateline(b'c', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
71 annotateline(b'p1', 3),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
72 annotateline(b'c', 4),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
73 annotateline(b'p2', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
74 ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
75
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
76 # 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
77
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
78 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
79 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
80 diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
81 self.assertEqual(childann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
82 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
83 annotateline(b'old', 2, True),
34433
2f5a135b2b04 annotate: track whether a particular annotation was the result of a skip
Siddharth Agarwal <sid0@fb.com>
parents: 34432
diff changeset
84 # note that this line was carried over from earlier so it is *not*
2f5a135b2b04 annotate: track whether a particular annotation was the result of a skip
Siddharth Agarwal <sid0@fb.com>
parents: 34432
diff changeset
85 # marked skipped
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
86 annotateline(b'p2', 2),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
87 annotateline(b'p2', 2, True),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
88 annotateline(b'p2', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
89 ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
90
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
91 childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
92 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
93 diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
94 self.assertEqual(childann[0], [
35947
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
95 annotateline(b'old', 1),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
96 annotateline(b'old', 2, True),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
97 annotateline(b'p1', 3),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
98 annotateline(b'p1', 3, True),
a36d3c8a0e41 py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35946
diff changeset
99 annotateline(b'p2', 3),
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
100 ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
101
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
102 if __name__ == '__main__':
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
103 import silenttestrunner
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
104 silenttestrunner.main(__name__)