003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/zmq/tests
usr
/
local
/
lib
/
python3.8
/
site-packages
/
zmq
/
tests
/
π
..
π
__init__.py
(7.75 KB)
π
__pycache__
π
conftest.py
(40 B)
π
test_asyncio.py
(15.57 KB)
π
test_auth.py
(20.72 KB)
π
test_cffi_backend.py
(8.79 KB)
π
test_constants.py
(4.49 KB)
π
test_context.py
(12.1 KB)
π
test_cython.py
(1.03 KB)
π
test_decorators.py
(9.4 KB)
π
test_device.py
(6.02 KB)
π
test_draft.py
(1.42 KB)
π
test_error.py
(1.17 KB)
π
test_etc.py
(545 B)
π
test_future.py
(10.62 KB)
π
test_imports.py
(1.76 KB)
π
test_includes.py
(997 B)
π
test_ioloop.py
(3.84 KB)
π
test_log.py
(6.51 KB)
π
test_message.py
(11.68 KB)
π
test_monitor.py
(3 KB)
π
test_monqueue.py
(7.97 KB)
π
test_multipart.py
(941 B)
π
test_mypy.py
(1.57 KB)
π
test_pair.py
(1.24 KB)
π
test_poll.py
(7.17 KB)
π
test_proxy_steerable.py
(3.7 KB)
π
test_pubsub.py
(1.07 KB)
π
test_reqrep.py
(1.8 KB)
π
test_retry_eintr.py
(2.88 KB)
π
test_security.py
(8 KB)
π
test_socket.py
(23.09 KB)
π
test_ssh.py
(235 B)
π
test_version.py
(1.3 KB)
π
test_win32_shim.py
(1.68 KB)
π
test_z85.py
(2.15 KB)
π
test_zmqstream.py
(2.35 KB)
Editing: test_log.py
# encoding: utf-8 # Copyright (C) PyZMQ Developers # Distributed under the terms of the Modified BSD License. import logging import time from unittest import TestCase import zmq from zmq.log import handlers from zmq.utils.strtypes import b, u from zmq.tests import BaseZMQTestCase class TestPubLog(BaseZMQTestCase): iface = 'inproc://zmqlog' topic = 'zmq' @property def logger(self): # print dir(self) logger = logging.getLogger('zmqtest') logger.setLevel(logging.DEBUG) return logger def connect_handler(self, topic=None): topic = self.topic if topic is None else topic logger = self.logger pub, sub = self.create_bound_pair(zmq.PUB, zmq.SUB) handler = handlers.PUBHandler(pub) handler.setLevel(logging.DEBUG) handler.root_topic = topic logger.addHandler(handler) sub.setsockopt(zmq.SUBSCRIBE, b(topic)) time.sleep(0.1) return logger, handler, sub def test_init_iface(self): logger = self.logger ctx = self.context handler = handlers.PUBHandler(self.iface) self.assertFalse(handler.ctx is ctx) self.sockets.append(handler.socket) # handler.ctx.term() handler = handlers.PUBHandler(self.iface, self.context) self.sockets.append(handler.socket) self.assertTrue(handler.ctx is ctx) handler.setLevel(logging.DEBUG) handler.root_topic = self.topic logger.addHandler(handler) sub = ctx.socket(zmq.SUB) self.sockets.append(sub) sub.setsockopt(zmq.SUBSCRIBE, b(self.topic)) sub.connect(self.iface) import time time.sleep(0.25) msg1 = 'message' logger.info(msg1) (topic, msg2) = sub.recv_multipart() self.assertEqual(topic, b'zmq.INFO') self.assertEqual(msg2, b(msg1) + b'\n') logger.removeHandler(handler) def test_init_socket(self): pub, sub = self.create_bound_pair(zmq.PUB, zmq.SUB) logger = self.logger handler = handlers.PUBHandler(pub) handler.setLevel(logging.DEBUG) handler.root_topic = self.topic logger.addHandler(handler) self.assertTrue(handler.socket is pub) self.assertTrue(handler.ctx is pub.context) self.assertTrue(handler.ctx is self.context) sub.setsockopt(zmq.SUBSCRIBE, b(self.topic)) import time time.sleep(0.1) msg1 = 'message' logger.info(msg1) (topic, msg2) = sub.recv_multipart() self.assertEqual(topic, b'zmq.INFO') self.assertEqual(msg2, b(msg1) + b'\n') logger.removeHandler(handler) def test_root_topic(self): logger, handler, sub = self.connect_handler() handler.socket.bind(self.iface) sub2 = sub.context.socket(zmq.SUB) self.sockets.append(sub2) sub2.connect(self.iface) sub2.setsockopt(zmq.SUBSCRIBE, b'') handler.root_topic = b'twoonly' msg1 = 'ignored' logger.info(msg1) self.assertRaisesErrno(zmq.EAGAIN, sub.recv, zmq.NOBLOCK) topic, msg2 = sub2.recv_multipart() self.assertEqual(topic, b'twoonly.INFO') self.assertEqual(msg2, b(msg1) + b'\n') logger.removeHandler(handler) def test_blank_root_topic(self): logger, handler, sub_everything = self.connect_handler() sub_everything.setsockopt(zmq.SUBSCRIBE, b'') handler.socket.bind(self.iface) sub_only_info = sub_everything.context.socket(zmq.SUB) self.sockets.append(sub_only_info) sub_only_info.connect(self.iface) sub_only_info.setsockopt(zmq.SUBSCRIBE, b'INFO') handler.setRootTopic(b'') msg_debug = 'debug_message' logger.debug(msg_debug) self.assertRaisesErrno(zmq.EAGAIN, sub_only_info.recv, zmq.NOBLOCK) topic, msg_debug_response = sub_everything.recv_multipart() self.assertEqual(topic, b'DEBUG') msg_info = 'info_message' logger.info(msg_info) topic, msg_info_response_everything = sub_everything.recv_multipart() self.assertEqual(topic, b'INFO') topic, msg_info_response_onlyinfo = sub_only_info.recv_multipart() self.assertEqual(topic, b'INFO') self.assertEqual(msg_info_response_everything, msg_info_response_onlyinfo) logger.removeHandler(handler) def test_unicode_message(self): logger, handler, sub = self.connect_handler() base_topic = b(self.topic + '.INFO') for msg, expected in [ (u('hello'), [base_topic, b('hello\n')]), (u('hΓ©llo'), [base_topic, b('hΓ©llo\n')]), (u('tΓΈpic::hΓ©llo'), [base_topic + b('.tΓΈpic'), b('hΓ©llo\n')]), ]: logger.info(msg) received = sub.recv_multipart() self.assertEqual(received, expected) logger.removeHandler(handler) def test_set_info_formatter_via_property(self): logger, handler, sub = self.connect_handler() handler.formatters[logging.INFO] = logging.Formatter("%(message)s UNITTEST\n") handler.socket.bind(self.iface) sub.setsockopt(zmq.SUBSCRIBE, b(handler.root_topic)) logger.info('info message') topic, msg = sub.recv_multipart() self.assertEqual(msg, b'info message UNITTEST\n') logger.removeHandler(handler) def test_custom_global_formatter(self): logger, handler, sub = self.connect_handler() formatter = logging.Formatter("UNITTEST %(message)s") handler.setFormatter(formatter) handler.socket.bind(self.iface) sub.setsockopt(zmq.SUBSCRIBE, b(handler.root_topic)) logger.info('info message') topic, msg = sub.recv_multipart() self.assertEqual(msg, b'UNITTEST info message') logger.debug('debug message') topic, msg = sub.recv_multipart() self.assertEqual(msg, b'UNITTEST debug message') logger.removeHandler(handler) def test_custom_debug_formatter(self): logger, handler, sub = self.connect_handler() formatter = logging.Formatter("UNITTEST DEBUG %(message)s") handler.setFormatter(formatter, logging.DEBUG) handler.socket.bind(self.iface) sub.setsockopt(zmq.SUBSCRIBE, b(handler.root_topic)) logger.info('info message') topic, msg = sub.recv_multipart() self.assertEqual(msg, b'info message\n') logger.debug('debug message') topic, msg = sub.recv_multipart() self.assertEqual(msg, b'UNITTEST DEBUG debug message') logger.removeHandler(handler)
Upload File
Create Folder