sapling/tests/integration/test-lookup.t
Jun Wu 7532a39624 codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:00 -08:00

89 lines
2.8 KiB
Perl

$ . $TESTDIR/library.sh
setup configuration
$ setup_mononoke_config
setup repo
$ cd $TESTTMP
$ hginit_treemanifest repo-hg
$ cd repo-hg
$ touch a
$ hg add a
$ hg ci -ma
$ touch b
$ hg add b
$ hg ci -ma
$ hg log
changeset: 1:f9ae6ef0865e
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: a
(re)
changeset: 0:3903775176ed
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: a
(re)
setup master bookmark
$ hg bookmark master_bookmark -r 3903775176ed
$ hg bookmark ffff775176ed42b1458a6281db4a0ccf4d9f287a
$ hg bookmark 3e19bf519e9af6c66edf28380101a92122cbea50
blobimport
$ cd $TESTTMP
$ blobimport repo-hg/.hg repo
start mononoke
$ mononoke
$ wait_for_mononoke $TESTTMP/repo
$ cd repo-hg
$ hg up -q 0
Helper script to test the lookup function
$ cat >> $TESTTMP/lookup.py <<EOF
> from edenscm.mercurial import registrar
> from edenscm.mercurial.node import bin
> from edenscm.mercurial import (bundle2, extensions)
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command('lookup', [], ('key'))
> def _lookup(ui, repo, key, **opts):
> treemanifestext = extensions.find('treemanifest')
> fallbackpath = treemanifestext.getfallbackpath(repo)
> with repo.connectionpool.get(fallbackpath) as conn:
> remote = conn.peer
> csid = remote.lookup(key)
> if b'not found' in csid:
> print(csid)
> EOF
Lookup non-existent hash
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup fffffffffffff6c66edf28380101a92122cbea50
remote: * DEBG Session with Mononoke started with uuid: * (glob)
abort: fffffffffffff6c66edf28380101a92122cbea50 not found!
[255]
Lookup existing hash
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup f9ae6ef0865e00431f2af076be6b680f75dd2777
remote: * DEBG Session with Mononoke started with uuid: * (glob)
Lookup non-existent bookmark
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup fake_bookmark
remote: * DEBG Session with Mononoke started with uuid: * (glob)
abort: fake_bookmark not found!
[255]
Lookup existing bookmark
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup master_bookmark
remote: * DEBG Session with Mononoke started with uuid: * (glob)
Lookup bookmark with hash name that exists as a hash (returns hash)
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup 3903775176ed42b1458a6281db4a0ccf4d9f287a
remote: * DEBG Session with Mononoke started with uuid: * (glob)
Lookup bookmark with hash name that doesn't exist as a hash (returns bookmark -> hash)
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup ffff775176ed42b1458a6281db4a0ccf4d9f287a
remote: * DEBG Session with Mononoke started with uuid: * (glob)