Mercurial > hg
annotate tests/test-annotate.py @ 50425:9fa3cda7449e
heptapod: add `.gitattributes` file to improve language detection
I am fully aware of the irony.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 05 Apr 2023 16:09:08 +0200 |
parents | 6000f5b25c9b |
children |
rev | line source |
---|---|
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
1 import unittest |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
2 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
3 from mercurial import ( |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
4 mdiff, |
37064
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
5 pycompat, |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
6 ) |
36917
7affcabf561e
dagop: move annotateline and _annotatepair from context.py
Yuya Nishihara <yuya@tcha.org>
parents:
35947
diff
changeset
|
7 from mercurial.dagop import ( |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
8 annotateline, |
37064
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
9 _annotatedfile, |
34430
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 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
13 |
37064
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
14 def tr(a): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
15 return [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
16 annotateline(fctx, lineno, skip) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
17 for fctx, lineno, skip in zip(a.fctxs, a.linenos, a.skips) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
18 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
19 |
37064
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
20 |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
21 class AnnotateTests(unittest.TestCase): |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
22 """Unit tests for annotate code.""" |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
23 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
24 def testannotatepair(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
25 self.maxDiff = None # camelcase-required |
34430
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 oldfctx = b'old' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
28 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
|
29 olddata = b'a\nb\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
30 p1data = b'a\nb\nc\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
31 p2data = b'a\nc\nd\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
32 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
|
33 diffopts = mdiff.diffopts() |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
34 |
36935
ec46b0ee2e3c
annotate: correct parameter name of decorate() function
Yuya Nishihara <yuya@tcha.org>
parents:
36917
diff
changeset
|
35 def decorate(text, fctx): |
37064
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
36 n = text.count(b'\n') |
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
37 linenos = pycompat.rangelist(1, n + 1) |
434e520adb8c
annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents:
36935
diff
changeset
|
38 return _annotatedfile([fctx] * n, linenos, [False] * n, text) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
39 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
40 # Basic usage |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
41 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
42 oldann = decorate(olddata, oldfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
43 p1ann = decorate(p1data, p1fctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
45 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
46 tr(p1ann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
47 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
48 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
49 annotateline(b'old', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
50 annotateline(b'p1', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
51 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
52 ) |
34430
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 p2ann = decorate(p2data, p2fctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
55 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
56 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
57 tr(p2ann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
58 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
59 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
60 annotateline(b'p2', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
61 annotateline(b'p2', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
62 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
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 # 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
|
66 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
67 childann = decorate(childdata, childfctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
68 childann = _annotatepair( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
69 [p1ann, p2ann], childfctx, childann, False, diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
70 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
71 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
72 tr(childann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
73 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
74 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
75 annotateline(b'c', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
76 annotateline(b'p2', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
77 annotateline(b'c', 4), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
78 annotateline(b'p2', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
79 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
80 ) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
81 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
82 childann = decorate(childdata, childfctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
83 childann = _annotatepair( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
84 [p2ann, p1ann], childfctx, childann, False, diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
85 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
86 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
87 tr(childann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
88 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
89 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
90 annotateline(b'c', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
91 annotateline(b'p1', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
92 annotateline(b'c', 4), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
93 annotateline(b'p2', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
94 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
95 ) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
96 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
97 # 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
|
98 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
99 childann = decorate(childdata, childfctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
100 childann = _annotatepair( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
101 [p1ann, p2ann], childfctx, childann, True, diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
102 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
103 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
104 tr(childann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
105 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
106 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
107 annotateline(b'old', 2, True), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
108 # note that this line was carried over from earlier so it is *not* |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
109 # marked skipped |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
110 annotateline(b'p2', 2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
111 annotateline(b'p2', 2, True), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
112 annotateline(b'p2', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
113 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
114 ) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
115 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
116 childann = decorate(childdata, childfctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
117 childann = _annotatepair( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
118 [p2ann, p1ann], childfctx, childann, True, diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
119 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
120 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
121 tr(childann), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
122 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
123 annotateline(b'old', 1), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
124 annotateline(b'old', 2, True), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
125 annotateline(b'p1', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
126 annotateline(b'p1', 3, True), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
127 annotateline(b'p2', 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
128 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
129 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
130 |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
131 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
132 if __name__ == '__main__': |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
133 import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37064
diff
changeset
|
134 |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
135 silenttestrunner.main(__name__) |