tests/silenttestrunner.py
author Arun Kulshreshtha <akulshreshtha@janestreet.com>
Tue, 30 Aug 2022 15:29:55 -0400
changeset 49491 c6a1beba27e9
parent 48875 6000f5b25c9b
permissions -rw-r--r--
bisect: avoid copying ancestor list for non-merge commits During a bisection, hg needs to compute a list of all ancestors for every candidate commit. This is accomplished via a bottom-up traversal of the set of candidates, during which each revision's ancestor list is populated using the ancestor list of its parent(s). Previously, this involved copying the entire list, which could be very long in if the bisection range was large. To help improve this, we can observe that each candidate commit is visited exactly once, at which point its ancestor list is copied into its children's lists and then dropped. In the case of non-merge commits, a commit's ancestor list consists exactly of its parent's list plus itself. This means that we can trivially reuse the parent's existing list for one of its non-merge children, which avoids copying entirely if that commit is the parent's only child. This makes bisections over linear ranges of commits much faster. During some informal testing in the large publicly-available `mozilla-central` repository, this noticeably sped up bisections over large ranges of history: Setup: $ cd mozilla-central $ hg bisect --reset $ hg bisect --good 0 $ hg log -r tip -T '{rev}\n' 628417 Test: $ time hg bisect --bad tip --noupdate Before: real 3m35.927s user 3m35.553s sys 0m0.319s After: real 1m41.142s user 1m40.810s sys 0m0.285s
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28736
403b0a7ab410 tests: lexicographical imports in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28730
diff changeset
     1
import os
403b0a7ab410 tests: lexicographical imports in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28730
diff changeset
     2
import sys
28729
fc2268b9a07c py3: use absolute_import in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 23308
diff changeset
     3
import unittest
18665
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     4
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 28736
diff changeset
     5
18665
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     6
def main(modulename):
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     7
    '''run the tests found in module, printing nothing when all tests pass'''
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     8
    module = sys.modules[modulename]
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     9
    suite = unittest.defaultTestLoader.loadTestsFromModule(module)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    10
    results = unittest.TestResult()
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    11
    suite.run(results)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    12
    if results.errors or results.failures:
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    13
        for tc, exc in results.errors:
28730
73437077753c py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28729
diff changeset
    14
            print('ERROR:', tc)
73437077753c py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28729
diff changeset
    15
            print()
18665
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    16
            sys.stdout.write(exc)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    17
        for tc, exc in results.failures:
28730
73437077753c py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28729
diff changeset
    18
            print('FAIL:', tc)
73437077753c py3: use print_function in silenttestrunner.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28729
diff changeset
    19
            print()
18665
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    20
            sys.stdout.write(exc)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    21
        sys.exit(1)
23308
dadcd40b62d8 silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents: 18665
diff changeset
    22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 28736
diff changeset
    23
23308
dadcd40b62d8 silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents: 18665
diff changeset
    24
if os.environ.get('SILENT_BE_NOISY'):
dadcd40b62d8 silenttestrunner: add environment variable to make tests noisy again
Augie Fackler <augie@google.com>
parents: 18665
diff changeset
    25
    main = unittest.main