##// END OF EJS Templates
py3: use absolute_import in test-hgweb-non-interactive.t
timeless -
r28859:af2e00c8 default
parent child Browse files
Show More
@@ -1,84 +1,91 b''
1 1 Tests if hgweb can run without touching sys.stdin, as is required
2 2 by the WSGI standard and strictly implemented by mod_wsgi.
3 3
4 4 $ hg init repo
5 5 $ cd repo
6 6 $ echo foo > bar
7 7 $ hg add bar
8 8 $ hg commit -m "test"
9 9 $ cat > request.py <<EOF
10 > from mercurial import dispatch
11 > from mercurial.hgweb.hgweb_mod import hgweb
12 > from mercurial.ui import ui
13 > from mercurial import hg
10 > from __future__ import absolute_import
11 > import os
12 > import sys
14 13 > from StringIO import StringIO
15 > import os, sys
14 > from mercurial import (
15 > dispatch,
16 > hg,
17 > ui as uimod,
18 > )
19 > ui = uimod.ui
20 > from mercurial.hgweb.hgweb_mod import (
21 > hgweb,
22 > )
16 23 >
17 24 > class FileLike(object):
18 25 > def __init__(self, real):
19 26 > self.real = real
20 27 > def fileno(self):
21 28 > print >> sys.__stdout__, 'FILENO'
22 29 > return self.real.fileno()
23 30 > def read(self):
24 31 > print >> sys.__stdout__, 'READ'
25 32 > return self.real.read()
26 33 > def readline(self):
27 34 > print >> sys.__stdout__, 'READLINE'
28 35 > return self.real.readline()
29 36 >
30 37 > sys.stdin = FileLike(sys.stdin)
31 38 > errors = StringIO()
32 39 > input = StringIO()
33 40 > output = StringIO()
34 41 >
35 42 > def startrsp(status, headers):
36 43 > print '---- STATUS'
37 44 > print status
38 45 > print '---- HEADERS'
39 46 > print [i for i in headers if i[0] != 'ETag']
40 47 > print '---- DATA'
41 48 > return output.write
42 49 >
43 50 > env = {
44 51 > 'wsgi.version': (1, 0),
45 52 > 'wsgi.url_scheme': 'http',
46 53 > 'wsgi.errors': errors,
47 54 > 'wsgi.input': input,
48 55 > 'wsgi.multithread': False,
49 56 > 'wsgi.multiprocess': False,
50 57 > 'wsgi.run_once': False,
51 58 > 'REQUEST_METHOD': 'GET',
52 59 > 'SCRIPT_NAME': '',
53 60 > 'PATH_INFO': '',
54 61 > 'QUERY_STRING': '',
55 62 > 'SERVER_NAME': '127.0.0.1',
56 63 > 'SERVER_PORT': os.environ['HGPORT'],
57 64 > 'SERVER_PROTOCOL': 'HTTP/1.0'
58 65 > }
59 66 >
60 67 > i = hgweb('.')
61 68 > for c in i(env, startrsp):
62 69 > pass
63 70 > print '---- ERRORS'
64 71 > print errors.getvalue()
65 72 > print '---- OS.ENVIRON wsgi variables'
66 73 > print sorted([x for x in os.environ if x.startswith('wsgi')])
67 74 > print '---- request.ENVIRON wsgi variables'
68 75 > with i._obtainrepo() as repo:
69 76 > print sorted([x for x in repo.ui.environ if x.startswith('wsgi')])
70 77 > EOF
71 78 $ python request.py
72 79 ---- STATUS
73 80 200 Script output follows
74 81 ---- HEADERS
75 82 [('Content-Type', 'text/html; charset=ascii')]
76 83 ---- DATA
77 84 ---- ERRORS
78 85
79 86 ---- OS.ENVIRON wsgi variables
80 87 []
81 88 ---- request.ENVIRON wsgi variables
82 89 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
83 90
84 91 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now