Patchwork [6,of,7] get-with-headers: handle python3 bytes in stdout

login
register
mail settings
Submitter timeless
Date May 16, 2016, 5:56 p.m.
Message ID <CAAKMeYi2UkOyG3OarAgh5H62JSPzhDYZ6NQqU2pPYmDcf03P5A@mail.gmail.com>
Download mbox | patch
Permalink /patch/15150/
State Changes Requested, archived
Headers show

Comments

timeless - May 16, 2016, 5:56 p.m.
These tests fail w/o that change:
test-hgweb-bundle.t
test-hgweb-removed.t
test-hgweb-empty.t
test-hgweb-raw.t
test-hgweb-descend-empties.t
test-hgwebdirsym.t
test-hgweb-filelog.t
test-mq-qclone-http.t
test-hgweb-diffs.t
test-share.t
test-hgweb-symrev.t
test-hgwebdir.t
test-obsolete.t
test-largefiles.t

I think the answer is that even though the py2 print statement isn't
documented to call flush, it must be calling flush.

The command I'm using:
./run-tests.py --with-hg=~/bin/hg -j120 $X

(Where X is that set of files)

I guess that change should be split into a distinct commit.

Sample failure output:

ERROR: test-hgweb-bundle.t output changed

On Mon, May 16, 2016 at 7:33 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Wed, 11 May 2016 05:20:28 +0000, timeless wrote:
>> # HG changeset patch
>> # User timeless <timeless@mozdev.org>
>> # Date 1462561643 0
>> #      Fri May 06 19:07:23 2016 +0000
>> # Node ID 6849a6b26ea35775c142b78802b6b943dd2adf68
>> # Parent  67542cf802e8669a1c954c3066f468fe3ae6ba0e
>> # EXP-Topic runtests
>> # Available At bb://timeless/mercurial-crew
>> #              hg pull bb://timeless/mercurial-crew -r 6849a6b26ea3
>> get-with-headers: handle python3 bytes in stdout
>>
>> diff -r 67542cf802e8 -r 6849a6b26ea3 tests/get-with-headers.py
>> --- a/tests/get-with-headers.py       Fri May 06 19:06:05 2016 +0000
>> +++ b/tests/get-with-headers.py       Fri May 06 19:07:23 2016 +0000
>> @@ -17,6 +17,17 @@
>>  except ImportError:
>>      pass
>>
>> +try:
>> +    stdout = sys.stdout.buffer
>> +except AttributeError:
>> +    stdout = sys.stdout
>> +
>> +if sys.version_info[0] < 3:
>> +    sprint = print
>> +else:
>> +    def sprint(*s):
>> +        print(*s, file=sys.stdout, flush=True)
>
> Why do flush() only on Python 3 ?
>
> The commit message explains why we need "stdout = sys.stdout.buffer", but
> it says nothing about sprint().
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - May 17, 2016, 1:24 p.m.
On Mon, 16 May 2016 10:56:59 -0700, timeless wrote:
> These tests fail w/o that change:
> test-hgweb-bundle.t
> test-hgweb-removed.t
> test-hgweb-empty.t
> test-hgweb-raw.t
> test-hgweb-descend-empties.t
> test-hgwebdirsym.t
> test-hgweb-filelog.t
> test-mq-qclone-http.t
> test-hgweb-diffs.t
> test-share.t
> test-hgweb-symrev.t
> test-hgwebdir.t
> test-obsolete.t
> test-largefiles.t
> 
> I think the answer is that even though the py2 print statement isn't
> documented to call flush, it must be calling flush.
> 
> The command I'm using:
> ./run-tests.py --with-hg=~/bin/hg -j120 $X
> 
> (Where X is that set of files)
> 
> I guess that change should be split into a distinct commit.
> 
> Sample failure output:
> --- test-hgweb-bundle.t
> +++ test-hgweb-bundle.t.err
> @@ -28,10 +28,10 @@
>  Ensure we're serving from the bundle
> 
>    $ (get-with-headers.py localhost:$HGPORT 'file/tip/?style=raw')
> -  200 Script output follows
> -

That's because you use different io objects without flushing. The following
code works for me, thought it is ugly.

            sys.stdout.flush()
            sys.stdout.buffer.write(data)
            sys.stdout.buffer.flush()

I don't know the Python3 way, but we'd probably better use either text or
binary io consistently.

Patch

--- test-hgweb-bundle.t
+++ test-hgweb-bundle.t.err
@@ -28,10 +28,10 @@ 
 Ensure we're serving from the bundle

   $ (get-with-headers.py localhost:$HGPORT 'file/tip/?style=raw')
-  200 Script output follows
-

   -rw-r--r-- 2 bar
   -rw-r--r-- 2 foo


+  200 Script output follows
+