Mercurial > hg
comparison tests/test-hook.t @ 37754:9bbb13c0f982
tests: port inline extensions in test-hook.t to py3
This test *almost* passes now, but some import errors print very
differently in ways that seem at least somewhat important.
Differential Revision: https://phab.mercurial-scm.org/D3363
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 13 Apr 2018 23:58:13 -0400 |
parents | f450a3be62ec |
children | 89ba51c3e4f1 |
comparison
equal
deleted
inserted
replaced
37753:f450a3be62ec | 37754:9bbb13c0f982 |
---|---|
1 commit hooks can see env vars | 1 commit hooks can see env vars |
2 (and post-transaction one are run unlocked) | 2 (and post-transaction one are run unlocked) |
3 | 3 |
4 | 4 |
5 $ cat > $TESTTMP/txnabort.checkargs.py <<EOF | 5 $ cat > $TESTTMP/txnabort.checkargs.py <<EOF |
6 > from mercurial import pycompat | |
6 > def showargs(ui, repo, hooktype, **kwargs): | 7 > def showargs(ui, repo, hooktype, **kwargs): |
7 > ui.write('%s Python hook: %s\n' % (hooktype, ','.join(sorted(kwargs)))) | 8 > kwargs = pycompat.byteskwargs(kwargs) |
9 > ui.write(b'%s Python hook: %s\n' % (hooktype, | |
10 > b','.join(sorted(kwargs)))) | |
8 > EOF | 11 > EOF |
9 | 12 |
10 $ hg init a | 13 $ hg init a |
11 $ cd a | 14 $ cd a |
12 $ cat > .hg/hgrc <<EOF | 15 $ cat > .hg/hgrc <<EOF |
408 | 411 |
409 $ cd "$TESTTMP/b" | 412 $ cd "$TESTTMP/b" |
410 | 413 |
411 $ cat > hooktests.py <<EOF | 414 $ cat > hooktests.py <<EOF |
412 > from __future__ import print_function | 415 > from __future__ import print_function |
413 > from mercurial import error | 416 > from mercurial import ( |
417 > error, | |
418 > pycompat, | |
419 > ) | |
414 > | 420 > |
415 > uncallable = 0 | 421 > uncallable = 0 |
416 > | 422 > |
417 > def printargs(ui, args): | 423 > def printargs(ui, args): |
418 > a = list(args.items()) | 424 > a = list(pycompat.byteskwargs(args).items()) |
419 > a.sort() | 425 > a.sort() |
420 > ui.write(b'hook args:\n') | 426 > ui.write(b'hook args:\n') |
421 > for k, v in a: | 427 > for k, v in a: |
422 > ui.write(b' %s %s\n' % (k, v)) | 428 > ui.write(b' %s %s\n' % (k, v)) |
423 > | 429 > |
430 > | 436 > |
431 > class LocalException(Exception): | 437 > class LocalException(Exception): |
432 > pass | 438 > pass |
433 > | 439 > |
434 > def raisehook(**args): | 440 > def raisehook(**args): |
435 > raise LocalException(b'exception from hook') | 441 > raise LocalException('exception from hook') |
436 > | 442 > |
437 > def aborthook(**args): | 443 > def aborthook(**args): |
438 > raise error.Abort(b'raise abort from hook') | 444 > raise error.Abort(b'raise abort from hook') |
439 > | 445 > |
440 > def brokenhook(**args): | 446 > def brokenhook(**args): |
628 $ hg init c | 634 $ hg init c |
629 $ cd c | 635 $ cd c |
630 | 636 |
631 $ cat > hookext.py <<EOF | 637 $ cat > hookext.py <<EOF |
632 > def autohook(ui, **args): | 638 > def autohook(ui, **args): |
633 > ui.write('Automatically installed hook\n') | 639 > ui.write(b'Automatically installed hook\n') |
634 > | 640 > |
635 > def reposetup(ui, repo): | 641 > def reposetup(ui, repo): |
636 > repo.ui.setconfig("hooks", "commit.auto", autohook) | 642 > repo.ui.setconfig(b"hooks", b"commit.auto", autohook) |
637 > EOF | 643 > EOF |
638 $ echo '[extensions]' >> .hg/hgrc | 644 $ echo '[extensions]' >> .hg/hgrc |
639 $ echo 'hookext = hookext.py' >> .hg/hgrc | 645 $ echo 'hookext = hookext.py' >> .hg/hgrc |
640 | 646 |
641 $ touch foo | 647 $ touch foo |