2
# Copyright (c) 2010 Brian E. Granger
4
# This file is part of pyzmq.
6
# pyzmq is free software; you can redistribute it and/or modify it under
7
# the terms of the Lesser GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# pyzmq is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# Lesser GNU General Public License for more details.
16
# You should have received a copy of the Lesser GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#-----------------------------------------------------------------------------
22
#-----------------------------------------------------------------------------
25
from sys import getrefcount as grc
27
from unittest import TestCase
30
from zmq.tests import PollZMQTestCase
32
#-----------------------------------------------------------------------------
34
#-----------------------------------------------------------------------------
36
class TestMessage(TestCase):
38
def test_above_30(self):
39
"""Message above 30 bytes are never copied by 0MQ."""
40
for i in range(5, 16): # 32, 64,..., 65536
42
self.assertEquals(grc(s), 2)
44
self.assertEquals(grc(s), 4)
46
self.assertEquals(grc(s), 2)
50
"""Test the str representations of the Messages."""
54
self.assertEquals(s, str(s))
55
self.assert_(s is str(s))
58
"""Test the len of the Messages."""
62
self.assertEquals(len(s), len(s))
64
def test_lifecycle1(self):
65
"""Run through a ref counting cycle with a copy."""
66
for i in range(5, 16): # 32, 64,..., 65536
68
self.assertEquals(grc(s), 2)
70
self.assertEquals(grc(s), 4)
72
self.assertEquals(grc(s), 5)
73
self.assertEquals(s, str(m))
74
self.assertEquals(s, str(m2))
75
self.assert_(s is str(m))
76
self.assert_(s is str(m2))
78
self.assertEquals(grc(s), 4)
80
self.assertEquals(grc(s), 2)
83
def test_lifecycle2(self):
84
"""Run through a different ref counting cycle with a copy."""
85
for i in range(5, 16): # 32, 64,..., 65536
87
self.assertEquals(grc(s), 2)
89
self.assertEquals(grc(s), 4)
91
self.assertEquals(grc(s), 5)
92
self.assertEquals(s, str(m))
93
self.assertEquals(s, str(m2))
94
self.assert_(s is str(m))
95
self.assert_(s is str(m2))
97
self.assertEquals(grc(s), 4)
99
self.assertEquals(grc(s), 2)