Commits

Lynn Rees committed 80d846f

- all extant tests pass for py27, py32, py33

  • Participants
  • Parent commits d7a6d4e

Comments (0)

Files changed (8)

crossroads/low.py

 # -*- coding: utf-8 -*-
 '''Low level API for ctypes binding to Crossroads.IO.'''
 
+from uuid import uuid4
 from functools import partial
 from ctypes import byref, sizeof, c_int, c_int64, c_char, c_size_t
 
-from stuf.utils import unique_id
 from stuf.desc import Setter, lazy
-from stuf.six import OrderedDict, items, tobytes, isstring
+from stuf.six import OrderedDict, items, tobytes, isstring, b
 
 from . import lowest as xs
 from . import constants as XS
 
 bigxsget = partial(getattr, XS)
 xsget = partial(getattr, xs)
+unique_id = lambda: b(uuid4().hex.upper())
 
 
 class Context(Setter):

crossroads/message.py

 
 from ctypes import sizeof, string_at, c_ubyte, byref, c_size_t, c_char, c_int
 
-from stuf.six import PY3, tobytes, tounicode, strings
+from stuf.six import PY3, tobytes, tounicode, u, b, isunicode
 
 from . import lowest as xs
 from .constants import MORE
 
 SLOTS = 'msg rc more size last_rc'.split()
 
+
+
 class Msg(object):
 
     def __init__(self):
         return tobytes(string_at(byref(self.msg), self.size))
 
     def __unicode__(self):
-        return tounicode(self)
+        if self.msg is None:
+            return u('')
+        return tounicode(self.array)
 
     def __len__(self):
         return self.size
 
     def __init__(self, size, source):
         super(SendMsg, self).__init__()
-        if isinstance(source, (Msg, strings)):
+        if isinstance(source, Msg):
             self.msg = source = bytes(source)
+        elif isunicode(source):
+            self.msg = source = b(source)
         else:
             self.msg = source
         self.size = len(source) if size is None else size
             self.msg = source.msg
         else:
             self.msg = xs.msg_t()
-            source = bytes(source)
+            source = b(source)
             length = len(source)
             self.rc = xs.msg_init_size(self.msg, length)
             xs.memmove(xs.msg_data(self.msg), source, length)

reqs/requires-2.6.txt

Empty file removed.

reqs/requires.txt

+stuf>=0.9.7
         if line.startswith('__version__'):
             return '%s.%s.%s' % eval(line[13:].rstrip())
 
-if float('%d.%s' % sys.version_info[:2]) < 2.7:
-    reqs = 'reqs/requires-2.6.txt'
-else:
-    reqs = 'reqs/requires.txt'
+
+reqs = 'reqs/requires.txt'
 install_requires = list(l for l in open(join(getcwd(), reqs), 'r').readlines())
 
 setup(

tests/test_low_level.py

     def test_pair_ipc(self):
         sb = self.ctx.pair()
         sc = self.ctx.pair()
-        with sb.bind_ipc('/tmp/tester'), sc.connect_ipc('/tmp/tester'):
+        with sb.bind_ipc(b'/tmp/tester'), sc.connect_ipc(b'/tmp/tester'):
             self.bounce(sb, sc)
 
     def test_pair_inproc(self):
         sb = self.ctx.pair()
         sc = self.ctx.pair()
-        with sb.bind_inproc('a'), sc.connect_inproc('a'):
+        with sb.bind_inproc(b'a'), sc.connect_inproc(b'a'):
             self.bounce(sb, sc)
 
     def test_pair_tcp(self):
         from time import sleep
         sb = self.ctx.pair()
         sc = self.ctx.pair()
-        with sb.bind_tcp('127.0.0.1:5560'), sc.connect_tcp('127.0.0.1:5560'):
+        with sb.bind_tcp(b'127.0.0.1:5560'), sc.connect_tcp(b'127.0.0.1:5560'):
             self.bounce(sb, sc)
             # Now let's try to open one more connection to the bound socket. The
             # connection should be silently rejected rather than causing error.
             msg = sb.recvmsg()
             self.assertTrue(msg.last_rc >= 0)
             self.assertEqual(msg.moremsg, 0)
-
+#
     def test_wireformat(self):
         import socket
         # create the basic infrastructure
             )
             rpull.connect(('127.0.0.1', 5561))
             # let's send some data and check if it arrived
