Mercurial > hg
annotate tests/printenv.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 | 036787c10b16 |
children | 84a6e39bc723 |
rev | line source |
---|---|
25477
a372f7b4463b
tests: make printenv executable
Matt Mackall <mpm@selenic.com>
parents:
17018
diff
changeset
|
1 #!/usr/bin/env python |
a372f7b4463b
tests: make printenv executable
Matt Mackall <mpm@selenic.com>
parents:
17018
diff
changeset
|
2 # |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
3 # simple script to be used in hooks |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
4 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
5 # put something like this in the repo .hg/hgrc: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
6 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
7 # [hooks] |
17018
e7fdfc702d9f
tests: consistently use printenv.py the same MSYS/Windows-compatible way
Mads Kiilerich <mads@kiilerich.com>
parents:
16982
diff
changeset
|
8 # changegroup = python "$TESTDIR/printenv.py" <hookname> [exit] [output] |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
9 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
10 # - <hookname> is a mandatory argument (e.g. "changegroup") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
11 # - [exit] is the exit code of the hook (default: 0) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
12 # - [output] is the name of the output file (default: use sys.stdout) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
13 # the file will be opened in append mode. |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
14 # |
28944
036787c10b16
py3: use absolute_import in printenv.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
25477
diff
changeset
|
15 from __future__ import absolute_import |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
16 import os |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
17 import sys |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
18 |
7080
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
19 try: |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
20 import msvcrt |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
21 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
22 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
7186
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7080
diff
changeset
|
23 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
7080
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
24 except ImportError: |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
25 pass |
a6477aa893b8
tests: Windows compatibility fixes
Patrick Mezard <pmezard@gmail.com>
parents:
4659
diff
changeset
|
26 |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
27 exitcode = 0 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
28 out = sys.stdout |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
29 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
30 name = sys.argv[1] |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
31 if len(sys.argv) > 2: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
32 exitcode = int(sys.argv[2]) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
33 if len(sys.argv) > 3: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
34 out = open(sys.argv[3], "ab") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
35 |
4643
a39cec1d5cb8
printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents:
4285
diff
changeset
|
36 # variables with empty values may not exist on all platforms, filter |
a39cec1d5cb8
printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents:
4285
diff
changeset
|
37 # them now for portability sake. |
16963
c19113e842d3
tests/printenv.py: replace \ with / in output
Adrian Buehlmann <adrian@cadifra.com>
parents:
13405
diff
changeset
|
38 env = [(k, v) for k, v in os.environ.iteritems() |
4643
a39cec1d5cb8
printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents:
4285
diff
changeset
|
39 if k.startswith("HG_") and v] |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
40 env.sort() |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
41 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
42 out.write("%s hook: " % name) |
16982
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
43 if os.name == 'nt': |
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
44 filter = lambda x: x.replace('\\', '/') |
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
45 else: |
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
46 filter = lambda x: x |
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
47 vars = ["%s=%s" % (k, filter(v)) for k, v in env] |
9c892c830a72
tests/printenv.py: eliminate trailing spaces on output
Adrian Buehlmann <adrian@cadifra.com>
parents:
16963
diff
changeset
|
48 out.write(" ".join(vars)) |
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
49 out.write("\n") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
50 out.close() |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
51 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
52 sys.exit(exitcode) |