MCPcopy
hub / github.com/pallets/werkzeug / test_run_wsgi_app_closing_iterator

Function test_run_wsgi_app_closing_iterator

tests/test_test.py:731–763  ·  tests/test_test.py::test_run_wsgi_app_closing_iterator
()

Source from the content-addressed store, hash-verified

729
730
731def test_run_wsgi_app_closing_iterator():
732 got_close = []
733
734 class CloseIter:
735 def __init__(self):
736 self.iterated = False
737
738 def __iter__(self):
739 return self
740
741 def close(self):
742 got_close.append(None)
743
744 def __next__(self):
745 if self.iterated:
746 raise StopIteration()
747 self.iterated = True
748 return class="st">"bar"
749
750 def bar(environ, start_response):
751 start_response(class="st">"200 OK", [(class="st">"Content-Type", class="st">"text/plain")])
752 return CloseIter()
753
754 app_iter, status, headers = run_wsgi_app(bar, {})
755 assert status == class="st">"200 OK"
756 assert list(headers) == [(class="st">"Content-Type", class="st">"text/plain")]
757 assert next(app_iter) == class="st">"bar"
758 pytest.raises(StopIteration, partial(next, app_iter))
759 app_iter.close()
760
761 assert run_wsgi_app(bar, {}, True)[0] == [class="st">"bar"]
762
763 assert len(got_close) == 2
764
765
766def iterable_middleware(app):

Callers

nothing calls this directly

Calls 3

run_wsgi_appFunction · 0.90
listFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected