Mercurial > hg
annotate tests/test-bdiff.py @ 43198:c16fe77e340a
pathcopies: give up any optimization based on `introrev`
Between 8a0136f69027 and d98fb3f42f33, we sped up the search for the
introduction revision during path copies. However, further checking show that
finding the introduction revision is still expensive and that we are better off
without it. So we simply drop it and only rely on the linkrev optimisation.
I ran `perfpathcopies` on 6989 pair of revision in the pypy
repository (`hg perfhelper-pathcopies`. The result is massively in favor of
dropping this condition. The result of the copy tracing are unchanged.
Attempt to use a smaller changes preserving linkrev usage were unsuccessful, it
can return wrong result. The following changesets broke test-mv-cp-st-diff.t
- if not f.isintroducedafter(limit):
+ if limit >= 0 and f.linkrev() < limit:
return None
Here are various numbers (before this changeset/after this changesets)
source destination before after saved-time ratio
worth cases e66f24650daf 695dfb0f493b 1.062843 1.246369 -0.183526 1.172675
c979853a3b6a 8d60fe293e79 1.036985 1.196414 -0.159429 1.153743
22349fa2fc33 fbb1c9fd86c0 0.879926 1.038682 -0.158756 1.180420
682b98f3e672 a4878080a536 0.909952 1.063801 -0.153849 1.169074
5adabc9b9848 920958a93997 0.993622 1.147452 -0.153830 1.154817
worse 1% dbfbfcf077e9 aea8f2fd3593 1.016595 1.082999 -0.066404 1.065320
worse 5% c95f1ced15f2 7d29d5e39734 0.453694 0.471156 -0.017462 1.038488
worse 10% 3e144ed1d5b7 2aef0e942480 0.035140 0.037535 -0.002395 1.068156
worse 25% 321fc60db035 801748ba582a 0.009267 0.009325 -0.000058 1.006259
median 2088ce763fc2 e6991321d78b 0.000665 0.000651 0.000014 0.978947
best 25% 915631a97de6 385b31354be6 0.040743 0.040363 0.000380 0.990673
best 10% ad495c36a765 19c10384d3e7 0.431658 0.411490 0.020168 0.953278
best 5% d13ae7d283ae 813c99f810ac 1.141404 1.075346 0.066058 0.942126
best 1% 81593cb4a496 99ae11866969 1.833297 0.063823 1.769474 0.034813
best cases c3b14617fbd7 743a0fcaa4eb 1101.811740 2.735970 1099.075770 0.002483
c3b14617fbd7 9ba6ab77fd29 1116.753953 2.800729 1113.953224 0.002508
058b99d6e81f 57e249b7a3ea 1246.128485 3.042762 1243.085723 0.002442
9a8c361aab49 0354a250d371 1253.111894 3.085796 1250.026098 0.002463
442dbbc53c68 3ec1002a818c 1261.786294 3.138607 1258.647687 0.002487
As one can see, the average case is not really impacted. However, the worth case
we get after this changeset are much better than the one we had before it. We
have 30 pairs where improvements are above 10 minutes.
This reflect in the combined time for all pairs
before: 26256s
after: 1300s (-95%)
If we remove these pathological 30 cases, we still see a significant improvements:
before: 1631s
after: 1245s (-24%)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 10 Oct 2019 03:49:33 +0200 |
parents | 2372284d9457 |
children | 6000f5b25c9b |
rev | line source |
---|---|
28734
4e51f9d1683e
py3: use print_function in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28733
diff
changeset
|
1 from __future__ import absolute_import, print_function |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
2 import collections |
8656 | 3 import struct |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
4 import unittest |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
5 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
6 from mercurial import mdiff |
400
8b067bde6679
Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff
changeset
|
7 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
8 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
9 class diffreplace(collections.namedtuple('diffreplace', 'start end from_ to')): |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
10 def __repr__(self): |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
11 return 'diffreplace(%r, %r, %r, %r)' % self |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
12 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
13 |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
14 class BdiffTests(unittest.TestCase): |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
15 def assert_bdiff_applies(self, a, b): |
32202
ded48ad55146
bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents:
30931
diff
changeset
|
16 d = mdiff.textdiff(a, b) |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
17 c = a |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
18 if d: |
32203
0c73634d0570
mpatch: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents:
32202
diff
changeset
|
19 c = mdiff.patches(a, [d]) |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
20 self.assertEqual( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
21 c, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
22 b, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
23 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
24 "bad diff+patch result from\n %r to\n " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
25 "%r: \nbdiff: %r\npatched: %r" % (a, b, d, c[:200]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
26 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
27 ) |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
28 |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
29 def assert_bdiff(self, a, b): |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
30 self.assert_bdiff_applies(a, b) |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
31 self.assert_bdiff_applies(b, a) |
400
8b067bde6679
Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff
changeset
|
32 |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
33 def test_bdiff_basic(self): |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
34 cases = [ |
39787
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
35 (b"a\nc\n\n\n\n", b"a\nb\n\n\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
36 (b"a\nb\nc\n", b"a\nc\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
37 (b"", b""), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
38 (b"a\nb\nc", b"a\nb\nc"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
39 (b"a\nb\nc\nd\n", b"a\nd\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
40 (b"a\nb\nc\nd\n", b"a\nc\ne\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
41 (b"a\nb\nc\n", b"a\nc\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
42 (b"a\n", b"c\na\nb\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
43 (b"a\n", b""), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
44 (b"a\n", b"b\nc\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
45 (b"a\n", b"c\na\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
46 (b"", b"adjfkjdjksdhfksj"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
47 (b"", b"ab"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
48 (b"", b"abc"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
49 (b"a", b"a"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
50 (b"ab", b"ab"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
51 (b"abc", b"abc"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
52 (b"a\n", b"a\n"), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
53 (b"a\nb", b"a\nb"), |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
54 ] |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
55 for a, b in cases: |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
56 self.assert_bdiff(a, b) |
400
8b067bde6679
Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff
changeset
|
57 |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
58 def showdiff(self, a, b): |
32202
ded48ad55146
bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents:
30931
diff
changeset
|
59 bin = mdiff.textdiff(a, b) |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
60 pos = 0 |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
61 q = 0 |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
62 actions = [] |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
63 while pos < len(bin): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
64 p1, p2, l = struct.unpack(">lll", bin[pos : pos + 12]) |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
65 pos += 12 |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
66 if p1: |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
67 actions.append(a[q:p1]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
68 actions.append(diffreplace(p1, p2, a[p1:p2], bin[pos : pos + l])) |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
69 pos += l |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
70 q = p2 |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
71 if q < len(a): |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
72 actions.append(a[q:]) |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
73 return actions |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
74 |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
75 def test_issue1295(self): |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
76 cases = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
77 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
78 b"x\n\nx\n\nx\n\nx\n\nz\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
79 b"x\n\nx\n\ny\n\nx\n\nx\n\nz\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
80 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
81 b'x\n\nx\n\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
82 diffreplace(6, 6, b'', b'y\n\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
83 b'x\n\nx\n\nz\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
84 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
85 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
86 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
87 b"x\n\nx\n\nx\n\nx\n\nz\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
88 b"x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
89 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
90 b'x\n\nx\n\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
91 diffreplace(6, 6, b'', b'y\n\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
92 b'x\n\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
93 diffreplace(9, 9, b'', b'y\n\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
94 b'x\n\nz\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
95 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
96 ), |
30592
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
97 ] |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
98 for old, new, want in cases: |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
99 self.assertEqual(self.showdiff(old, new), want) |
0d8cada9998d
tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents:
30591
diff
changeset
|
100 |
30595
99bd5479d58b
tests: fix test-bdiff to handle variance between pure and c bdiff code
Augie Fackler <augie@google.com>
parents:
30594
diff
changeset
|
101 def test_issue1295_varies_on_pure(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
102 # we should pick up abbbc. rather than bc.de as the longest match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
103 got = self.showdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
104 b"a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
105 b"a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
106 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
107 want_c = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
108 b'a\nb\nb\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
109 diffreplace(6, 6, b'', b'a\nb\nb\nb\nc\n.\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
110 b'b\nc\n.\nd\ne\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
111 diffreplace(16, 18, b'.\n', b''), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
112 b'f\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
113 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
114 want_pure = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
115 diffreplace(0, 0, b'', b'a\nb\nb\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
116 b'a\nb\nb\nb\nc\n.\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
117 diffreplace(12, 12, b'', b'b\nc\n.\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
118 b'd\ne\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
119 diffreplace(16, 18, b'.\n', b''), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
120 b'f\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
121 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
122 self.assertTrue( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
123 got in (want_c, want_pure), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
124 'got: %r, wanted either %r or %r' % (got, want_c, want_pure), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
125 ) |
30595
99bd5479d58b
tests: fix test-bdiff to handle variance between pure and c bdiff code
Augie Fackler <augie@google.com>
parents:
30594
diff
changeset
|
126 |
30593
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
127 def test_fixws(self): |
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
128 cases = [ |
39787
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
129 (b" \ta\r b\t\n", b"ab\n", 1), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
130 (b" \ta\r b\t\n", b" a b\n", 0), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
131 (b"", b"", 1), |
e05d7c71f209
py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
32203
diff
changeset
|
132 (b"", b"", 0), |
30593
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
133 ] |
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
134 for a, b, allws in cases: |
32202
ded48ad55146
bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents:
30931
diff
changeset
|
135 c = mdiff.fixws(a, allws) |
30593
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
136 self.assertEqual( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
137 c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
138 ) |
30593
4286015285ec
tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents:
30592
diff
changeset
|
139 |
30594
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
140 def test_nice_diff_for_trivial_change(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
141 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
142 self.showdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
143 b''.join(b'<%d\n-\n' % i for i in range(5)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
144 b''.join(b'>%d\n-\n' % i for i in range(5)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
145 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
146 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
147 diffreplace(0, 3, b'<0\n', b'>0\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
148 b'-\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
149 diffreplace(5, 8, b'<1\n', b'>1\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
150 b'-\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
151 diffreplace(10, 13, b'<2\n', b'>2\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
152 b'-\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
153 diffreplace(15, 18, b'<3\n', b'>3\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
154 b'-\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
155 diffreplace(20, 23, b'<4\n', b'>4\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
156 b'-\n', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
157 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
158 ) |
30427
ede7bc45bf0a
tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents:
29013
diff
changeset
|
159 |
30594
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
160 def test_prefer_appending(self): |
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
161 # 1 line to 3 lines |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
162 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
163 self.showdiff(b'a\n', b'a\n' * 3), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
164 [b'a\n', diffreplace(2, 2, b'', b'a\na\n')], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
165 ) |
30594
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
166 # 1 line to 5 lines |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
167 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
168 self.showdiff(b'a\n', b'a\n' * 5), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
169 [b'a\n', diffreplace(2, 2, b'', b'a\na\na\na\n')], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
170 ) |
30428
3743e5dbb824
tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents:
30427
diff
changeset
|
171 |
30594
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
172 def test_prefer_removing_trailing(self): |
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
173 # 3 lines to 1 line |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
174 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
175 self.showdiff(b'a\n' * 3, b'a\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
176 [b'a\n', diffreplace(2, 6, b'a\na\n', b'')], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
177 ) |
30594
ea648e8f8a34
tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents:
30593
diff
changeset
|
178 # 5 lines to 1 line |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
179 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
180 self.showdiff(b'a\n' * 5, b'a\n'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
181 [b'a\n', diffreplace(2, 10, b'a\na\na\na\n', b'')], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
182 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
183 |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
184 |
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
185 if __name__ == '__main__': |
30931
f2ad0d804700
test-bdiff: move import inside the function to avoid test failure
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30595
diff
changeset
|
186 import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
39789
diff
changeset
|
187 |
30591
1b393a93a7df
tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents:
30433
diff
changeset
|
188 silenttestrunner.main(__name__) |