'When a Deferred is returned from a callback directly attached to that
same Deferred, a warning is emitted.'

def test_circularChainWarning(self):

    d = defer.Deferred()
    def circularCallback(result):
        return d
    d.addCallback(circularCallback)
    d.callback('foo')
    circular_warnings = self.flushWarnings([circularCallback])
    self.assertEqual(len(circular_warnings), 1)
    warning = circular_warnings[0]
    self.assertEqual(warning['category'], DeprecationWarning)
    pattern = 'Callback    returned    the    Deferred    it    was    attached    to'
    self.assertTrue(re.search(pattern, warning['message']), ('\nExpected    match:    %r\nGot:    %r' % (pattern, warning['message'])))
