comparison tests/test-commandserver.t @ 40355:77ab5fbdbbf0

py3: use bprint() helper in test-commandserver.t
author Yuya Nishihara <yuya@tcha.org>
date Tue, 16 Oct 2018 07:38:31 +0200
parents f9f2faf25fc4
children 756e9b1084fd
comparison
equal deleted inserted replaced
40354:f9f2faf25fc4 40355:77ab5fbdbbf0
11 $ mv $HGRCPATH.new $HGRCPATH 11 $ mv $HGRCPATH.new $HGRCPATH
12 12
13 $ hg init repo 13 $ hg init repo
14 $ cd repo 14 $ cd repo
15 15
16 >>> from __future__ import absolute_import, print_function 16 >>> from __future__ import absolute_import
17 >>> import os 17 >>> import os
18 >>> import sys 18 >>> import sys
19 >>> from hgclient import check, readchannel, runcommand 19 >>> from hgclient import bprint, check, readchannel, runcommand
20 >>> @check 20 >>> @check
21 ... def hellomessage(server): 21 ... def hellomessage(server):
22 ... ch, data = readchannel(server) 22 ... ch, data = readchannel(server)
23 ... print(b'%c, %r' % (ch, data)) 23 ... bprint(b'%c, %r' % (ch, data))
24 ... # run an arbitrary command to make sure the next thing the server 24 ... # run an arbitrary command to make sure the next thing the server
25 ... # sends isn't part of the hello message 25 ... # sends isn't part of the hello message
26 ... runcommand(server, [b'id']) 26 ... runcommand(server, [b'id'])
27 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 27 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
28 *** runcommand id 28 *** runcommand id
91 000000000000 tip 91 000000000000 tip
92 *** runcommand id -runknown 92 *** runcommand id -runknown
93 abort: unknown revision 'unknown'! 93 abort: unknown revision 'unknown'!
94 [255] 94 [255]
95 95
96 >>> from hgclient import check, readchannel 96 >>> from hgclient import bprint, check, readchannel
97 >>> @check 97 >>> @check
98 ... def inputeof(server): 98 ... def inputeof(server):
99 ... readchannel(server) 99 ... readchannel(server)
100 ... server.stdin.write(b'runcommand\n') 100 ... server.stdin.write(b'runcommand\n')
101 ... # close stdin while server is waiting for input 101 ... # close stdin while server is waiting for input
102 ... server.stdin.close() 102 ... server.stdin.close()
103 ... 103 ...
104 ... # server exits with 1 if the pipe closed while reading the command 104 ... # server exits with 1 if the pipe closed while reading the command
105 ... print(b'server exit code =', server.wait()) 105 ... bprint(b'server exit code =', b'%d' % server.wait())
106 server exit code = 1 106 server exit code = 1
107 107
108 >>> from hgclient import check, readchannel, runcommand, stringio 108 >>> from hgclient import check, readchannel, runcommand, stringio
109 >>> @check 109 >>> @check
110 ... def serverinput(server): 110 ... def serverinput(server):
233 #else 233 #else
234 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH" 234 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
235 #endif 235 #endif
236 236
237 $ cat <<EOF > hook.py 237 $ cat <<EOF > hook.py
238 > from __future__ import print_function
239 > import sys 238 > import sys
239 > from hgclient import bprint
240 > def hook(**args): 240 > def hook(**args):
241 > print(b'hook talking') 241 > bprint(b'hook talking')
242 > print(b'now try to read something: %r' % sys.stdin.read()) 242 > bprint(b'now try to read something: %r' % sys.stdin.read())
243 > EOF 243 > EOF
244 244
245 >>> from hgclient import check, readchannel, runcommand, stringio 245 >>> from hgclient import check, readchannel, runcommand, stringio
246 >>> @check 246 >>> @check
247 ... def hookoutput(server): 247 ... def hookoutput(server):
279 summary: 2 279 summary: 2
280 280
281 *** runcommand status 281 *** runcommand status
282 282
283 >>> import os 283 >>> import os
284 >>> from hgclient import check, readchannel, runcommand 284 >>> from hgclient import bprint, check, readchannel, runcommand
285 >>> @check 285 >>> @check
286 ... def bookmarks(server): 286 ... def bookmarks(server):
287 ... readchannel(server) 287 ... readchannel(server)
288 ... runcommand(server, [b'bookmarks']) 288 ... runcommand(server, [b'bookmarks'])
289 ... 289 ...
300 ... f = open('a', 'ab') 300 ... f = open('a', 'ab')
301 ... f.write(b'a\n') and None 301 ... f.write(b'a\n') and None
302 ... f.close() 302 ... f.close()
303 ... runcommand(server, [b'commit', b'-Amm']) 303 ... runcommand(server, [b'commit', b'-Amm'])
304 ... runcommand(server, [b'bookmarks']) 304 ... runcommand(server, [b'bookmarks'])
305 ... print(b'') 305 ... bprint(b'')
306 *** runcommand bookmarks 306 *** runcommand bookmarks
307 no bookmarks set 307 no bookmarks set
308 *** runcommand bookmarks 308 *** runcommand bookmarks
309 bm1 1:d3a0a68be6de 309 bm1 1:d3a0a68be6de
310 bm2 1:d3a0a68be6de 310 bm2 1:d3a0a68be6de
344 3: draft 344 3: draft
345 *** runcommand phase -r . 345 *** runcommand phase -r .
346 3: public 346 3: public
347 347
348 $ echo a >> a 348 $ echo a >> a
349 >>> from hgclient import check, readchannel, runcommand 349 >>> from hgclient import bprint, check, readchannel, runcommand
350 >>> @check 350 >>> @check
351 ... def rollback(server): 351 ... def rollback(server):
352 ... readchannel(server) 352 ... readchannel(server)
353 ... runcommand(server, [b'phase', b'-r', b'.', b'-p']) 353 ... runcommand(server, [b'phase', b'-r', b'.', b'-p'])
354 ... runcommand(server, [b'commit', b'-Am.']) 354 ... runcommand(server, [b'commit', b'-Am.'])
355 ... runcommand(server, [b'rollback']) 355 ... runcommand(server, [b'rollback'])
356 ... runcommand(server, [b'phase', b'-r', b'.']) 356 ... runcommand(server, [b'phase', b'-r', b'.'])
357 ... print(b'') 357 ... bprint(b'')
358 *** runcommand phase -r . -p 358 *** runcommand phase -r . -p
359 no phases changed 359 no phases changed
360 *** runcommand commit -Am. 360 *** runcommand commit -Am.
361 *** runcommand rollback 361 *** runcommand rollback
362 repository tip rolled back to revision 3 (undo commit) 362 repository tip rolled back to revision 3 (undo commit)
383 marked working directory as branch default 383 marked working directory as branch default
384 (branches are permanent and global, did you want a bookmark?) 384 (branches are permanent and global, did you want a bookmark?)
385 385
386 $ touch .hgignore 386 $ touch .hgignore
387 >>> import os 387 >>> import os
388 >>> from hgclient import check, readchannel, runcommand 388 >>> from hgclient import bprint, check, readchannel, runcommand
389 >>> @check 389 >>> @check
390 ... def hgignore(server): 390 ... def hgignore(server):
391 ... readchannel(server) 391 ... readchannel(server)
392 ... runcommand(server, [b'commit', b'-Am.']) 392 ... runcommand(server, [b'commit', b'-Am.'])
393 ... f = open('ignored-file', 'ab') 393 ... f = open('ignored-file', 'ab')
395 ... f.close() 395 ... f.close()
396 ... f = open('.hgignore', 'ab') 396 ... f = open('.hgignore', 'ab')
397 ... f.write(b'ignored-file') 397 ... f.write(b'ignored-file')
398 ... f.close() 398 ... f.close()
399 ... runcommand(server, [b'status', b'-i', b'-u']) 399 ... runcommand(server, [b'status', b'-i', b'-u'])
400 ... print(b'') 400 ... bprint(b'')
401 *** runcommand commit -Am. 401 *** runcommand commit -Am.
402 adding .hgignore 402 adding .hgignore
403 *** runcommand status -i -u 403 *** runcommand status -i -u
404 I ignored-file 404 I ignored-file
405 405
406 406
407 cache of non-public revisions should be invalidated on repository change 407 cache of non-public revisions should be invalidated on repository change
408 (issue4855): 408 (issue4855):
409 409
410 >>> import os 410 >>> import os
411 >>> from hgclient import check, readchannel, runcommand 411 >>> from hgclient import bprint, check, readchannel, runcommand
412 >>> @check 412 >>> @check
413 ... def phasesetscacheaftercommit(server): 413 ... def phasesetscacheaftercommit(server):
414 ... readchannel(server) 414 ... readchannel(server)
415 ... # load _phasecache._phaserevs and _phasesets 415 ... # load _phasecache._phaserevs and _phasesets
416 ... runcommand(server, [b'log', b'-qr', b'draft()']) 416 ... runcommand(server, [b'log', b'-qr', b'draft()'])
421 ... f.write(b'a\n') and None 421 ... f.write(b'a\n') and None
422 ... f.close() 422 ... f.close()
423 ... os.system('hg commit -Aqm%d' % i) 423 ... os.system('hg commit -Aqm%d' % i)
424 ... # new commits should be listed as draft revisions 424 ... # new commits should be listed as draft revisions
425 ... runcommand(server, [b'log', b'-qr', b'draft()']) 425 ... runcommand(server, [b'log', b'-qr', b'draft()'])
426 ... print(b'') 426 ... bprint(b'')
427 *** runcommand log -qr draft() 427 *** runcommand log -qr draft()
428 4:7966c8e3734d 428 4:7966c8e3734d
429 *** runcommand log -qr draft() 429 *** runcommand log -qr draft()
430 4:7966c8e3734d 430 4:7966c8e3734d
431 5:41f6602d1c4f 431 5:41f6602d1c4f
432 6:10501e202c35 432 6:10501e202c35
433 433
434 434
435 >>> import os 435 >>> import os
436 >>> from hgclient import check, readchannel, runcommand 436 >>> from hgclient import bprint, check, readchannel, runcommand
437 >>> @check 437 >>> @check
438 ... def phasesetscacheafterstrip(server): 438 ... def phasesetscacheafterstrip(server):
439 ... readchannel(server) 439 ... readchannel(server)
440 ... # load _phasecache._phaserevs and _phasesets 440 ... # load _phasecache._phaserevs and _phasesets
441 ... runcommand(server, [b'log', b'-qr', b'draft()']) 441 ... runcommand(server, [b'log', b'-qr', b'draft()'])
442 ... # strip cached revisions by another process 442 ... # strip cached revisions by another process
443 ... os.system('hg --config extensions.strip= strip -q 5') 443 ... os.system('hg --config extensions.strip= strip -q 5')
444 ... # shouldn't abort by "unknown revision '6'" 444 ... # shouldn't abort by "unknown revision '6'"
445 ... runcommand(server, [b'log', b'-qr', b'draft()']) 445 ... runcommand(server, [b'log', b'-qr', b'draft()'])
446 ... print(b'') 446 ... bprint(b'')
447 *** runcommand log -qr draft() 447 *** runcommand log -qr draft()
448 4:7966c8e3734d 448 4:7966c8e3734d
449 5:41f6602d1c4f 449 5:41f6602d1c4f
450 6:10501e202c35 450 6:10501e202c35
451 *** runcommand log -qr draft() 451 *** runcommand log -qr draft()
666 stdout should be redirected to stderr 666 stdout should be redirected to stderr
667 667
668 668
669 run commandserver in commandserver, which is silly but should work: 669 run commandserver in commandserver, which is silly but should work:
670 670
671 >>> from __future__ import print_function 671 >>> from hgclient import bprint, check, readchannel, runcommand, stringio
672 >>> from hgclient import check, readchannel, runcommand, stringio
673 >>> @check 672 >>> @check
674 ... def nested(server): 673 ... def nested(server):
675 ... print(b'%c, %r' % readchannel(server)) 674 ... bprint(b'%c, %r' % readchannel(server))
676 ... class nestedserver(object): 675 ... class nestedserver(object):
677 ... stdin = stringio(b'getencoding\n') 676 ... stdin = stringio(b'getencoding\n')
678 ... stdout = stringio() 677 ... stdout = stringio()
679 ... runcommand(server, [b'serve', b'--cmdserver', b'pipe'], 678 ... runcommand(server, [b'serve', b'--cmdserver', b'pipe'],
680 ... output=nestedserver.stdout, input=nestedserver.stdin) 679 ... output=nestedserver.stdout, input=nestedserver.stdin)
681 ... nestedserver.stdout.seek(0) 680 ... nestedserver.stdout.seek(0)
682 ... print(b'%c, %r' % readchannel(nestedserver)) # hello 681 ... bprint(b'%c, %r' % readchannel(nestedserver)) # hello
683 ... print(b'%c, %r' % readchannel(nestedserver)) # getencoding 682 ... bprint(b'%c, %r' % readchannel(nestedserver)) # getencoding
684 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 683 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
685 *** runcommand serve --cmdserver pipe 684 *** runcommand serve --cmdserver pipe
686 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 685 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
687 r, '*' (glob) 686 r, '*' (glob)
688 687
689 688
690 start without repository: 689 start without repository:
691 690
692 $ cd .. 691 $ cd ..
693 692
694 >>> from __future__ import print_function 693 >>> from hgclient import bprint, check, readchannel, runcommand
695 >>> from hgclient import check, readchannel, runcommand
696 >>> @check 694 >>> @check
697 ... def hellomessage(server): 695 ... def hellomessage(server):
698 ... ch, data = readchannel(server) 696 ... ch, data = readchannel(server)
699 ... print(b'%c, %r' % (ch, data)) 697 ... bprint(b'%c, %r' % (ch, data))
700 ... # run an arbitrary command to make sure the next thing the server 698 ... # run an arbitrary command to make sure the next thing the server
701 ... # sends isn't part of the hello message 699 ... # sends isn't part of the hello message
702 ... runcommand(server, [b'id']) 700 ... runcommand(server, [b'id'])
703 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 701 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
704 *** runcommand id 702 *** runcommand id
730 $ cd repo 728 $ cd repo
731 $ hg update -q 729 $ hg update -q
732 730
733 #if unix-socket unix-permissions 731 #if unix-socket unix-permissions
734 732
735 >>> from __future__ import print_function 733 >>> from hgclient import bprint, check, readchannel, runcommand, stringio, unixserver
736 >>> from hgclient import check, readchannel, runcommand, stringio, unixserver
737 >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log') 734 >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log')
738 >>> def hellomessage(conn): 735 >>> def hellomessage(conn):
739 ... ch, data = readchannel(conn) 736 ... ch, data = readchannel(conn)
740 ... print(b'%c, %r' % (ch, data)) 737 ... bprint(b'%c, %r' % (ch, data))
741 ... runcommand(conn, [b'id']) 738 ... runcommand(conn, [b'id'])
742 >>> check(hellomessage, server.connect) 739 >>> check(hellomessage, server.connect)
743 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob) 740 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
744 *** runcommand id 741 *** runcommand id
745 eff892de26ec tip bm1/bm2/bm3 742 eff892de26ec tip bm1/bm2/bm3
782 779
783 $ cat <<EOF >> .hg/hgrc 780 $ cat <<EOF >> .hg/hgrc
784 > [cmdserver] 781 > [cmdserver]
785 > log = inexistent/path.log 782 > log = inexistent/path.log
786 > EOF 783 > EOF
787 >>> from __future__ import print_function 784 >>> from hgclient import bprint, check, readchannel, unixserver
788 >>> from hgclient import check, readchannel, unixserver
789 >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log') 785 >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log')
790 >>> def earlycrash(conn): 786 >>> def earlycrash(conn):
791 ... while True: 787 ... while True:
792 ... try: 788 ... try:
793 ... ch, data = readchannel(conn) 789 ... ch, data = readchannel(conn)
794 ... if not data.startswith(b' '): 790 ... if not data.startswith(b' '):
795 ... print(b'%c, %r' % (ch, data)) 791 ... bprint(b'%c, %r' % (ch, data))
796 ... except EOFError: 792 ... except EOFError:
797 ... break 793 ... break
798 >>> check(earlycrash, server.connect) 794 >>> check(earlycrash, server.connect)
799 e, 'Traceback (most recent call last):\n' 795 e, 'Traceback (most recent call last):\n'
800 e, "IOError: *" (glob) 796 e, "IOError: *" (glob)