[PATCH 5 of 5 V3] tests: check that procutil.std{out,err}.write() returns correct result
Yuya Nishihara
yuya at tcha.org
Wed Jul 15 12:32:23 UTC 2020
On Wed, 15 Jul 2020 14:23:17 +0200, Manuel Jacob wrote:
> On 2020-07-15 13:14, Yuya Nishihara wrote:
> > On Tue, 14 Jul 2020 20:41:51 +0200, Manuel Jacob wrote:
> >> # HG changeset patch
> >> # User Manuel Jacob <me at manueljacob.de>
> >> # Date 1594291924 -7200
> >> # Thu Jul 09 12:52:04 2020 +0200
> >> # Node ID b2aabfc8d6800bf6e103b783a245c45e3b1ae4ac
> >> # Parent 49ebcf3b048c7352a4c32b1fd6c793ab99aec246
> >> # EXP-Topic stdio
> >> tests: check that procutil.std{out,err}.write() returns correct result
> >
> >> -procutil.{stream}.write(b'x' * 1048576)
> >> +write_result = procutil.{stream}.write(b'x' * 1048576)
> >> +with open({write_result_fn}, 'w') as write_result_f:
> >> + write_result_f.write(str(write_result))
> >
> > Nit: {write_result_fn!r} can be used instead of repr().
> >
> >> + # tempfile.mktemp() is unsafe in general, as a malicious
> >> process
> >> + # could create the file before we do. But in tests, we're
> >> running
> >> + # in a controlled environment.
> >> + write_result_fn = tempfile.mktemp()
> >
> > Even so, I think it's better to not use deprecated function which may
> > be
> > deleted in future version.
>
> According to the module documentation, the file created by the more
> secure (for general use) variants can’t be opened twice, but that’s
> exactly the functionality we need. For this reason, I don’t think
> tempfile.mktemp() will be deleted. But I can try to find some hack.
IIUC, we can just create an empty temp file (and close it immediately)
to reserve the file name.
More information about the Mercurial-devel
mailing list