tests/test-bdiff.py
author Boris Feld <boris.feld@octobus.net>
Mon, 14 Jan 2019 17:15:21 +0100
changeset 41277 61f9ef23a12f
parent 39789 e961f18a0094
child 43076 2372284d9457
permissions -rw-r--r--
dagop: minor python optimization to `headrevs` Less lookup and less function call never hurt. This provides a small speedup on various run of the 'heads()' revset. This also buys back some of the slow down we observed in the previous changesets for single value lookup. Performance number: 0) before dagop.headrevs usage 1) after dagop.headrevs usage 2) after this change revset: heads(all()) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.036503 0.032564 0.030024 0.032378 0.030887 0.036367 0.031713 0.032205 0.036467 0.032286 0.030300 1) 0.036668 0.035347 108% 0.035611 118% 0.035358 109% 0.035726 115% 0.036411 0.035261 111% 0.036096 112% 0.036052 0.035095 108% 0.035792 118% 2) 0.034254 93% 0.034482 0.035003 0.034353 0.033754 94% 0.034689 0.034361 0.035059 0.034636 0.034662 0.035465 revset: heads(-10000:-1) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.003936 0.003218 0.003227 0.003302 0.003328 0.003848 0.003305 0.003252 0.003839 0.003306 0.003279 1) 0.003870 0.003785 117% 0.003821 118% 0.003780 114% 0.003769 113% 0.003776 0.003792 114% 0.003805 117% 0.003810 0.003798 114% 0.003840 117% 2) 0.003666 94% 0.003577 94% 0.003632 0.003644 0.003614 0.003638 0.003652 0.003632 0.003661 0.003660 0.003658 revset: (-5000:-1000) and heads(-10000:-1) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.004244 0.003368 0.003313 0.003367 0.003327 0.004325 0.003401 0.003379 0.004310 0.003359 0.003396 1) 0.003969 93% 0.003862 114% 0.003834 115% 0.003810 113% 0.003822 114% 0.003940 91% 0.003908 114% 0.003814 112% 0.003986 92% 0.003954 117% 0.003816 112% 2) 0.003728 93% 0.003638 94% 0.003659 0.003685 0.003628 94% 0.003716 94% 0.003653 93% 0.003655 0.003748 94% 0.003740 94% 0.003686 revset: heads(matching(tip, "author")) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.574666 7.545950 7.570743 7.578697 7.525725 7.509929 7.443854 7.488442 7.452880 7.445411 7.689107 1) 7.549390 7.389162 7.529790 7.536297 7.450467 7.555347 7.404586 7.514948 7.542794 7.524787 7.536918 2) 7.568294 7.479326 7.578624 7.380375 7.440102 7.454218 7.515189 7.556511 7.524585 7.537566 7.507418 revset: heads(matching(tip, "author")) and -10000:-1 plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.512533 7.605877 7.382894 7.462109 7.420086 7.575034 7.448452 7.549374 7.457880 7.450308 7.515019 1) 7.548677 7.551832 7.629598 7.494857 7.550554 7.521838 7.451794 error 7.321781 7.546885 7.557523 2) 7.451985 7.541044 7.506563 7.470928 7.512618 7.474988 7.498887 7.547930 7.560276 7.618599 7.465442 revset: (-10000:-1) and heads(matching(tip, "author")) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.465419 7.570089 7.439594 7.521221 7.498716 7.492922 7.479108 7.552397 7.407888 error 7.468264 1) 7.539866 7.548045 7.491761 7.517170 7.469824 7.501990 7.579102 7.502568 7.578102 7.555754 7.567622 2) 7.370463 7.514712 7.497024 7.679428 7.638138 7.490775 7.472273 7.652587 7.584139 7.511893 7.466384
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
284fda4cd093 removed unused imports
Martin Geisler <mg@lazybytes.net>
parents: 8449
diff changeset
     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
28733
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
     6
from mercurial import (
32202
ded48ad55146 bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents: 30931
diff changeset
     7
    mdiff,
28733
2e54aaa65afc py3: use absolute_import in test-bdiff.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 15530
diff changeset
     8
)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
     9
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
class diffreplace(
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
    collections.namedtuple('diffreplace', 'start end from_ to')):
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
    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
    13
        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
    14
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    15
class BdiffTests(unittest.TestCase):
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    16
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    17
    def assert_bdiff_applies(self, a, b):
32202
ded48ad55146 bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents: 30931
diff changeset
    18
        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
    19
        c = a
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    20
        if d:
32203
0c73634d0570 mpatch: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents: 32202
diff changeset
    21
            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
    22
        self.assertEqual(
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    23
            c, b, ("bad diff+patch result from\n  %r to\n  "
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    24
                   "%r: \nbdiff: %r\npatched: %r" % (a, b, d, c[:200])))
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    25
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    26
    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
    27
        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
    28
        self.assert_bdiff_applies(b, a)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    29
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    30
    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
    31
        cases = [
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    32
            (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
    33
            (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
    34
            (b"", b""),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    35
            (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
    36
            (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
    37
            (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
    38
            (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
    39
            (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
    40
            (b"a\n", b""),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    41
            (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
    42
            (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
    43
            (b"", b"adjfkjdjksdhfksj"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    44
            (b"", b"ab"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    45
            (b"", b"abc"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    46
            (b"a", b"a"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    47
            (b"ab", b"ab"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    48
            (b"abc", 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\n", b"a\n"),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    50
            (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
    51
        ]
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
    52
        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
    53
            self.assert_bdiff(a, b)
400
8b067bde6679 Add a fast binary diff extension (not yet used)
mpm@selenic.com
parents:
diff changeset
    54
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
    55
    def showdiff(self, a, b):
32202
ded48ad55146 bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents: 30931
diff changeset
    56
        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
    57
        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
    58
        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
    59
        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
    60
        while pos < len(bin):
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
            p1, p2, l = struct.unpack(">lll", bin[pos: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
    62
            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
    63
            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
    64
                actions.append(a[q: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
    65
            actions.append(diffreplace(p1, p2, a[p1:p2], bin[pos: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
    66
            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
    67
            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
    68
        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
    69
            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
    70
        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
    71
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
    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
    73
        cases = [
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    74
            (b"x\n\nx\n\nx\n\nx\n\nz\n", b"x\n\nx\n\ny\n\nx\n\nx\n\nz\n",
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    75
             [b'x\n\nx\n\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    76
              diffreplace(6, 6, b'', b'y\n\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    77
              b'x\n\nx\n\nz\n']),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    78
            (b"x\n\nx\n\nx\n\nx\n\nz\n", b"x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n",
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    79
             [b'x\n\nx\n\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    80
              diffreplace(6, 6, b'', b'y\n\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    81
              b'x\n\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    82
              diffreplace(9, 9, b'', b'y\n\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    83
              b'x\n\nz\n']),
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
    84
        ]
0d8cada9998d tests: update more of test-bdiff.py to use unittest (part 2 of 4)
Augie Fackler <augie@google.com>
parents: 30591
diff changeset
    85
        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
    86
            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
    87
30595
99bd5479d58b tests: fix test-bdiff to handle variance between pure and c bdiff code
Augie Fackler <augie@google.com>
parents: 30594
diff changeset
    88
    def test_issue1295_varies_on_pure(self):
99bd5479d58b tests: fix test-bdiff to handle variance between pure and c bdiff code
Augie Fackler <augie@google.com>
parents: 30594
diff changeset
    89
            # we should pick up abbbc. rather than bc.de as the longest match
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    90
        got = self.showdiff(b"a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    91
                            b"a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n")
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    92
        want_c = [b'a\nb\nb\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    93
                  diffreplace(6, 6, b'', b'a\nb\nb\nb\nc\n.\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    94
                  b'b\nc\n.\nd\ne\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    95
                  diffreplace(16, 18, b'.\n', b''),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    96
                  b'f\n']
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    97
        want_pure = [diffreplace(0, 0, b'', b'a\nb\nb\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    98
                     b'a\nb\nb\nb\nc\n.\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
    99
                     diffreplace(12, 12, b'', b'b\nc\n.\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   100
                     b'd\ne\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   101
                     diffreplace(16, 18, b'.\n', b''), b'f\n']
39789
e961f18a0094 tests: use assertTrue() instead of assert_() in test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39788
diff changeset
   102
        self.assertTrue(got in (want_c, want_pure),
e961f18a0094 tests: use assertTrue() instead of assert_() in test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39788
diff changeset
   103
                        'got: %r, wanted either %r or %r' % (
e961f18a0094 tests: use assertTrue() instead of assert_() in test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39788
diff changeset
   104
                            got, want_c, want_pure))
30595
99bd5479d58b tests: fix test-bdiff to handle variance between pure and c bdiff code
Augie Fackler <augie@google.com>
parents: 30594
diff changeset
   105
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
   106
    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
   107
        cases = [
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   108
            (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
   109
            (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
   110
            (b"", b"", 1),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   111
            (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
   112
        ]
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   113
        for a, b, allws in cases:
32202
ded48ad55146 bdiff: proxy through mdiff module
Yuya Nishihara <yuya@tcha.org>
parents: 30931
diff changeset
   114
            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
   115
            self.assertEqual(
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   116
                c, b, 'fixws(%r) want %r got %r (allws=%r)' % (a, b, c, allws))
4286015285ec tests: update more of test-bdiff.py to use unittest (part 3 of 4)
Augie Fackler <augie@google.com>
parents: 30592
diff changeset
   117
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   118
    def test_nice_diff_for_trivial_change(self):
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   119
        self.assertEqual(self.showdiff(
39788
69defbb83be7 py3: use '%d' for integers instead of '%s'
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39787
diff changeset
   120
            b''.join(b'<%d\n-\n' % i for i in range(5)),
69defbb83be7 py3: use '%d' for integers instead of '%s'
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39787
diff changeset
   121
            b''.join(b'>%d\n-\n' % i for i in range(5))),
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   122
                         [diffreplace(0, 3, b'<0\n', b'>0\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   123
                          b'-\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   124
                          diffreplace(5, 8, b'<1\n', b'>1\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   125
                          b'-\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   126
                          diffreplace(10, 13, b'<2\n', b'>2\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   127
                          b'-\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   128
                          diffreplace(15, 18, b'<3\n', b'>3\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   129
                          b'-\n',
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   130
                          diffreplace(20, 23, b'<4\n', b'>4\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   131
                          b'-\n'])
30427
ede7bc45bf0a tests: make test-bdiff.py easier to maintain
Mads Kiilerich <madski@unity3d.com>
parents: 29013
diff changeset
   132
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   133
    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
   134
        # 1 line to 3 lines
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   135
        self.assertEqual(self.showdiff(b'a\n', b'a\n' * 3),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   136
                         [b'a\n', diffreplace(2, 2, b'', b'a\na\n')])
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   137
        # 1 line to 5 lines
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   138
        self.assertEqual(self.showdiff(b'a\n', b'a\n' * 5),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   139
                         [b'a\n', diffreplace(2, 2, b'', b'a\na\na\na\n')])
30428
3743e5dbb824 tests: explore some bdiff cases
Mads Kiilerich <madski@unity3d.com>
parents: 30427
diff changeset
   140
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   141
    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
   142
        # 3 lines to 1 line
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   143
        self.assertEqual(self.showdiff(b'a\n' * 3, b'a\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   144
                         [b'a\n', diffreplace(2, 6, b'a\na\n', b'')])
30594
ea648e8f8a34 tests: finish updating test-bdiff to unittest (part 4 of 4)
Augie Fackler <augie@google.com>
parents: 30593
diff changeset
   145
        # 5 lines to 1 line
39787
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   146
        self.assertEqual(self.showdiff(b'a\n' * 5, b'a\n'),
e05d7c71f209 py3: add b'' prefixes in tests/test-bdiff.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 32203
diff changeset
   147
                         [b'a\n', diffreplace(2, 10, b'a\na\na\na\n', b'')])
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   148
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   149
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
   150
    import silenttestrunner
30591
1b393a93a7df tests: migrate test-bdiff.py to use unittest (part 1 of 4)
Augie Fackler <augie@google.com>
parents: 30433
diff changeset
   151
    silenttestrunner.main(__name__)