diff options
Diffstat (limited to 'wsgiref/tests/__init__.py')
-rw-r--r-- | wsgiref/tests/__init__.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/wsgiref/tests/__init__.py b/wsgiref/tests/__init__.py new file mode 100644 index 0000000..6b482a0 --- /dev/null +++ b/wsgiref/tests/__init__.py @@ -0,0 +1,82 @@ +from unittest import TestSuite, TestCase, makeSuite + +def 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).""" + + it = make_it() + n = 0 + for item in match: + assert it[n]==item + n+=1 + try: + it[n] + except IndexError: + pass + else: + raise AssertionError("Too many items from __getitem__",it) + + try: + iter, StopIteration + except NameError: + pass + else: + # Only test iter mode under 2.2+ + it = make_it() + assert iter(it) is it + for item in match: + assert it.next()==item + try: + it.next() + except StopIteration: + pass + else: + raise AssertionError("Too many items from .next()",it) + + + + +def test_suite(): + + from wsgiref.tests import test_util + from wsgiref.tests import test_headers + from wsgiref.tests import test_handlers + + tests = [ + test_util.test_suite(), + test_headers.test_suite(), + test_handlers.test_suite(), + ] + + return TestSuite(tests) + + + + + + + + + + + + + + + + + + + + + + + + + + + + |