tests/test-hgwebdir-paths.py
author Arseniy Alekseyev <aalekseyev@janestreet.com>
Mon, 04 Sep 2023 13:33:32 +0100
branchstable
changeset 50930 5dc7e1907e48
parent 48875 6000f5b25c9b
permissions -rw-r--r--
setup: make the error "Unable to find a working hg binary" more informative The error message now shows the attempted hg commands and their stderr, to make it easier to investigate why things are not working. Here's an example output /!\ /!\ Unable to find a working hg binary /!\ Version cannot be extracted from the repository /!\ Re-run the setup once a first version is built /!\ Attempts: /!\ attempt #0: /!\ cmd: ['hg-missing', 'log', '-r.', '-Ttest'] /!\ exception: [Errno 2] No such file or directory: 'hg-missing': 'hg-missing' /!\ attempt #1: /!\ cmd: ['/usr/bin/python3', 'hg', 'log', '-r.', '-Ttest'] /!\ return code: 255 /!\ std output: /!\ std error: *** failed to import extension "topic": No module named 'topic' *** failed to import extension "evolve": No module named 'evolve' abort: accessing `dirstate-v2` repository without associated fast implementation. (check `hg help config.format.use-dirstate-v2` for details) /!\ /!\ Could not determine the Mercurial version /!\ You need to build a local version first /!\ Run `make local` and try again /!\

import os
from mercurial import (
    hg,
    ui as uimod,
)
from mercurial.hgweb import hgwebdir_mod

hgwebdir = hgwebdir_mod.hgwebdir

os.mkdir(b'webdir')
os.chdir(b'webdir')

webdir = os.path.realpath(b'.')

u = uimod.ui.load()
hg.repository(u, b'a', create=1)
hg.repository(u, b'b', create=1)
os.chdir(b'b')
hg.repository(u, b'd', create=1)
os.chdir(b'..')
hg.repository(u, b'c', create=1)
os.chdir(b'..')

paths = {
    b't/a/': b'%s/a' % webdir,
    b'b': b'%s/b' % webdir,
    b'coll': b'%s/*' % webdir,
    b'rcoll': b'%s/**' % webdir,
}

config = os.path.join(webdir, b'hgwebdir.conf')
configfile = open(config, 'wb')
configfile.write(b'[paths]\n')
for k, v in paths.items():
    configfile.write(b'%s = %s\n' % (k, v))
configfile.close()

confwd = hgwebdir(config)
dictwd = hgwebdir(paths)

assert len(confwd.repos) == len(dictwd.repos), 'different numbers'
assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos)

found = dict(confwd.repos)
for key, path in dictwd.repos:
    assert key in found, 'repository %s was not found' % key
    assert found[key] == path, 'different paths for repo %s' % key