/usr/share/doc/python-amqplib-doc/examples/tests/client_0_8/test_with.py is in python-amqplib-doc 1.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #!/usr/bin/env python
"""
Test support for 'with' statements in Python >= 2.5
"""
# Copyright (C) 2009 Barry Pederson <bp@barryp.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
from __future__ import with_statement
import unittest
import settings
from amqplib.client_0_8 import Connection, Message
class TestChannel(unittest.TestCase):
def test_with(self):
with Connection(**settings.connect_args) as conn:
self.assertEqual(conn.transport is None, False)
with conn.channel(1) as ch:
self.assertEqual(1 in conn.channels, True)
#
# Do something with the channel
#
ch.access_request('/data', active=True, write=True)
ch.exchange_declare('unittest.fanout', 'fanout', auto_delete=True)
msg = Message('unittest message',
content_type='text/plain',
application_headers={'foo': 7, 'bar': 'baz'})
ch.basic_publish(msg, 'unittest.fanout')
#
# check that the channel was closed
#
self.assertEqual(1 in conn.channels, False)
self.assertEqual(ch.is_open, False)
#
# Check that the connection was closed
#
self.assertEqual(conn.transport, None)
def main():
suite = unittest.TestLoader().loadTestsFromTestCase(TestChannel)
unittest.TextTestRunner(**settings.test_args).run(suite)
if __name__ == '__main__':
main()
|