tests/test-hgweb-non-interactive.t
author Matt Harbison <matt_harbison@yahoo.com>
Sun, 30 Sep 2018 01:15:46 -0400
changeset 39913 8bd589aecf65
parent 39707 5abc47d4ca6b
child 40203 f80f7a67e176
permissions -rw-r--r--
py3: avoid b'' output in test-hgweb-non-interactive.t I couldn't figure out how to get the list to print without b'' with pycompat.write(), without converted each element to str.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     1
Tests if hgweb can run without touching sys.stdin, as is required
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     2
by the WSGI standard and strictly implemented by mod_wsgi.
5337
8c5ef3b87cb1 Don't try to determine interactivity if ui() called with interactive=False.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     3
13956
ffb5c09ba822 tests: remove redundant mkdir
Martin Geisler <mg@lazybytes.net>
parents: 12743
diff changeset
     4
  $ hg init repo
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     5
  $ cd repo
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     6
  $ echo foo > bar
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     7
  $ hg add bar
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     8
  $ hg commit -m "test"
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     9
  $ cat > request.py <<EOF
28859
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    10
  > from __future__ import absolute_import
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    11
  > import os
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    12
  > import sys
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    13
  > from mercurial import (
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    14
  >     dispatch,
39913
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    15
  >     encoding,
28859
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    16
  >     hg,
39913
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    17
  >     pycompat,
28859
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    18
  >     ui as uimod,
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28859
diff changeset
    19
  >     util,
28859
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    20
  > )
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    21
  > ui = uimod.ui
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    22
  > from mercurial.hgweb.hgweb_mod import (
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    23
  >     hgweb,
af2e00c85d0a py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents: 26247
diff changeset
    24
  > )
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28859
diff changeset
    25
  > stringio = util.stringio
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    26
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    27
  > class FileLike(object):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    28
  >     def __init__(self, real):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    29
  >         self.real = real
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    30
  >     def fileno(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    31
  >         print >> sys.__stdout__, 'FILENO'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    32
  >         return self.real.fileno()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    33
  >     def read(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    34
  >         print >> sys.__stdout__, 'READ'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    35
  >         return self.real.read()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    36
  >     def readline(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    37
  >         print >> sys.__stdout__, 'READLINE'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    38
  >         return self.real.readline()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    39
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    40
  > sys.stdin = FileLike(sys.stdin)
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28859
diff changeset
    41
  > errors = stringio()
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28859
diff changeset
    42
  > input = stringio()
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28859
diff changeset
    43
  > output = stringio()
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    44
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    45
  > def startrsp(status, headers):
33720
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    46
  >     print('---- STATUS')
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    47
  >     print(status)
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    48
  >     print('---- HEADERS')
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    49
  >     print([i for i in headers if i[0] != 'ETag'])
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    50
  >     print('---- DATA')
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    51
  >     return output.write
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    52
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    53
  > env = {
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    54
  >     'wsgi.version': (1, 0),
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    55
  >     'wsgi.url_scheme': 'http',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    56
  >     'wsgi.errors': errors,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    57
  >     'wsgi.input': input,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    58
  >     'wsgi.multithread': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    59
  >     'wsgi.multiprocess': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    60
  >     'wsgi.run_once': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    61
  >     'REQUEST_METHOD': 'GET',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    62
  >     'SCRIPT_NAME': '',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    63
  >     'PATH_INFO': '',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    64
  >     'QUERY_STRING': '',
31008
636cf3f7620d tests: use LOCALIP
Jun Wu <quark@fb.com>
parents: 28861
diff changeset
    65
  >     'SERVER_NAME': '$LOCALIP',
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    66
  >     'SERVER_PORT': os.environ['HGPORT'],
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    67
  >     'SERVER_PROTOCOL': 'HTTP/1.0'
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    68
  > }
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    69
  > 
39658
c20861b65688 py3: add b'' prefixes in tests/test-hgweb-non-interactive.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 33720
diff changeset
    70
  > i = hgweb(b'.')
26247
7df5d4760873 hgweb: consume generator inside context manager (issue4756)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26220
diff changeset
    71
  > for c in i(env, startrsp):
7df5d4760873 hgweb: consume generator inside context manager (issue4756)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26220
diff changeset
    72
  >     pass
39913
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    73
  > sys.stdout.flush()
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    74
  > pycompat.stdout.write(b'---- ERRORS\n')
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    75
  > pycompat.stdout.write(b'%s\n' % errors.getvalue())
33720
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    76
  > print('---- OS.ENVIRON wsgi variables')
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    77
  > print(sorted([x for x in os.environ if x.startswith('wsgi')]))
27fb986e54d0 tests: fix simple heredoc print statements to work on Py3
Augie Fackler <augie@google.com>
parents: 32940
diff changeset
    78
  > print('---- request.ENVIRON wsgi variables')
26220
a43328baa2ac hgweb: use separate repo instances per thread
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26219
diff changeset
    79
  > with i._obtainrepo() as repo:
39913
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    80
  >     print(sorted([encoding.strfromlocal(x) for x in repo.ui.environ
8bd589aecf65 py3: avoid b'' output in test-hgweb-non-interactive.t
Matt Harbison <matt_harbison@yahoo.com>
parents: 39707
diff changeset
    81
  >                   if x.startswith(b'wsgi')]))
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    82
  > EOF
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39658
diff changeset
    83
  $ "$PYTHON" request.py
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    84
  ---- STATUS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    85
  200 Script output follows
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    86
  ---- HEADERS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    87
  [('Content-Type', 'text/html; charset=ascii')]
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    88
  ---- DATA
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    89
  ---- ERRORS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    90
  
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    91
  ---- OS.ENVIRON wsgi variables
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    92
  []
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    93
  ---- request.ENVIRON wsgi variables
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    94
  ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13956
diff changeset
    95
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13956
diff changeset
    96
  $ cd ..