sapling/eden/scm/tests/test-atexit-epipe.t
Adam Simpkins 3723a1a0b1 fix invalid buffering setting in some tests
Summary:
Update a test that was attempting to call `os.fdopen()` in binary mode with
line buffering.  Line buffering is only valid on files opened in text mode.
Python 3.8 now emits a warning about this invalid call, which causes the test
to fail.  Switch the test to use unbuffered mode.

Reviewed By: pixelb

Differential Revision: D20484844

fbshipit-source-id: 3bedfa3f0fb7926ad3ab3b6ea85716d0e1b603c3
2020-03-17 11:07:50 -07:00

54 lines
1.6 KiB
Perl

#chg-compatible
$ cat > a.py << EOF
> import os
> def uisetup(ui):
> # make the test slightly more interesting
> ui.fout = os.fdopen(ui.fout.fileno(), "wb", 0)
> @ui.atexit
> def printlines():
> ui.write("line1\n")
> ui.write("line2\n" * 10000) # probably triggers EPIPE or SIGPIPE
> open("executed-here1", "w").close()
> EOF
This should not trigger StdioError (IOError), or BrokenPipeError (OSError):
$ hg --config extensions.a=a.py init foo1 | head -1
line1
'executed-here1' should exist to indicate the execution flow:
$ [ -f executed-here1 ]
Try again, using a pager:
$ cat > b.py << EOF
> import os
> def uisetup(ui):
> ui.fout = os.fdopen(ui.fout.fileno(), "wb", 0)
> @ui.atexit
> def printlines():
> # This is hacky. But it makes sure pager is running.
> # Using --pager=always is not enough, because killpager is also
> # an atexit handler and gets executed before this one.
> ui.pager("internal-always-atexit")
> # Redo signal.signal(signal.SIGPIPE, signal.SIG_IGN) called by
> # _runexithandlers.
> import signal
> signal.signal(signal.SIGPIPE, signal.SIG_IGN)
> ui.write("line1\n")
> ui.write("line2\n" * 10000) # probably triggers EPIPE or SIGPIPE
> open("executed-here2", "w").close()
> EOF
This should not raise SignalInterrupt (KeyboardInterrupt):
$ hg --config extensions.b=b.py --config 'pager.pager=head -1' init foo2
line1
'executed-here2' should exist to indicate the execution flow:
$ [ -f executed-here2 ]