tests/test-doctest.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 21 Dec 2020 11:20:31 +0100
changeset 46584 aa19d60ac974
parent 45942 89a2afe31e82
child 46907 ffd3e823a7e5
permissions -rw-r--r--
copies-rust: use simpler overwrite when value on both side are identical If the value are the same, their "overwritten" set is the same and we don't need to combine them. It helps our slower cases Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 86.722016 s, 80.828689 s, -5.893327 s, × 0.9320, 352 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 35.113727 s, 34.094064 s, -1.019663 s, × 0.9710, 89 µs/rev Full comparison with the previous revision below: Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000043 s, 0.000043 s, +0.000000 s, × 1.0000, 43 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000114 s, 0.000114 s, +0.000000 s, × 1.0000, 19 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004899 s, 0.004899 s, +0.000000 s, × 1.0000, 4 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000196 s, 0.000196 s, +0.000000 s, × 1.0000, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000050 s, 0.000049 s, -0.000001 s, × 0.9800, 49 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000125 s, 0.000117 s, -0.000008 s, × 0.9360, 16 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000321 s, 0.6f1f4a s, +0.000001 s, × 1.0031, 322 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.011948 s, 0.011856 s, -0.000092 s, × 0.9923, 1976 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.051267 s, 0.050992 s, -0.000275 s, × 0.9946, 10 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.087755 s, 0.087444 s, -0.000311 s, × 0.9965, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.061818 s, 0.062487 s, +0.000669 s, × 1.0108, 11 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.634253 s, 0.634909 s, +0.000656 s, × 1.0010, 14 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.013179 s, 0.013360 s, +0.000181 s, × 1.0137, 6680 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.119643 s, 0.120775 s, +0.001132 s, × 1.0095, 10 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000085 s, 0.000085 s, +0.000000 s, × 1.0000, 42 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000107 s, 0.000108 s, +0.000001 s, × 1.0093, 54 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000176 s, 0.000176 s, +0.000000 s, × 1.0000, 58 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000743 s, 0.000747 s, +0.000004 s, × 1.0054, 83 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.010246 s, 0.010128 s, -0.000118 s, × 0.9885, 7 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.015853 s, 0.015899 s, +0.000046 s, × 1.0029, 10 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.062971 s, 0.062215 s, -0.000756 s, × 0.9880, 10 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.518337 s, 0.521004 s, +0.002667 s, × 1.0051, 7 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000090 s, 0.000090 s, +0.000000 s, × 1.0000, 45 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000268 s, 0.000264 s, -0.000004 s, × 0.9851, 33 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000187 s, 0.000186 s, -0.000001 s, × 0.9947, 20 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000661 s, 0.000660 s, -0.000001 s, × 0.9985, 94 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003494 s, 0.003542 s, +0.000048 s, × 1.0137, 1180 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.070509 s, 0.071574 s, +0.001065 s, × 1.0151, 11929 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006489 s, 0.006498 s, +0.000009 s, × 1.0014, 4 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005070 s, 0.005206 s, +0.000136 s, × 1.0268, 126 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.065241 s, 0.065535 s, +0.000294 s, × 1.0045, 8 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.027284 s, 0.027139 s, -0.000145 s, × 0.9947, 44 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.203671 s, 0.201924 s, -0.001747 s, × 0.9914, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.239373 s, 1.257201 s, +0.017828 s, × 1.0144, 8 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 1.649803 s, 1.663045 s, +0.013242 s, × 1.0080, 8 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.000868 s, 0.000866 s, -0.000002 s, × 0.9977, 433 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000885 s, 0.000883 s, -0.000002 s, × 0.9977, 441 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000165 s, 0.000163 s, -0.000002 s, × 0.9879, 40 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001147 s, 0.001139 s, -0.000008 s, × 0.9930, 569 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.032885 s, 0.032753 s, -0.000132 s, × 0.9960, 32752 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.071304 s, 0.073266 s, +0.001962 s, × 1.0275, 12211 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.006506 s, 0.006567 s, +0.000061 s, × 1.0094, 4 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005486 s, 0.005427 s, -0.000059 s, × 0.9892, 132 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.064677 s, 0.064058 s, -0.000619 s, × 0.9904, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.306000 s, 0.303320 s, -0.002680 s, × 0.9912, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.288217 s, 0.288456 s, +0.000239 s, × 1.0008, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.086117 s, 0.085925 s, -0.000192 s, × 0.9978, 9 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.027512 s, 0.027302 s, -0.000210 s, × 0.9924, 44 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 1.998239 s, 2.034596 s, +0.036357 s, × 1.0182, 20 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.688201 s, 0.694030 s, +0.005829 s, × 1.0085, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 4.389428 s, 4.407723 s, +0.018295 s, × 1.0042, 12 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.578736 s, 0.574355 s, -0.004381 s, × 0.9924, 16 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 4.363599 s, 4.457827 s, +0.094228 s, × 1.0216, 12 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 4.324129 s, 4.351696 s, +0.027567 s, × 1.0064, 12 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 1.565727 s, 1.570065 s, +0.004338 s, × 1.0028, 8 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 86.722016 s, 80.828689 s, -5.893327 s, × 0.9320, 352 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 35.113727 s, 34.094064 s, -1.019663 s, × 0.9710, 89 µs/rev private : 459513 revs, 27.397070 s, 27.435529 s, +0.038459 s, × 1.0014, 59 µs/rev Differential Revision: https://phab.mercurial-scm.org/D9655
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7041
b856071435f7 tests: fix readline escape characters in output for test-doctest.py
Mads Kiilerich <mads@kiilerich.com>
parents: 5525
diff changeset
     1
