author | Simon Sapin <simon.sapin@octobus.net> |
Fri, 10 Sep 2021 09:53:09 +0200 | |
changeset 47955 | e834b79def74 |
parent 45055 | 4c1b4805db57 |
child 48876 | 42d2b31cee0b |
permissions | -rw-r--r-- |
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, |
af2e00c85d0a
py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents:
26247
diff
changeset
|
17 |
> ui as uimod, |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28859
diff
changeset
|
18 |
> util, |
28859
af2e00c85d0a
py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents:
26247
diff
changeset
|
19 |
> ) |
45055
4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents:
40203
diff
changeset
|
20 |
> from mercurial.utils import ( |
4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents:
40203
diff
changeset
|
21 |
> procutil, |
4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents:
40203
diff
changeset
|
22 |
> ) |
28859
af2e00c85d0a
py3: use absolute_import in test-hgweb-non-interactive.t
timeless <timeless@mozdev.org>
parents:
26247
diff
changeset
|
23 |
> ui = uimod.ui |
40203
f80f7a67e176
tests: fix style issue of importing hgweb in embedded code fragments
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
39913
diff
changeset
|
24 |
> from mercurial.hgweb import hgweb_mod |
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 | 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 |
> |
40203
f80f7a67e176
tests: fix style issue of importing hgweb in embedded code fragments
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
39913
diff
changeset
|
70 |
> i = hgweb_mod.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() |
45055
4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents:
40203
diff
changeset
|
74 |
> procutil.stdout.write(b'---- ERRORS\n') |
4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents:
40203
diff
changeset
|
75 |
> procutil.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 .. |