Mercurial > hg
view tests/test-linerange.py @ 36037:8de90e006c78
run-tests: report tests that exception occurred in
We now record the test that an exception occurred in. We put this
information to use by aggregating the count of failures in each
test. For each exception, the exception report now prints the total
number of tests having that exception and the test with the least
number of exceptions exhibiting that failure. The exception list
is now sorted by (total count, tests impacted, count of failures
in least failing test).
This allows us to:
* Assess how widespread a failure is. Some exceptions occur a lot
in a few tests. Others occur over many tests.
* Easily run a test exhibiting an exception without having to find
a failure in test output.
* Find and fix low hanging fruit (e.g. exceptions that are the
only failure in a test).
Here's an example of the new output:
199 (4 tests) /home/gps/src/hg/hgext/blackbox.py:191: %b requires a bytes-like object, or an object that implements __bytes__, not 'str' (test-devel-warnings.t - 1 total)
142 (19 tests) /home/gps/src/hg/hgext/mq.py:655: list indices must be integers or slices, not bytes (test-hardlinks.t - 1 total)
140 (20 tests) /home/gps/src/hg/mercurial/patch.py:296: string argument expected, got 'bytes' (test-audit-subrepo.t - 1 total)
101 (15 tests) /home/gps/src/hg/hgext/convert/convcmd.py:60: encode() argument 1 must be str, not bytes (test-convert-clonebranches.t - 1 total)
90 (2 tests) /home/gps/src/hg/hgext/mq.py:456: can't concat str to bytes (test-mq-qqueue.t - 1 total)
87 (2 tests) /home/gps/src/hg/mercurial/branchmap.py:380: %b requires a bytes-like object, or an object that implements __bytes__, not 'FileNotFoundError' (test-branches.t - 2 total)
85 (22 tests) /home/gps/src/hg/mercurial/sshpeer.py:223: cannot convert 'UUID' object to bytes (test-bundle2-pushback.t - 1 total)
1 (1 tests) /home/gps/src/hg/mercurial/formatter.py:254: %b requires a bytes-like object, or an object that implements __bytes__, not 'str' (test-debugextensions.t - 2 total)
1 (1 tests) /home/gps/src/hg/hgext/convert/convcmd.py:420: startswith first arg must be str or a tuple of str, not bytes (test-convert-authormap.t - 2 total)
1 (1 tests) /home/gps/src/hg/mercurial/revlog.py:797: '>=' not supported between instances of 'NoneType' and 'int' (test-unionrepo.t - 1 total)
1 (1 tests) /home/gps/src/hg/hgext/show.py:129: %b requires a bytes-like object, or an object that implements __bytes__, not 'str' (test-show.t - 1 total)
Differential Revision: https://phab.mercurial-scm.org/D2138
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Feb 2018 12:42:10 -0800 |
parents | 3eeb8e138e5c |
children | 6939b6ac960a |
line wrap: on
line source
from __future__ import absolute_import import unittest from mercurial import error, mdiff # for readability, line numbers are 0-origin text1 = ''' 00 at OLD 01 at OLD 02 at OLD 02 at NEW, 03 at OLD 03 at NEW, 04 at OLD 04 at NEW, 05 at OLD 05 at NEW, 06 at OLD 07 at OLD 08 at OLD 09 at OLD 10 at OLD 11 at OLD '''[1:] # strip initial LF text2 = ''' 00 at NEW 01 at NEW 02 at NEW, 03 at OLD 03 at NEW, 04 at OLD 04 at NEW, 05 at OLD 05 at NEW, 06 at OLD 06 at NEW 07 at NEW 08 at NEW 09 at NEW 10 at NEW 11 at NEW '''[1:] # strip initial LF def filteredblocks(blocks, rangeb): """return `rangea` extracted from `blocks` coming from `mdiff.blocksinrange` along with the mask of blocks within rangeb. """ filtered, rangea = mdiff.blocksinrange(blocks, rangeb) skipped = [b not in filtered for b in blocks] return rangea, skipped class blocksinrangetests(unittest.TestCase): def setUp(self): self.blocks = list(mdiff.allblocks(text1, text2)) assert self.blocks == [ ([0, 3, 0, 2], '!'), ((3, 7, 2, 6), '='), ([7, 12, 6, 12], '!'), ((12, 12, 12, 12), '='), ], self.blocks def testWithinEqual(self): """linerange within an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^ linerange2 = (3, 5) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (4, 6)) self.assertEqual(skipped, [True, False, True, True]) def testWithinEqualStrictly(self): """linerange matching exactly an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^^^ linerange2 = (2, 6) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (3, 7)) self.assertEqual(skipped, [True, False, True, True]) def testWithinEqualLowerbound(self): """linerange at beginning of an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^ linerange2 = (2, 4) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (3, 5)) self.assertEqual(skipped, [True, False, True, True]) def testWithinEqualLowerboundOneline(self): """oneline-linerange at beginning of an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^ linerange2 = (2, 3) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (3, 4)) self.assertEqual(skipped, [True, False, True, True]) def testWithinEqualUpperbound(self): """linerange at end of an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^^ linerange2 = (3, 6) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (4, 7)) self.assertEqual(skipped, [True, False, True, True]) def testWithinEqualUpperboundOneLine(self): """oneline-linerange at end of an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^ linerange2 = (5, 6) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (6, 7)) self.assertEqual(skipped, [True, False, True, True]) def testWithinFirstBlockNeq(self): """linerange within the first "!" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^ # | (empty) # ^ # ^^ for linerange2 in [ (0, 1), (1, 1), (1, 2), (0, 2), ]: linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (0, 3)) self.assertEqual(skipped, [False, True, True, True]) def testWithinLastBlockNeq(self): """linerange within the last "!" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^ # ^ # | (empty) # ^^^^^^ # ^ for linerange2 in [ (6, 7), (7, 8), (7, 7), (6, 12), (11, 12), ]: linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (7, 12)) self.assertEqual(skipped, [True, True, False, True]) def testAccrossTwoBlocks(self): """linerange accross two blocks""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^^^ linerange2 = (1, 5) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (0, 6)) self.assertEqual(skipped, [False, False, True, True]) def testCrossingSeveralBlocks(self): """linerange accross three blocks""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^^^^^^ linerange2 = (1, 8) linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, (0, 12)) self.assertEqual(skipped, [False, False, False, True]) def testStartInEqBlock(self): """linerange starting in an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^^^ # ^^^^^^^ for linerange2, expectedlinerange1 in [ ((5, 9), (6, 12)), ((4, 11), (5, 12)), ]: linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, expectedlinerange1) self.assertEqual(skipped, [True, False, False, True]) def testEndInEqBlock(self): """linerange ending in an "=" block""" # IDX 0 1 # 012345678901 # SRC NNOOOONNNNNN (New/Old) # ^^ # ^^^^^ for linerange2, expectedlinerange1 in [ ((1, 3), (0, 4)), ((0, 4), (0, 5)), ]: linerange1, skipped = filteredblocks(self.blocks, linerange2) self.assertEqual(linerange1, expectedlinerange1) self.assertEqual(skipped, [False, False, True, True]) def testOutOfRange(self): """linerange exceeding file size""" exctype = error.Abort for linerange2 in [ (0, 34), (15, 12), ]: # Could be `with self.assertRaises(error.Abort)` but python2.6 # does not have assertRaises context manager. try: mdiff.blocksinrange(self.blocks, linerange2) except exctype as exc: self.assertTrue('line range exceeds file size' in str(exc)) else: self.fail('%s not raised' % exctype.__name__) if __name__ == '__main__': import silenttestrunner silenttestrunner.main(__name__)