tests/test-ui-verbosity.py
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 49285 56f98406831b
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     1
import os
28842
d466facc5a6e tests: alias ui as uimod in test-revlog-ancestry/test-ui-verbosity
Yuya Nishihara <yuya@tcha.org>
parents: 28679
diff changeset
     2
from mercurial import (
36294
2507bf180413 py3: use range instead of xrange on py3 in tests/test-ui-verbosity.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
     3
    pycompat,
28842
d466facc5a6e tests: alias ui as uimod in test-revlog-ancestry/test-ui-verbosity
Yuya Nishihara <yuya@tcha.org>
parents: 28679
diff changeset
     4
    ui as uimod,
d466facc5a6e tests: alias ui as uimod in test-revlog-ancestry/test-ui-verbosity
Yuya Nishihara <yuya@tcha.org>
parents: 28679
diff changeset
     5
)
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     6
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     7
hgrc = os.environ['HGRCPATH']
5523
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3349
diff changeset
     8
f = open(hgrc)
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3349
diff changeset
     9
basehgrc = f.read()
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3349
diff changeset
    10
f.close()
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    11
28678
870dae78234c py3: make test-ui-verbosity use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 12865
diff changeset
    12
print('      hgrc settings    command line options      final result   ')
870dae78234c py3: make test-ui-verbosity use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 12865
diff changeset
    13
print('    quiet verbo debug   quiet verbo debug      quiet verbo debug')
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    14
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48875
diff changeset
    15
for i in range(64):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    16
    hgrc_quiet = bool(i & 1 << 0)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    17
    hgrc_verbose = bool(i & 1 << 1)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    18
    hgrc_debug = bool(i & 1 << 2)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    19
    cmd_quiet = bool(i & 1 << 3)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    20
    cmd_verbose = bool(i & 1 << 4)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    21
    cmd_debug = bool(i & 1 << 5)
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    22
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    23
    f = open(hgrc, 'w')
5523
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3349
diff changeset
    24
    f.write(basehgrc)
5db730475d6d tests/*: avoid losing the original settings from $HGRCPATH
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3349
diff changeset
    25
    f.write('\n[ui]\n')
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    26
    if hgrc_quiet:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    27
        f.write('quiet = True\n')
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    28
    if hgrc_verbose:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    29
        f.write('verbose = True\n')
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    30
    if hgrc_debug:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    31
        f.write('debug = True\n')
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    32
    f.close()
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    33
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28842
diff changeset
    34
    u = uimod.ui.load()
8136
6b5522cb2ad2 ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents: 5523
diff changeset
    35
    if cmd_quiet or cmd_debug or cmd_verbose:
37927
76d0a343c305 tests: port test-ui-verbosity.py to Python 3
Augie Fackler <augie@google.com>
parents: 36294
diff changeset
    36
        u.setconfig(b'ui', b'quiet', pycompat.bytestr(bool(cmd_quiet)))
76d0a343c305 tests: port test-ui-verbosity.py to Python 3
Augie Fackler <augie@google.com>
parents: 36294
diff changeset
    37
        u.setconfig(b'ui', b'verbose', pycompat.bytestr(bool(cmd_verbose)))
76d0a343c305 tests: port test-ui-verbosity.py to Python 3
Augie Fackler <augie@google.com>
parents: 36294
diff changeset
    38
        u.setconfig(b'ui', b'debug', pycompat.bytestr(bool(cmd_debug)))
3349
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    39
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    40
    check = ''
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    41
    if u.debugflag:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    42
        if not u.verbose or u.quiet:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    43
            check = ' *'
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    44
    elif u.verbose and u.quiet:
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    45
        check = ' +'
25d270e0b27f ui.py: untangle updateopts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    46
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    47
    print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    48
        (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    49
            '%2d  %5s %5s %5s   %5s %5s %5s  ->  %5s %5s %5s%s'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    50
            % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    51
                i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    52
                hgrc_quiet,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    53
                hgrc_verbose,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    54
                hgrc_debug,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    55
                cmd_quiet,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    56
                cmd_verbose,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    57
                cmd_debug,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    58
                u.quiet,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    59
                u.verbose,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    60
                u.debugflag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    61
                check,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    62
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    63
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37927
diff changeset
    64
    )