tests/test-hgwebdir-paths.py
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48875 6000f5b25c9b
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:
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
     1
import os
28932
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     2
from mercurial import (
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     3
    hg,
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     4
    ui as uimod,
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     5
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
     6
from mercurial.hgweb import hgwebdir_mod
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
     7
28932
4eac86331acb tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 15381
diff changeset
     8
hgwebdir = hgwebdir_mod.hgwebdir
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
     9
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    10
os.mkdir(b'webdir')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    11
os.chdir(b'webdir')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    12
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    13
webdir = os.path.realpath(b'.')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    14
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28932
diff changeset
    15
u = uimod.ui.load()
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    16
hg.repository(u, b'a', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    17
hg.repository(u, b'b', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    18
os.chdir(b'b')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    19
hg.repository(u, b'd', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    20
os.chdir(b'..')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    21
hg.repository(u, b'c', create=1)
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    22
os.chdir(b'..')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    23
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    24
paths = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    25
    b't/a/': b'%s/a' % webdir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    26
    b'b': b'%s/b' % webdir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    27
    b'coll': b'%s/*' % webdir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    28
    b'rcoll': b'%s/**' % webdir,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37879
diff changeset
    29
}
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    30
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    31
config = os.path.join(webdir, b'hgwebdir.conf')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    32
configfile = open(config, 'wb')
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    33
configfile.write(b'[paths]\n')
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    34
for k, v in paths.items():
37879
81455f482478 tests: port test-hgwebdir-paths.py to Python 3
Augie Fackler <augie@google.com>
parents: 30559
diff changeset
    35
    configfile.write(b'%s = %s\n' % (k, v))
8529
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    36
configfile.close()
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    37
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    38
confwd = hgwebdir(config)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    39
dictwd = hgwebdir(paths)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    40
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    41
assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    42
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    43
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    44
found = dict(confwd.repos)
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    45
for key, path in dictwd.repos:
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    46
    assert key in found, 'repository %s was not found' % key
a767998f0a78 hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff changeset
    47
    assert found[key] == path, 'different paths for repo %s' % key