Skip to content

Commit b661f5c

Browse files
Automate tests.
1 parent da5aec2 commit b661f5c

21 files changed

+213
-52
lines changed

.hgignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ mod_wsgi/*.lo
1111
mod_wsgi/*.slo
1212

1313
mod_wsgi-docs/_build/*
14+
15+
mod_wsgi-tests/python2.X/*.pyc
16+
mod_wsgi-tests/python3.X/*.pyc

mod_wsgi-tests/python2.X/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TESTS = $(wildcard *.wsgi)
2+
3+
tests :
4+
@for file in $(TESTS); \
5+
do \
6+
echo $$file; \
7+
python -m doctest $$file; \
8+
done
9+
10+
clean :
11+
$(RM) *.pyc
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import httplib
3+
import re
4+
import time
5+
6+
host = 'wsgi-tests.example.com'
7+
port = '11111'
8+
9+
host = os.environ.get('WSGI_TESTS_HOST', host)
10+
port = int(os.environ.get('WSGI_TESTS_PORT', port))
11+
12+
log_file = '/var/log/apache2/%s-error_log' % host
13+
log_delay = '0.1'
14+
15+
log_file = os.environ.get('WSGI_TEST_LOG_FILE', log_file)
16+
log_delay = float(os.environ.get('WSGI_TEST_LOG_DELAY', log_delay))
17+
18+
def connection():
19+
connection = httplib.HTTPConnection(host, port)
20+
connection.connect()
21+
return connection
22+
23+
class Log(object):
24+
25+
def __init__(self, filename):
26+
self.__filename = filename
27+
self.__fp = open(self.__filename, 'r')
28+
self.__fp.seek(0, os.SEEK_END)
29+
self.__errors = None
30+
31+
def output(self, index):
32+
if not self.__errors is None:
33+
return self.__errors[index]
34+
time.sleep(1)
35+
self.__errors = []
36+
for line in self.__fp.readlines():
37+
match = re.match(r'(\[[^]]*\]) (\[[^]]*\]) (\[[^]]*\]) (.*)', line)
38+
if match:
39+
groups = match.groups()
40+
line = groups[1] + ' ' + groups[3]
41+
else:
42+
match = re.match(r'(\[[^]]*\]) (.*)', line)
43+
if match:
44+
groups = match.groups()
45+
line = groups[1]
46+
self.__errors.append(line)
47+
return self.__errors[index]
48+
49+
def messages():
50+
return Log(log_file)

mod_wsgi-tests/python2.X/dump_environ.wsgi

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> connection.putrequest('GET', '/dump_environ.wsgi')
6+
>>> connection.endheaders()
7+
>>> response = connection.getresponse()
8+
>>> response.status
9+
200
10+
11+
"""
12+
113
import cStringIO
214
import os
315

mod_wsgi-tests/python2.X/hello_world.wsgi

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> connection.putrequest('GET', '/hello_world.wsgi')
6+
>>> connection.endheaders()
7+
>>> response = connection.getresponse()
8+
>>> response.status
9+
200
10+
>>> response.getheader('Content-Length')
11+
'12'
12+
>>> response.read()
13+
'Hello World!'
14+
15+
"""
16+
117
def application(environ, start_response):
218
status = '200 OK'
319
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1a.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1a.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1a.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: status code is not a 3 digit integer'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = ''
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1b.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1b.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1b.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: status code is not a 3 digit integer'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = '20 OK'
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1c.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1c.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1c.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: status code is not a 3 digit integer'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = '2000 OK'
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1d.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1d.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1d.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: no space following status code'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = '200'
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1e.txt

-3
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1e.wsgi

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> connection.putrequest('GET', '/start_response-1e.wsgi')
6+
>>> connection.endheaders()
7+
>>> response = connection.getresponse()
8+
>>> response.status
9+
200
10+
>>> response.getheader('Content-Length')
11+
'12'
12+
>>> response.read()
13+
'Hello World!'
14+
15+
"""
16+
117
def application(environ, start_response):
218
status = '200 '
319
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1f.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1f.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1f.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: control character present in reason phrase'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = '200 OK\r\n\r\nXXXXXXXXXXXX'
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1g.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1g.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1g.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] ValueError: status code is not a 3 digit integer'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = 'XYZ OK'
318
output = 'Hello World!'

mod_wsgi-tests/python2.X/start_response-1h.txt

-7
This file was deleted.

mod_wsgi-tests/python2.X/start_response-1h.wsgi

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""
2+
3+
>>> import _testfuncs
4+
>>> connection = _testfuncs.connection()
5+
>>> messages = _testfuncs.messages()
6+
>>> connection.putrequest('GET', '/start_response-1h.wsgi')
7+
>>> connection.endheaders()
8+
>>> response = connection.getresponse()
9+
>>> response.status
10+
500
11+
>>> messages.output(-1)
12+
'[error] TypeError: expected byte string object, value of type NoneType found'
13+
14+
"""
15+
116
def application(environ, start_response):
217
status = None
318
output = 'Hello World!'

0 commit comments

Comments
 (0)