'If the application object returns an iterator which also has a I{close}
method, that method is called after iteration is complete.'

def test_close(self):

    channel = DummyChannel()
    class Result:
        def __init__(self):
            self.open = True
        def __iter__(self):
            for i in range(3):
                if self.open:
                    (yield intToBytes(i))
        def close(self):
            self.open = False
    result = Result()
    def applicationFactory():
        def application(environ, startResponse):
            startResponse('200    OK', [('content-length', '3')])
            return result
        return application
    (d, requestFactory) = self.requestFactoryFactory()
    def cbRendered(ignored):
        self.assertEqual(self.getContentFromResponse(channel.transport.written.getvalue()), '012')
        self.assertFalse(result.open)
    d.addCallback(cbRendered)
    self.lowLevelRender(requestFactory, applicationFactory, (lambda : channel), 'GET', '1.1', [], [''])
    return d