# this is hack to make sure no escape characters are inserted into the output
28933
6262f0215d08 tests: make test-doctest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27432
diff changeset
     2
6262f0215d08 tests: make test-doctest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27432
diff changeset
     3
from __future__ import absolute_import
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
     4
from __future__ import print_function
28933
6262f0215d08 tests: make test-doctest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27432
diff changeset
     5
6262f0215d08 tests: make test-doctest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27432
diff changeset
     6
import doctest
45657
4a146cff76fa tests: fix test-check-module-imports.t broken by D9150
Martin von Zweigbergk <martinvonz@google.com>
parents: 45633
diff changeset
     7
import os
34140
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
     8
import re
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
     9
import subprocess
28933
6262f0215d08 tests: make test-doctest use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27432
diff changeset
    10
import sys
31438
82350f7fa56c tests: allow running doctests selectively on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 31024
diff changeset
    11
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    12
ispy3 = sys.version_info[0] >= 3
31438
82350f7fa56c tests: allow running doctests selectively on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 31024
diff changeset
    13
7078
967adcf5910d test-doctest: remove TERM env variable only if it's there
Patrick Mezard <pmezard@gmail.com>
parents: 7041
diff changeset
    14
if 'TERM' in os.environ:
7184
380fda3eed13 clean up trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7078
diff changeset
    15
    del os.environ['TERM']
3232
394ac87f3b74 [extendedchangelog] encode/decode function
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
    16
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    17
34140
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    18
class py3docchecker(doctest.OutputChecker):
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    19
    def check_output(self, want, got, optionflags):
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    20
        want2 = re.sub(r'''\bu(['"])(.*?)\1''', r'\1\2\1', want)  # py2: u''
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    21
        got2 = re.sub(r'''\bb(['"])(.*?)\1''', r'\1\2\1', got)  # py3: b''
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    22
        # py3: <exc.name>: b'<msg>' -> <name>: <msg>
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    23
        #      <exc.name>: <others> -> <name>: <others>
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    24
        got2 = re.sub(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    25
            r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    26
            r'\1: \3',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    27
            got2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    28
            re.MULTILINE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    29
        )
