comparison tests/test-extension.t @ 36458:2218f5bfafca

py3: add b'' prefixes in tests/test-extension.t We are now close to getting this test pass on Python 3. # skip-blame because just b'' prefixes. Differential Revision: https://phab.mercurial-scm.org/D2478
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 27 Feb 2018 14:44:37 +0530
parents 4088e568a411
children 2208149c4b8e
comparison
equal deleted inserted replaced
36457:0e8b76644e20 36458:2218f5bfafca
5 > from mercurial import commands, registrar 5 > from mercurial import commands, registrar
6 > cmdtable = {} 6 > cmdtable = {}
7 > command = registrar.command(cmdtable) 7 > command = registrar.command(cmdtable)
8 > configtable = {} 8 > configtable = {}
9 > configitem = registrar.configitem(configtable) 9 > configitem = registrar.configitem(configtable)
10 > configitem('tests', 'foo', default="Foo") 10 > configitem(b'tests', b'foo', default=b"Foo")
11 > def uisetup(ui): 11 > def uisetup(ui):
12 > ui.write("uisetup called\\n") 12 > ui.write(b"uisetup called\\n")
13 > ui.flush() 13 > ui.flush()
14 > def reposetup(ui, repo): 14 > def reposetup(ui, repo):
15 > ui.write("reposetup called for %s\\n" % os.path.basename(repo.root)) 15 > ui.write(b"reposetup called for %s\\n" % os.path.basename(repo.root))
16 > ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!")) 16 > ui.write(b"ui %s= repo.ui\\n" % (ui == repo.ui and b"=" or b"!"))
17 > ui.flush() 17 > ui.flush()
18 > @command(b'foo', [], 'hg foo') 18 > @command(b'foo', [], b'hg foo')
19 > def foo(ui, *args, **kwargs): 19 > def foo(ui, *args, **kwargs):
20 > foo = ui.config('tests', 'foo') 20 > foo = ui.config(b'tests', b'foo')
21 > ui.write(foo) 21 > ui.write(foo)
22 > ui.write("\\n") 22 > ui.write(b"\\n")
23 > @command(b'bar', [], 'hg bar', norepo=True) 23 > @command(b'bar', [], b'hg bar', norepo=True)
24 > def bar(ui, *args, **kwargs): 24 > def bar(ui, *args, **kwargs):
25 > ui.write("Bar\\n") 25 > ui.write(b"Bar\\n")
26 > EOF 26 > EOF
27 $ abspath=`pwd`/foobar.py 27 $ abspath=`pwd`/foobar.py
28 28
29 $ mkdir barfoo 29 $ mkdir barfoo
30 $ cp foobar.py barfoo/__init__.py 30 $ cp foobar.py barfoo/__init__.py
438 > # real "module" object) might hide problem of succeeding import. 438 > # real "module" object) might hide problem of succeeding import.
439 > 439 >
440 > @command(b'showabsolute', [], norepo=True) 440 > @command(b'showabsolute', [], norepo=True)
441 > def showabsolute(ui, *args, **opts): 441 > def showabsolute(ui, *args, **opts):
442 > from absextroot import absolute 442 > from absextroot import absolute
443 > ui.write('ABS: %s\n' % '\nABS: '.join(absolute.getresult())) 443 > ui.write(b'ABS: %s\n' % '\nABS: '.join(absolute.getresult()))
444 > 444 >
445 > @command(b'showrelative', [], norepo=True) 445 > @command(b'showrelative', [], norepo=True)
446 > def showrelative(ui, *args, **opts): 446 > def showrelative(ui, *args, **opts):
447 > from . import relative 447 > from . import relative
448 > ui.write('REL: %s\n' % '\nREL: '.join(relative.getresult())) 448 > ui.write(b'REL: %s\n' % '\nREL: '.join(relative.getresult()))
449 > 449 >
450 > # import modules from external library 450 > # import modules from external library
451 > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused 451 > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused
452 > from extlibroot.lsub1.lsub2.called import func as lfunc 452 > from extlibroot.lsub1.lsub2.called import func as lfunc
453 > from extlibroot.recursedown import absdetail, legacydetail 453 > from extlibroot.recursedown import absdetail, legacydetail
562 > '''only debugcommands 562 > '''only debugcommands
563 > ''' 563 > '''
564 > from mercurial import registrar 564 > from mercurial import registrar
565 > cmdtable = {} 565 > cmdtable = {}
566 > command = registrar.command(cmdtable) 566 > command = registrar.command(cmdtable)
567 > @command(b'debugfoobar', [], 'hg debugfoobar') 567 > @command(b'debugfoobar', [], b'hg debugfoobar')
568 > def debugfoobar(ui, repo, *args, **opts): 568 > def debugfoobar(ui, repo, *args, **opts):
569 > "yet another debug command" 569 > "yet another debug command"
570 > pass 570 > pass
571 > @command(b'foo', [], 'hg foo') 571 > @command(b'foo', [], b'hg foo')
572 > def foo(ui, repo, *args, **opts): 572 > def foo(ui, repo, *args, **opts):
573 > """yet another foo command 573 > """yet another foo command
574 > This command has been DEPRECATED since forever. 574 > This command has been DEPRECATED since forever.
575 > """ 575 > """
576 > pass 576 > pass
803 > from mercurial import commands, registrar 803 > from mercurial import commands, registrar
804 > cmdtable = {} 804 > cmdtable = {}
805 > command = registrar.command(cmdtable) 805 > command = registrar.command(cmdtable)
806 > """multirevs extension 806 > """multirevs extension
807 > Big multi-line module docstring.""" 807 > Big multi-line module docstring."""
808 > @command(b'multirevs', [], 'ARG', norepo=True) 808 > @command(b'multirevs', [], b'ARG', norepo=True)
809 > def multirevs(ui, repo, arg, *args, **opts): 809 > def multirevs(ui, repo, arg, *args, **opts):
810 > """multirevs command""" 810 > """multirevs command"""
811 > pass 811 > pass
812 > EOF 812 > EOF
813 $ echo "multirevs = multirevs.py" >> $HGRCPATH 813 $ echo "multirevs = multirevs.py" >> $HGRCPATH
878 > writes 'Foo foo' 878 > writes 'Foo foo'
879 > """ 879 > """
880 > from mercurial import commands, registrar 880 > from mercurial import commands, registrar
881 > cmdtable = {} 881 > cmdtable = {}
882 > command = registrar.command(cmdtable) 882 > command = registrar.command(cmdtable)
883 > @command(b'dodo', [], 'hg dodo') 883 > @command(b'dodo', [], b'hg dodo')
884 > def dodo(ui, *args, **kwargs): 884 > def dodo(ui, *args, **kwargs):
885 > """Does nothing""" 885 > """Does nothing"""
886 > ui.write("I do nothing. Yay\\n") 886 > ui.write(b"I do nothing. Yay\\n")
887 > @command(b'foofoo', [], 'hg foofoo') 887 > @command(b'foofoo', [], b'hg foofoo')
888 > def foofoo(ui, *args, **kwargs): 888 > def foofoo(ui, *args, **kwargs):
889 > """Writes 'Foo foo'""" 889 > """Writes 'Foo foo'"""
890 > ui.write("Foo foo\\n") 890 > ui.write(b"Foo foo\\n")
891 > EOF 891 > EOF
892 $ dodopath=$TESTTMP/d/dodo.py 892 $ dodopath=$TESTTMP/d/dodo.py
893 893
894 $ echo "dodo = $dodopath" >> $HGRCPATH 894 $ echo "dodo = $dodopath" >> $HGRCPATH
895 895
989 > also writes 'Beep beep' 989 > also writes 'Beep beep'
990 > """ 990 > """
991 > from mercurial import commands, registrar 991 > from mercurial import commands, registrar
992 > cmdtable = {} 992 > cmdtable = {}
993 > command = registrar.command(cmdtable) 993 > command = registrar.command(cmdtable)
994 > @command(b'something', [], 'hg something') 994 > @command(b'something', [], b'hg something')
995 > def something(ui, *args, **kwargs): 995 > def something(ui, *args, **kwargs):
996 > """Does something""" 996 > """Does something"""
997 > ui.write("I do something. Yaaay\\n") 997 > ui.write(b"I do something. Yaaay\\n")
998 > @command(b'beep', [], 'hg beep') 998 > @command(b'beep', [], b'hg beep')
999 > def beep(ui, *args, **kwargs): 999 > def beep(ui, *args, **kwargs):
1000 > """Writes 'Beep beep'""" 1000 > """Writes 'Beep beep'"""
1001 > ui.write("Beep beep\\n") 1001 > ui.write(b"Beep beep\\n")
1002 > EOF 1002 > EOF
1003 $ dudupath=$TESTTMP/d/dudu.py 1003 $ dudupath=$TESTTMP/d/dudu.py
1004 1004
1005 $ echo "dudu = $dudupath" >> $HGRCPATH 1005 $ echo "dudu = $dudupath" >> $HGRCPATH
1006 1006
1233 $ cat > throw.py <<EOF 1233 $ cat > throw.py <<EOF
1234 > from mercurial import commands, registrar, util 1234 > from mercurial import commands, registrar, util
1235 > cmdtable = {} 1235 > cmdtable = {}
1236 > command = registrar.command(cmdtable) 1236 > command = registrar.command(cmdtable)
1237 > class Bogon(Exception): pass 1237 > class Bogon(Exception): pass
1238 > @command(b'throw', [], 'hg throw', norepo=True) 1238 > @command(b'throw', [], b'hg throw', norepo=True)
1239 > def throw(ui, **opts): 1239 > def throw(ui, **opts):
1240 > """throws an exception""" 1240 > """throws an exception"""
1241 > raise Bogon() 1241 > raise Bogon()
1242 > EOF 1242 > EOF
1243 1243
1276 ** Extensions loaded: throw 1276 ** Extensions loaded: throw
1277 1277
1278 If the extensions declare outdated versions, accuse the older extension first: 1278 If the extensions declare outdated versions, accuse the older extension first:
1279 $ echo "from mercurial import util" >> older.py 1279 $ echo "from mercurial import util" >> older.py
1280 $ echo "util.version = lambda:'2.2'" >> older.py 1280 $ echo "util.version = lambda:'2.2'" >> older.py
1281 $ echo "testedwith = '1.9.3'" >> older.py 1281 $ echo "testedwith = b'1.9.3'" >> older.py
1282 $ echo "testedwith = '2.1.1'" >> throw.py 1282 $ echo "testedwith = b'2.1.1'" >> throw.py
1283 $ rm -f throw.pyc throw.pyo 1283 $ rm -f throw.pyc throw.pyo
1284 $ rm -Rf __pycache__ 1284 $ rm -Rf __pycache__
1285 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \ 1285 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \
1286 > throw 2>&1 | egrep '^\*\*' 1286 > throw 2>&1 | egrep '^\*\*'
1287 ** Unknown exception encountered with possibly-broken third-party extension older 1287 ** Unknown exception encountered with possibly-broken third-party extension older
1291 ** Python * (glob) 1291 ** Python * (glob)
1292 ** Mercurial Distributed SCM (version 2.2) 1292 ** Mercurial Distributed SCM (version 2.2)
1293 ** Extensions loaded: throw, older 1293 ** Extensions loaded: throw, older
1294 1294
1295 One extension only tested with older, one only with newer versions: 1295 One extension only tested with older, one only with newer versions:
1296 $ echo "util.version = lambda:'2.1'" >> older.py 1296 $ echo "util.version = lambda:b'2.1'" >> older.py
1297 $ rm -f older.pyc older.pyo 1297 $ rm -f older.pyc older.pyo
1298 $ rm -Rf __pycache__ 1298 $ rm -Rf __pycache__
1299 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \ 1299 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \
1300 > throw 2>&1 | egrep '^\*\*' 1300 > throw 2>&1 | egrep '^\*\*'
1301 ** Unknown exception encountered with possibly-broken third-party extension older 1301 ** Unknown exception encountered with possibly-broken third-party extension older
1305 ** Python * (glob) 1305 ** Python * (glob)
1306 ** Mercurial Distributed SCM (version 2.1) 1306 ** Mercurial Distributed SCM (version 2.1)
1307 ** Extensions loaded: throw, older 1307 ** Extensions loaded: throw, older
1308 1308
1309 Older extension is tested with current version, the other only with newer: 1309 Older extension is tested with current version, the other only with newer:
1310 $ echo "util.version = lambda:'1.9.3'" >> older.py 1310 $ echo "util.version = lambda:b'1.9.3'" >> older.py
1311 $ rm -f older.pyc older.pyo 1311 $ rm -f older.pyc older.pyo
1312 $ rm -Rf __pycache__ 1312 $ rm -Rf __pycache__
1313 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \ 1313 $ hg --config extensions.throw=throw.py --config extensions.older=older.py \
1314 > throw 2>&1 | egrep '^\*\*' 1314 > throw 2>&1 | egrep '^\*\*'
1315 ** Unknown exception encountered with possibly-broken third-party extension throw 1315 ** Unknown exception encountered with possibly-broken third-party extension throw
1343 ** Python * (glob) 1343 ** Python * (glob)
1344 ** Mercurial Distributed SCM (*) (glob) 1344 ** Mercurial Distributed SCM (*) (glob)
1345 ** Extensions loaded: throw 1345 ** Extensions loaded: throw
1346 1346
1347 Patch version is ignored during compatibility check 1347 Patch version is ignored during compatibility check
1348 $ echo "testedwith = '3.2'" >> throw.py 1348 $ echo "testedwith = b'3.2'" >> throw.py
1349 $ echo "util.version = lambda:'3.2.2'" >> throw.py 1349 $ echo "util.version = lambda:b'3.2.2'" >> throw.py
1350 $ rm -f throw.pyc throw.pyo 1350 $ rm -f throw.pyc throw.pyo
1351 $ rm -Rf __pycache__ 1351 $ rm -Rf __pycache__
1352 $ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*' 1352 $ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
1353 ** unknown exception encountered, please report by visiting 1353 ** unknown exception encountered, please report by visiting
1354 ** https://mercurial-scm.org/wiki/BugTracker 1354 ** https://mercurial-scm.org/wiki/BugTracker
1436 1436
1437 Refuse to load extensions with minimum version requirements 1437 Refuse to load extensions with minimum version requirements
1438 1438
1439 $ cat > minversion1.py << EOF 1439 $ cat > minversion1.py << EOF
1440 > from mercurial import util 1440 > from mercurial import util
1441 > util.version = lambda: '3.5.2' 1441 > util.version = lambda: b'3.5.2'
1442 > minimumhgversion = '3.6' 1442 > minimumhgversion = b'3.6'
1443 > EOF 1443 > EOF
1444 $ hg --config extensions.minversion=minversion1.py version 1444 $ hg --config extensions.minversion=minversion1.py version
1445 (third party extension minversion requires version 3.6 or newer of Mercurial; disabling) 1445 (third party extension minversion requires version 3.6 or newer of Mercurial; disabling)
1446 Mercurial Distributed SCM (version 3.5.2) 1446 Mercurial Distributed SCM (version 3.5.2)
1447 (see https://mercurial-scm.org for more information) 1447 (see https://mercurial-scm.org for more information)
1450 This is free software; see the source for copying conditions. There is NO 1450 This is free software; see the source for copying conditions. There is NO
1451 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1451 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1452 1452
1453 $ cat > minversion2.py << EOF 1453 $ cat > minversion2.py << EOF
1454 > from mercurial import util 1454 > from mercurial import util
1455 > util.version = lambda: '3.6' 1455 > util.version = lambda: b'3.6'
1456 > minimumhgversion = '3.7' 1456 > minimumhgversion = b'3.7'
1457 > EOF 1457 > EOF
1458 $ hg --config extensions.minversion=minversion2.py version 2>&1 | egrep '\(third' 1458 $ hg --config extensions.minversion=minversion2.py version 2>&1 | egrep '\(third'
1459 (third party extension minversion requires version 3.7 or newer of Mercurial; disabling) 1459 (third party extension minversion requires version 3.7 or newer of Mercurial; disabling)
1460 1460
1461 Can load version that is only off by point release 1461 Can load version that is only off by point release
1462 1462
1463 $ cat > minversion2.py << EOF 1463 $ cat > minversion2.py << EOF
1464 > from mercurial import util 1464 > from mercurial import util
1465 > util.version = lambda: '3.6.1' 1465 > util.version = lambda: b'3.6.1'
1466 > minimumhgversion = '3.6' 1466 > minimumhgversion = b'3.6'
1467 > EOF 1467 > EOF
1468 $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third' 1468 $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
1469 [1] 1469 [1]
1470 1470
1471 Can load minimum version identical to current 1471 Can load minimum version identical to current
1472 1472
1473 $ cat > minversion3.py << EOF 1473 $ cat > minversion3.py << EOF
1474 > from mercurial import util 1474 > from mercurial import util
1475 > util.version = lambda: '3.5' 1475 > util.version = lambda: b'3.5'
1476 > minimumhgversion = '3.5' 1476 > minimumhgversion = b'3.5'
1477 > EOF 1477 > EOF
1478 $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third' 1478 $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
1479 [1] 1479 [1]
1480 1480
1481 Restore HGRCPATH 1481 Restore HGRCPATH
1490 $ cd reposetup-test 1490 $ cd reposetup-test
1491 1491
1492 $ cat > $TESTTMP/reposetuptest.py <<EOF 1492 $ cat > $TESTTMP/reposetuptest.py <<EOF
1493 > from mercurial import extensions 1493 > from mercurial import extensions
1494 > def reposetup(ui, repo): 1494 > def reposetup(ui, repo):
1495 > ui.write('reposetup() for %s\n' % (repo.root)) 1495 > ui.write(b'reposetup() for %s\n' % (repo.root))
1496 > ui.flush() 1496 > ui.flush()
1497 > EOF 1497 > EOF
1498 $ hg init src 1498 $ hg init src
1499 $ echo a > src/a 1499 $ echo a > src/a
1500 $ hg -R src commit -Am '#0 at src/a' 1500 $ hg -R src commit -Am '#0 at src/a'
1624 1624
1625 $ cat <<EOF > deprecatedcmd.py 1625 $ cat <<EOF > deprecatedcmd.py
1626 > def deprecatedcmd(repo, ui): 1626 > def deprecatedcmd(repo, ui):
1627 > pass 1627 > pass
1628 > cmdtable = { 1628 > cmdtable = {
1629 > 'deprecatedcmd': (deprecatedcmd, [], ''), 1629 > b'deprecatedcmd': (deprecatedcmd, [], b''),
1630 > } 1630 > }
1631 > EOF 1631 > EOF
1632 $ cat <<EOF > .hg/hgrc 1632 $ cat <<EOF > .hg/hgrc
1633 > [extensions] 1633 > [extensions]
1634 > deprecatedcmd = `pwd`/deprecatedcmd.py 1634 > deprecatedcmd = `pwd`/deprecatedcmd.py
1661 > def uisetup(ui): 1661 > def uisetup(ui):
1662 > synopsis = ' GREPME [--foo] [-x]' 1662 > synopsis = ' GREPME [--foo] [-x]'
1663 > docstring = ''' 1663 > docstring = '''
1664 > GREPME make sure that this is in the help! 1664 > GREPME make sure that this is in the help!
1665 > ''' 1665 > '''
1666 > extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks, 1666 > extensions.wrapcommand(commands.table, b'bookmarks', exbookmarks,
1667 > synopsis, docstring) 1667 > synopsis, docstring)
1668 > EOF 1668 > EOF
1669 $ abspath=`pwd`/exthelp.py 1669 $ abspath=`pwd`/exthelp.py
1670 $ echo '[extensions]' >> $HGRCPATH 1670 $ echo '[extensions]' >> $HGRCPATH
1671 $ echo "exthelp = $abspath" >> $HGRCPATH 1671 $ echo "exthelp = $abspath" >> $HGRCPATH
1696 1696
1697 $ cat > $TESTTMP/test_unicode_default_value.py << EOF 1697 $ cat > $TESTTMP/test_unicode_default_value.py << EOF
1698 > from mercurial import registrar 1698 > from mercurial import registrar
1699 > cmdtable = {} 1699 > cmdtable = {}
1700 > command = registrar.command(cmdtable) 1700 > command = registrar.command(cmdtable)
1701 > @command('dummy', [('', 'opt', u'value', u'help')], 'ext [OPTIONS]') 1701 > @command(b'dummy', [('', 'opt', u'value', u'help')], 'ext [OPTIONS]')
1702 > def ext(*args, **opts): 1702 > def ext(*args, **opts):
1703 > print(opts['opt']) 1703 > print(opts['opt'])
1704 > EOF 1704 > EOF
1705 $ cat > $TESTTMP/opt-unicode-default/.hg/hgrc << EOF 1705 $ cat > $TESTTMP/opt-unicode-default/.hg/hgrc << EOF
1706 > [extensions] 1706 > [extensions]