Commit 82f8f6f6 authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 2.0.10.1

parent 412d4291
......@@ -52,9 +52,9 @@ copyright = u'2010, Brian E. Granger'
# built documents.
#
# The short X.Y version.
version = '0.1'
version = '2.0.10.1'
# The full version, including alpha/beta/rc tags.
release = '0.1'
release = '2.0.10.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
......
......@@ -24,6 +24,7 @@
#-----------------------------------------------------------------------------
import os, sys
from traceback import print_exc
from distutils.core import setup, Command
from distutils.ccompiler import get_default_compiler
......@@ -35,6 +36,11 @@ from unittest import TextTestRunner, TestLoader
from glob import glob
from os.path import splitext, basename, join as pjoin
try:
import nose
except ImportError:
nose = None
try:
from os.path import walk
except:
......@@ -49,7 +55,7 @@ except:
if get_default_compiler() in ('unix', 'mingw32'):
ignore_common_warnings=True
else:
ignore_common_warnings=True
ignore_common_warnings=False
release = False # flag for whether to include *.c in package_data
......@@ -67,18 +73,41 @@ class TestCommand(Command):
def finalize_options(self):
pass
def run(self):
"""Finds all the tests modules in zmq/tests/, and runs them."""
def run_nose(self):
"""Run the test suite with nose."""
return nose.core.TestProgram(argv=["", '-vvs', pjoin(self._dir, 'zmq', 'tests')])
def run_unittest(self):
"""Finds all the tests modules in zmq/tests/ and runs them."""
testfiles = [ ]
for t in glob(pjoin(self._dir, 'zmq', 'tests', '*.py')):
if not t.endswith('__init__.py'):
name = splitext(basename(t))[0]
if name.startswith('test_'):
testfiles.append('.'.join(
['zmq.tests', splitext(basename(t))[0]])
['zmq.tests', name])
)
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity = 2)
t.run(tests)
def run(self):
"""Run the test suite, with nose, or unittest if nose is unavailable"""
# crude check for inplace build:
try:
import zmq
except ImportError:
print_exc()
print ("Could not import zmq!")
print ("You must build pyzmq with 'python setup.py build_ext --inplace' for 'python setup.py test' to work.")
print ("If you did build pyzmq in-place, then this is a real error.")
sys.exit(1)
if nose is None:
print ("nose unavailable, falling back on unittest. Skipped tests will appear as ERRORs.")
return self.run_unittest()
else:
return self.run_nose()
class CleanCommand(Command):
......@@ -254,7 +283,7 @@ the ZeroMQ library (http://www.zeromq.org).
setup(
name = "pyzmq",
version = "2.0.10",
version = "2.0.10.1",
packages = ['zmq', 'zmq.tests', 'zmq.eventloop', 'zmq.log', 'zmq.core',
'zmq.devices', 'zmq.utils'],
ext_modules = extensions,
......
......@@ -23,10 +23,6 @@
# Imports
#-----------------------------------------------------------------------------
# from libc.stdlib cimport free,malloc
from cpython cimport bool
#-----------------------------------------------------------------------------
# Import the C header files
#-----------------------------------------------------------------------------
......
......@@ -23,7 +23,6 @@
# Imports
#-----------------------------------------------------------------------------
from cpython cimport bool
from czmq cimport zmq_msg_t
#-----------------------------------------------------------------------------
......@@ -44,7 +43,7 @@ cdef class Message:
cdef object _data # The actual message data as a Python object.
cdef object _buffer # A Python Buffer/View of the message contents
cdef object _bytes # A bytes/str copy of the message.
cdef bool _failed_init # Flag to handle failed zmq_msg_init
cdef bint _failed_init # Flag to handle failed zmq_msg_init
cdef public object tracker_queue # Queue for use with zmq_free_fn.
cdef public object tracker # MessageTracker object.
......
......@@ -31,7 +31,6 @@ from libc.stdlib cimport free, malloc
from cpython cimport PyBytes_FromStringAndSize
from cpython cimport PyBytes_AsString, PyBytes_Size
from cpython cimport Py_DECREF, Py_INCREF
from cpython cimport bool
from allocate cimport allocate
from buffers cimport asbuffer_r, frombuffer_r, viewfromobject_r
......@@ -490,7 +489,9 @@ cdef class Socket:
rc = zmq_recv(self.handle, &zmq_msg, flags)
if rc != 0:
raise ZMQError()
return copy_zmq_msg_bytes(&zmq_msg)
msg_bytes = copy_zmq_msg_bytes(&zmq_msg)
zmq_msg_close(&zmq_msg)
return msg_bytes
def send_multipart(self, msg_parts, int flags=0, copy=True, track=False):
"""s.send_multipart(msg_parts, flags=0, copy=True, track=False)
......
......@@ -29,7 +29,7 @@ from czmq cimport _zmq_version
# Code
#-----------------------------------------------------------------------------
__version__ = '2.0.10'
__version__ = '2.0.10.1'
def pyzmq_version():
......
......@@ -83,7 +83,7 @@ def monitored_queue(Socket in_socket, Socket out_socket, Socket mon_socket,
cdef void *mons=mon_socket.handle
cdef zmq_msg_t in_msg
cdef zmq_msg_t out_msg
cdef bool swap_ids
cdef bint swap_ids
cdef char *msg_c = NULL
cdef Py_ssize_t msg_c_len
cdef int rc
......
......@@ -24,6 +24,7 @@ import time
import traceback
from zmq.eventloop import stack_context
from zmq.utils.strtypes import asbytes
try:
import signal
......@@ -338,7 +339,7 @@ class IOLoop(object):
def _wake(self):
try:
self._waker_writer.write("x")
self._waker_writer.write(asbytes("x"))
except IOError:
pass
......@@ -363,9 +364,10 @@ class IOLoop(object):
logging.error("Exception in callback %r", callback, exc_info=True)
def _read_waker(self, fd, events):
s=None
try:
while True:
self._waker_reader.read()
while True and s is None:
s = self._waker_reader.read()
except IOError:
pass
......@@ -392,6 +394,9 @@ class _Timeout(object):
return cmp((self.deadline, id(self.callback)),
(other.deadline, id(other.callback)))
def __lt__(self, other):
return (self.deadline, id(self.callback)) < \
(other.deadline, id(other.callback))
class PeriodicCallback(object):
"""Schedules the given callback to be called periodically.
......
......@@ -50,10 +50,14 @@ from __future__ import with_statement
import contextlib
import functools
import itertools
import logging
import threading
try:
from itertools import izip
except ImportError:
izip = zip # In Python 3, zip produces an iterator
class _State(threading.local):
def __init__(self):
self.contexts = ()
......@@ -114,7 +118,7 @@ def wrap(fn):
# NullContext to clear the state and then recreate from contexts.
if (len(_state.contexts) > len(contexts) or
any(a is not b
for a, b in itertools.izip(_state.contexts, contexts))):
for a, b in izip(_state.contexts, contexts))):
# contexts have been removed or changed, so start over
new_contexts = ([NullContext()] +
[StackContext(c) for c in contexts])
......
......@@ -27,13 +27,20 @@ from unittest import TestCase
import zmq
try:
from nose import SkipTest
except ImportError:
class SkipTest(Exception):
pass
#-----------------------------------------------------------------------------
# Utilities
#-----------------------------------------------------------------------------
class BaseZMQTestCase(TestCase):
_pgm = None
def setUp(self):
self.context = zmq.Context()
self.sockets = []
......@@ -42,9 +49,29 @@ class BaseZMQTestCase(TestCase):
while self.sockets:
sock = self.sockets.pop()
sock.close()
self.context.term()
del self.context
def has_pgm(self):
if self._pgm is None:
s = self.context.socket(zmq.PUB)
try:
s.bind('epgm://:12345')
except zmq.ZMQError:
e = sys.exc_info()[1]
if e.errno == zmq.EPROTONOSUPPORT:
self._pgm = False
else:
raise e
else:
self._pgm = True
return self._pgm
def skip_if_pgm(self):
major,minor = zmq.zmq_version().split('.',2)[:2]
if self.has_pgm() and major == '2' and minor == '0':
raise SkipTest("Known Failure on 0MQ 2.0.x+PGM")
def create_bound_pair(self, type1, type2, interface='tcp://127.0.0.1'):
"""Create a bound socket pair using a random port."""
s1 = zmq.Socket(self.context, type1)
......
......@@ -33,6 +33,8 @@ from zmq.tests import BaseZMQTestCase
class TestContext(BaseZMQTestCase):
def test_init(self):
if self.has_pgm():
del self.context
c1 = zmq.Context()
self.assert_(isinstance(c1, zmq.Context))
del c1
......@@ -42,12 +44,20 @@ class TestContext(BaseZMQTestCase):
c3 = zmq.Context()
self.assert_(isinstance(c3, zmq.Context))
del c3
if self.has_pgm():
self.context = zmq.Context()
def test_term(self):
c = zmq.Context()
c = self.context
c.term()
self.assert_(c.closed)
def test_fail_init(self):
if self.has_pgm():
del self.context
self.assertRaisesErrno(zmq.EINVAL, zmq.Context, 0)
if self.has_pgm():
self.context = zmq.Context()
......@@ -64,6 +64,7 @@ class TestDevice(BaseZMQTestCase):
def test_single_socket_forwarder_connect(self):
self.skip_if_pgm()
dev = devices.ThreadDevice(zmq.FORWARDER, zmq.REP, -1)
req = self.context.socket(zmq.REQ)
port = req.bind_to_random_port('tcp://127.0.0.1')
......@@ -88,6 +89,7 @@ class TestDevice(BaseZMQTestCase):
del req
def test_single_socket_forwarder_bind(self):
self.skip_if_pgm()
dev = devices.ThreadDevice(zmq.FORWARDER, zmq.REP, -1)
req = self.context.socket(zmq.REQ)
port = 12345
......
#
# Copyright (c) 2010 Min Ragan-Kelley
#
# This file is part of pyzmq.
#
# pyzmq is free software; you can redistribute it and/or modify it under
# the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# pyzmq 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
# Lesser GNU General Public License for more details.
#
# You should have received a copy of the Lesser GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import sys
from unittest import TestCase
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
class TestImports(TestCase):
"""Test Imports - the quickest test to ensure that we haven't
introduced version-incompatible syntax errors."""
def test_toplevel(self):
"""test toplevel import"""
import zmq
def test_core(self):
"""test core imports"""
import zmq.core
from zmq.core import constants
from zmq.core import error
from zmq.core import version
from zmq.core import context
from zmq.core import socket
from zmq.core import message
from zmq.core import stopwatch
from zmq.core import device
def test_devices(self):
"""test device imports"""
import zmq.devices
from zmq.devices import basedevice
from zmq.devices import monitoredqueue
from zmq.devices import monitoredqueuedevice
def test_log(self):
"""test log imports"""
import zmq.log
from zmq.log import handlers
def test_eventloop(self):
"""test eventloop imports"""
import zmq.eventloop
from zmq.eventloop import stack_context
from zmq.eventloop import ioloop
from zmq.eventloop import zmqstream
if sys.platform == 'win32':
from zmq.eventloop import win32_support
def test_utils(self):
"""test util imports"""
import zmq.utils
from zmq.utils import strtypes
from zmq.utils import jsonapi
#
# Copyright (c) 2010 Min Ragan-Kelley
#
# This file is part of pyzmq.
#
# pyzmq is free software; you can redistribute it and/or modify it under
# the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# pyzmq 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
# Lesser GNU General Public License for more details.
#
# You should have received a copy of the Lesser GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import time
import os
import threading
import zmq
from zmq.tests import BaseZMQTestCase
from zmq.eventloop import ioloop
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
def printer():
os.system("say hello")
raise Exception
print (time.time())
class Delay(threading.Thread):
def __init__(self, f, delay=1):
self.f=f
self.delay=delay
self.aborted=False
self.cond=threading.Condition()
super(Delay, self).__init__()
def run(self):
self.cond.acquire()
self.cond.wait(self.delay)
self.cond.release()
if not self.aborted:
self.f()
def abort(self):
self.aborted=True
self.cond.acquire()
self.cond.notify()
self.cond.release()
class TestIOLoop(BaseZMQTestCase):
def test_simple(self):
"""simple IOLoop creation test"""
loop = ioloop.IOLoop()
dc = ioloop.DelayedCallback(loop.stop, 200, loop)
pc = ioloop.DelayedCallback(lambda : None, 10, loop)
pc.start()
dc.start()
t = Delay(loop.stop,1)
t.start()
loop.start()
if t.isAlive():
t.abort()
else:
self.assert_(False, "IOLoop failed to exit")
def test_timeout_compare(self):
"""test timeout comparisons"""
t = ioloop._Timeout(1,2)
t2 = ioloop._Timeout(1,3)
self.assertEquals(t < t2, id(2) < id(3))
t2 = ioloop._Timeout(1,2)
self.assertFalse(t < t2)
t2 = ioloop._Timeout(2,1)
self.assertTrue(t < t2)
......@@ -60,8 +60,9 @@ class TestPubLog(BaseZMQTestCase):
def test_init_iface(self):
logger = self.logger
ctx = self.context
handler = handlers.PUBHandler(self.iface)
self.assertFalse(handler.ctx is ctx)
handler = handlers.PUBHandler(self.iface, ctx)
self.assertTrue(handler.ctx is ctx)
logger.removeHandler(handler)
handler.socket.close()
handler = handlers.PUBHandler(self.iface, self.context)
......@@ -71,7 +72,6 @@ class TestPubLog(BaseZMQTestCase):
handler.root_topic = self.topic
logger.addHandler(handler)
# handler.socket.close()
sub = ctx.socket(zmq.SUB)
sub.connect(self.iface)
sub.setsockopt(zmq.SUBSCRIBE, self.topic)
......@@ -83,7 +83,7 @@ class TestPubLog(BaseZMQTestCase):
self.assertEquals(topic, 'zmq.INFO'.encode())
self.assertEquals(msg2, (msg1+'\n').encode())
logger.removeHandler(handler)
# handler.socket.close()
handler.socket.close()
def test_init_socket(self):
pub,sub = self.create_bound_pair(zmq.PUB, zmq.SUB)
......@@ -106,7 +106,7 @@ class TestPubLog(BaseZMQTestCase):
self.assertEquals(topic, 'zmq.INFO'.encode())
self.assertEquals(msg2, (msg1+'\n').encode())
logger.removeHandler(handler)
# handler.socket.close()
handler.socket.close()
def test_root_topic(self):
logger, handler, sub = self.connect_handler()
......
......@@ -31,15 +31,9 @@ from pprint import pprint
from unittest import TestCase
import zmq
from zmq.tests import BaseZMQTestCase
from zmq.tests import BaseZMQTestCase, SkipTest
from zmq.utils.strtypes import unicode,bytes
try:
from nose import SkipTest
except ImportError:
class SkipTest(Exception):
pass
#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
......@@ -269,7 +263,7 @@ class TestMessage(BaseZMQTestCase):
try:
import numpy
except ImportError:
raise SkipTest
raise SkipTest("NumPy unavailable")
shapes = map(numpy.random.randint, [2]*5,[16]*5)
for i in range(1,len(shapes)+1):
shape = shapes[:i]
......
......@@ -38,6 +38,7 @@ class TestMonitoredQueue(BaseZMQTestCase):
pass
def build_device(self, mon_sub="".encode(), in_prefix='in'.encode(), out_prefix='out'.encode()):
self.skip_if_pgm()
self.device = devices.ThreadMonitoredQueue(zmq.PAIR, zmq.PAIR, zmq.PUB,
in_prefix, out_prefix)
alice = self.context.socket(zmq.PAIR)
......
......@@ -27,7 +27,7 @@ import sys
import time
import zmq
from zmq.tests import BaseZMQTestCase
from zmq.tests import BaseZMQTestCase, SkipTest
from zmq.utils.strtypes import bytes, unicode
try:
from queue import Queue
......@@ -41,13 +41,12 @@ except:
class TestSocket(BaseZMQTestCase):
def test_create(self):
ctx = zmq.Context()
s = ctx.socket(zmq.PUB)
s = self.context.socket(zmq.PUB)
# Superluminal protocol not yet implemented
self.assertRaisesErrno(zmq.EPROTONOSUPPORT, s.bind, 'ftl://')
self.assertRaisesErrno(zmq.EPROTONOSUPPORT, s.connect, 'ftl://')
s.close()
del ctx
# del ctx
def test_unicode_sockopts(self):
"""test setting/getting sockopts with unicode strings"""
......@@ -143,14 +142,12 @@ class TestSocket(BaseZMQTestCase):
def test_close(self):
ctx = zmq.Context()
s = ctx.socket(zmq.PUB)
s = self.context.socket(zmq.PUB)
s.close()
self.assertRaises(zmq.ZMQError, s.bind, ''.encode())
self.assertRaises(zmq.ZMQError, s.connect, ''.encode())
self.assertRaises(zmq.ZMQError, s.setsockopt, zmq.SUBSCRIBE, ''.encode())
self.assertRaises(zmq.ZMQError, s.send, 'asdf'.encode())
self.assertRaises(zmq.ZMQError, s.recv)
del ctx
......@@ -31,9 +31,11 @@ if major >= 3:
bytes = bytes
unicode = str
basestring = (bytes, unicode)
asbytes = lambda s: s.encode('utf8')
elif major == 2:
unicode = unicode
bytes = str
basestring = basestring
asbytes = str
__all__ = ['bytes', 'unicode', 'basestring']
__all__ = ['asbytes', 'bytes', 'unicode', 'basestring']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment