Back to index

python3.2  3.2.2
Classes | Functions
test.test_wsgiref Namespace Reference

Classes

class  MockServer
class  MockHandler
class  IntegrationTests
class  UtilityTests
class  HeaderTests
class  ErrorHandler
class  TestHandler
class  HandlerTests

Functions

def hello_app
def run_amock
def compare_generic_iter
def test_main

Function Documentation

def test.test_wsgiref.compare_generic_iter (   make_it,
  match 
)
Utility to compare a generic 2.1/2.2+ iterator with an iterable

If running under Python 2.2+, this tests the iterator using iter()/next(),
as well as __getitem__.  'make_it' must be a function returning a fresh
iterator to be tested (since this may test the iterator twice).

Definition at line 88 of file test_wsgiref.py.

00088 
00089 def compare_generic_iter(make_it,match):
00090     """Utility to compare a generic 2.1/2.2+ iterator with an iterable
00091 
00092     If running under Python 2.2+, this tests the iterator using iter()/next(),
00093     as well as __getitem__.  'make_it' must be a function returning a fresh
00094     iterator to be tested (since this may test the iterator twice)."""
00095 
00096     it = make_it()
00097     n = 0
00098     for item in match:
00099         if not it[n]==item: raise AssertionError
00100         n+=1
00101     try:
00102         it[n]
00103     except IndexError:
00104         pass
00105     else:
00106         raise AssertionError("Too many items from __getitem__",it)
00107 
00108     try:
00109         iter, StopIteration
00110     except NameError:
00111         pass
00112     else:
00113         # Only test iter mode under 2.2+
00114         it = make_it()
00115         if not iter(it) is it: raise AssertionError
00116         for item in match:
00117             if not next(it) == item: raise AssertionError
00118         try:
00119             next(it)
00120         except StopIteration:
00121             pass
00122         else:
00123             raise AssertionError("Too many items from .__next__()", it)
00124 
00125 
00126 
00127 
00128 

Here is the caller graph for this function:

def test.test_wsgiref.hello_app (   environ,
  start_response 
)

Definition at line 45 of file test_wsgiref.py.

00045 
00046 def hello_app(environ,start_response):
00047     start_response("200 OK", [
00048         ('Content-Type','text/plain'),
00049         ('Date','Mon, 05 Jun 2006 18:49:54 GMT')
00050     ])
00051     return [b"Hello, world!"]

def test.test_wsgiref.run_amock (   app = hello_app,
  data = b"GET / HTTP/1.0\n\n" 
)

Definition at line 52 of file test_wsgiref.py.

00052 
00053 def run_amock(app=hello_app, data=b"GET / HTTP/1.0\n\n"):
00054     server = make_server("", 80, app, MockServer, MockHandler)
00055     inp = BufferedReader(BytesIO(data))
00056     out = BytesIO()
00057     olderr = sys.stderr
00058     err = sys.stderr = StringIO()
00059 
00060     try:
00061         server.finish_request((inp, out), ("127.0.0.1",8888))
00062     finally:
00063         sys.stderr = olderr
00064 
00065     return out.getvalue(), err.getvalue()
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 661 of file test_wsgiref.py.

00661 
00662 def test_main():
00663     support.run_unittest(__name__)