-            self.assertEqual(rpush.send('\x04\0abc', 0), 5)
+            self.assertEqual(rpush.send(b'\x04\0abc', 0), 5)
             buf = pull.recv(3)
             self.assertEqual(pull.last_rc, 3)
             self.assertEqual(bytes(buf), b'abc')
                 with pull.bind_ipc('/tmp/tester'):
                     pull.recv(3)
                     self.assertEqual(pull.last_rc, 3)
-
+#
     def test_hwn(self):
         # Create pair of socket, each with high watermark of 2. Thus the
         # total buffer space should be 4 messages.
         sc = self.ctx.push(sndhwm=2)
         with sb.bind_inproc('a'), sc.connect_inproc('a'):
             # Try to send 10 messages. Only 4 should succeed.
-            for t in xrange(10):
+            for t in range(10):
                 try:
                     sc.send(None, 0, nowait=True)
                     if t < 4:
             # Get the response and check it's the response to the new survey and
             # that response to the old survey was silently discarded.
             self.assertEqual(surveyor.recv(2).last_rc, 2)
-
+#
     def test_invalid_rep(self):
         from stuf.six import int2byte
         # create REQ/XREP wiring
             self.assertEqual(buff2.last_rc, 3)
             self.assertEqual(bytes(buff2), b'JKL')
             self.assertEqual(buff2.more, 0)
-
+#
     def test_resubscribe(self):
         try:
             from stuf.six import int2byte

tests/test_lowest_level.py

         self.assertTrue(ctx)
         sb = xs.socket(ctx, XS.PAIR)
         self.assertTrue(sb)
-        self.assertNotEqual(xs.bind(sb, 'inproc://a'), -1)
+        self.assertNotEqual(xs.bind(sb, b'inproc://a'), -1)
         sc = xs.socket(ctx, XS.PAIR)
         self.assertTrue(sc)
-        self.assertNotEqual(xs.connect(sc, 'inproc://a'), -1)
+        self.assertNotEqual(xs.connect(sc, b'inproc://a'), -1)
         self.bounce(sb, sc)
         self.assertEqual(xs.close(sc), 0)
         self.assertEqual(xs.close(sb), 0)
         )
         self.assertNotEqual(xs.connect(sc, b'inproc://a'), -1)
         # try to send 10 messages. Only 4 should succeed.
-        for t in xrange(10):
+        for t in range(10):
             try:
                 rc = xs.send(sc, None, 0, XS.DONTWAIT)
                 if t < 4:
         self.assertTrue(sb)
         self.assertNotEqual(xs.bind(sb, b'inproc://timeout_test'), -1)
         # check whether non-blocking recv returns immediately.
-        buf = c_char_p('12345678ABCDEFGH12345678abcdefgh')
+        buf = c_char_p(b'12345678ABCDEFGH12345678abcdefgh')
         try:
             xs.recv(sb, buf, 32, XS.DONTWAIT)
         except xs.XSError as e:
 #            rc = xs.close(s_)
 #            self.assertEqual(rc, 0)
 #        threads = []  # THREAD_COUNT
-#        for j in xrange(10):
+#        for j in lrange(10):
 #            # Check the shutdown with many parallel I/O threads.
 #            ctx = xs.init()
 #            self.assertTrue(ctx)
 #            self.assertTrue(s1)
 #            rc = xs.bind(s1, b'tcp://127.0.0.1:5560')
 #            self.assertNotEqual(rc, -1)
-#            for i in xrange(THREAD_COUNT):
+#            for i in lrange(THREAD_COUNT):
 #                s2 = xs.socket(ctx, XS.SUB)
 #                if not s2 and (
 #                    get_errno() == XS.EMFILE or get_errno() == XS.ENFILE
 #                    self.assertTrue(s2)
 #                    threads[i] = self.thread_create(shutdown_stress_worker, s2)
 #                    self.assertTrue(threads[i])
-#            for i in xrange(THREAD_COUNT):
+#            for i in lrange(THREAD_COUNT):
 #                if threads[i]:
 #                    self.thread_join(threads[i])
 #            rc = xs.close(s1)
 [tox]
-envlist = py26,py27,py31,py32,py33,pypy
+envlist = py27,py32,py33
 
-[testenv:py26]
-deps=
-  unittest2
-  -r{toxinidir}/reqs/test_requires.txt
-commands=
-  nosetests {posargs:--with-coverage  --cover-package=crossroads}
-  
 [testenv]
 deps=
   -r{toxinidir}/reqs/test_requires.txt