()
| 729 | |
| 730 | |
| 731 | def 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 | |
| 766 | def iterable_middleware(app): |
nothing calls this directly
no test coverage detected