tests/test-annotate.py
author Siddharth Agarwal <sid0@fb.com>
Mon, 02 Oct 2017 02:34:47 -0700
changeset 34432 2e32c6a31cc7
parent 34430 80215865d154
child 34433 2f5a135b2b04
permissions -rw-r--r--
annotate: introduce attr for storing per-line annotate data We're going to extend this a bit -- at first by simply adding whether this was a skipped child. We're well on our way to outgrowing tuples, though -- adding more and more fields to tuples becomes annoying very quickly. Differential Revision: https://phab.mercurial-scm.org/D898
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    30
                     for i in xrange(1, text.count(b'\n') + 1)],
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], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    39
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    40
            annotateline('old', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    41
            annotateline('p1', 3),
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], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    47
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    48
            annotateline('p2', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    49
            annotateline('p2', 3),
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], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    58
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    59
            annotateline('c', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    60
            annotateline('p2', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    61
            annotateline('c', 4),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    62
            annotateline('p2', 3),
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], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    69
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    70
            annotateline('c', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    71
            annotateline('p1', 3),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    72
            annotateline('c', 4),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    73
            annotateline('p2', 3),
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], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    82
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    83
            annotateline('old', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    84
            annotateline('p2', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    85
            annotateline('p2', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    86
            annotateline('p2', 3),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    87
        ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    88
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    89
        childann = decorate(childdata, childfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    90
        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
    91
                                 diffopts)
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    92
        self.assertEqual(childann[0], [
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    93
            annotateline('old', 1),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    94
            annotateline('old', 2),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    95
            annotateline('p1', 3),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    96
            annotateline('p1', 3),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    97
            annotateline('p2', 3),
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
    98
        ])
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    99
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   100
if __name__ == '__main__':
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   101
    import silenttestrunner
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   102
    silenttestrunner.main(__name__)