34140
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    30
        got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    31
        return any(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    32
            doctest.OutputChecker.check_output(self, w, g, optionflags)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    33
            for w, g in [(want, got), (want2, got2)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    34
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    35
34140
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    36
34424
e416819d9ebb doctest: drop hack to run py2/3 tests selectively
Yuya Nishihara <yuya@tcha.org>
parents: 34362
diff changeset
    37
def testmod(name, optionflags=0, testtarget=None):
20047
10a7d2bcb81b tests: make doctest test runner less verbose
Mads Kiilerich <madski@unity3d.com>
parents: 19098
diff changeset
    38
    __import__(name)
10a7d2bcb81b tests: make doctest test runner less verbose
Mads Kiilerich <madski@unity3d.com>
parents: 19098
diff changeset
    39
    mod = sys.modules[name]
10a7d2bcb81b tests: make doctest test runner less verbose
Mads Kiilerich <madski@unity3d.com>
parents: 19098
diff changeset
    40
    if testtarget is not None:
10a7d2bcb81b tests: make doctest test runner less verbose
Mads Kiilerich <madski@unity3d.com>
parents: 19098
diff changeset
    41
        mod = getattr(mod, testtarget)
34140
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    42
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    43
    # minimal copy of doctest.testmod()
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    44
    finder = doctest.DocTestFinder()
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    45
    checker = None
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    46
    if ispy3:
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    47
        checker = py3docchecker()
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    48
    runner = doctest.DocTestRunner(checker=checker, optionflags=optionflags)
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    49
    for test in finder.find(mod, name):
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    50
        runner.run(test)
52ec9ac0303b doctest: normalize b'', u'' and exception output on Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 32485
diff changeset
    51
    runner.summarize()
14171
fa2b596db182 ui: add configint function and tests
Sune Foldager <cryo@cyanite.org>
parents: 13949
diff changeset
    52
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41359
diff changeset
    53
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    54
DONT_RUN = []
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    55
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    56
# Exceptions to the defaults for a given detected module. The value for each
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    57
# module name is a list of dicts that specify the kwargs to pass to testmod.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    58
# testmod is called once per item in the list, so an empty list will cause the
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    59
# module to not be tested.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    60
testmod_arg_overrides = {
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    61
    'i18n.check-translation': DONT_RUN,  # may require extra installation
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    62
    'mercurial.dagparser': [{'optionflags': doctest.NORMALIZE_WHITESPACE}],
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    63
    'mercurial.keepalive': DONT_RUN,  # >>> is an example, not a doctest
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    64
    'mercurial.posix': DONT_RUN,  # run by mercurial.platform
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    65
    'mercurial.statprof': DONT_RUN,  # >>> is an example, not a doctest
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    66
    'mercurial.util': [{}, {'testtarget': 'platform'}],  # run twice!
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    67
    'mercurial.windows': DONT_RUN,  # run by mercurial.platform
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    68
    'tests.test-url': [{'optionflags': doctest.NORMALIZE_WHITESPACE}],
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    69
}
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    70
44656
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    71
fileset = 'set:(**.py)'
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    72
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    73
cwd = os.path.dirname(os.environ["TESTDIR"])
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    74
45633
5a19d7c9129b tests: skip doctests if not running from a hg repo
Joerg Sonnenberger <joerg@bec.de>
parents: 44656
diff changeset
    75
if not os.path.isdir(os.path.join(cwd, ".hg")):
5a19d7c9129b tests: skip doctests if not running from a hg repo
Joerg Sonnenberger <joerg@bec.de>
parents: 44656
diff changeset
    76
    sys.exit(0)
5a19d7c9129b tests: skip doctests if not running from a hg repo
Joerg Sonnenberger <joerg@bec.de>
parents: 44656
diff changeset
    77
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    78
files = subprocess.check_output(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45657
diff changeset
    79
    "hg files --print0 \"%s\"" % fileset,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45657
diff changeset
    80
    shell=True,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45657
diff changeset
    81
    cwd=cwd,
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    82
).split(b'\0')
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    83
44656
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    84
if sys.version_info[0] >= 3:
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    85
    cwd = os.fsencode(cwd)
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    86
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    87
mods_tested = set()
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    88
for f in files:
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    89
    if not f:
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    90
        continue
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    91
44656
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    92
    with open(os.path.join(cwd, f), "rb") as fh:
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    93
        if not re.search(br'\n\s*>>>', fh.read()):
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    94
            continue
15aef805619d tests: perform grep manually in test-doctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 44565
diff changeset
    95
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    96
    if ispy3:
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    97
        f = f.decode()
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    98
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
    99
    modname = f.replace('.py', '').replace('\\', '.').replace('/', '.')
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   100
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   101
    # Third-party modules aren't our responsibility to test, and the modules in
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   102
    # contrib generally do not have doctests in a good state, plus they're hard
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   103
    # to import if this test is running with py2, so we just skip both for now.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   104
    if modname.startswith('mercurial.thirdparty.') or modname.startswith(
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   105
        'contrib.'
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   106
    ):
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   107
        continue
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   108
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   109
    for kwargs in testmod_arg_overrides.get(modname, [{}]):
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   110
        mods_tested.add((modname, '%r' % (kwargs,)))
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   111
        if modname.startswith('tests.'):
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   112
            # On py2, we can't import from tests.foo, but it works on both py2
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   113
            # and py3 with the way that PYTHONPATH is setup to import without
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   114
            # the 'tests.' prefix, so we do that.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   115
            modname = modname[len('tests.') :]
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   116
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   117
        testmod(modname, **kwargs)
44564
529cb23155bc tests: make test-doctest.t module list match reality
Kyle Lippincott <spectral@google.com>
parents: 43780
diff changeset
   118
44565
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   119
# Meta-test: let's make sure that we actually ran what we expected to, above.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   120
# Each item in the set is a 2-tuple of module name and stringified kwargs passed
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   121
# to testmod.
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   122
expected_mods_tested = set(
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   123
    [
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   124
        ('hgext.convert.convcmd', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   125
        ('hgext.convert.cvsps', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   126
        ('hgext.convert.filemap', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   127
        ('hgext.convert.p4', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   128
        ('hgext.convert.subversion', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   129
        ('hgext.fix', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   130
        ('hgext.mq', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   131
        ('mercurial.changelog', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   132
        ('mercurial.cmdutil', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   133
        ('mercurial.color', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   134
        ('mercurial.config', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   135
        ('mercurial.dagparser', "{'optionflags': 4}"),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   136
        ('mercurial.encoding', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   137
        ('mercurial.fancyopts', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   138
        ('mercurial.formatter', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   139
        ('mercurial.hg', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   140
        ('mercurial.hgweb.hgwebdir_mod', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   141
        ('mercurial.match', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   142
        ('mercurial.mdiff', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   143
        ('mercurial.minirst', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   144
        ('mercurial.parser', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   145
        ('mercurial.patch', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   146
        ('mercurial.pathutil', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   147
        ('mercurial.pycompat', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   148
        ('mercurial.revlogutils.deltas', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   149
        ('mercurial.revset', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   150
        ('mercurial.revsetlang', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   151
        ('mercurial.simplemerge', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   152
        ('mercurial.smartset', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   153
        ('mercurial.store', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   154
        ('mercurial.subrepo', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   155
        ('mercurial.templater', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   156
        ('mercurial.ui', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   157
        ('mercurial.util', "{'testtarget': 'platform'}"),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   158
        ('mercurial.util', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   159
        ('mercurial.utils.dateutil', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   160
        ('mercurial.utils.stringutil', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   161
        ('tests.drawdag', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   162
        ('tests.test-run-tests', '{}'),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   163
        ('tests.test-url', "{'optionflags': 4}"),
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   164
    ]
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   165
)
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   166
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   167
unexpectedly_run = mods_tested.difference(expected_mods_tested)
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   168
not_run = expected_mods_tested.difference(mods_tested)
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   169
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   170
if unexpectedly_run:
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   171
    print('Unexpectedly ran (probably need to add to list):')
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   172
    for r in sorted(unexpectedly_run):
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   173
        print('  %r' % (r,))
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   174
if not_run:
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   175
    print('Expected to run, but was not run (doctest removed?):')
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   176
    for r in sorted(not_run):
0af56d3ee24c tests: make test-doctest.t automatically find files to run tests on
Kyle Lippincott <spectral@google.com>
parents: 44564
diff changeset
   177
        print('  %r' % (r,))