Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't show empty items in repr and add a NAME for the base Properties…

… class

- Add test coverage for this module
  • Loading branch information...
commit 5a007071e4556fceb9440f57cdcdf97c62c3adcd 1 parent b5f212e
Gavin M. Roy authored
Showing with 74 additions and 0 deletions.
  1. +3 −0  pika/amqp_object.py
  2. +71 −0 tests/amqp_object_tests.py
View
3  pika/amqp_object.py
@@ -17,6 +17,8 @@ def __repr__(self):
for key, value in self.__dict__.iteritems():
if getattr(self.__class__, key, None) != value:
items.append('%s=%s' % (key, value))
+ if not items:
+ return "<%s>" % self.NAME
return "<%s(%s)>" % (self.NAME, items)
@@ -59,3 +61,4 @@ def get_body(self):
class Properties(AMQPObject):
"""Class to encompass message properties (AMQP Basic.Properties)"""
+ NAME = 'Unextended Properties'
View
71 tests/amqp_object_tests.py
@@ -0,0 +1,71 @@
+"""
+Tests for pika.callback
+
+"""
+import mock
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+
+from pika import amqp_object
+
+
+class AMQPObjectTests(unittest.TestCase):
+
+ def test_base_name(self):
+ self.assertEqual(amqp_object.AMQPObject().NAME, 'AMQPObject')
+
+ def test_repr_no_items(self):
+ obj = amqp_object.AMQPObject()
+ self.assertEqual(repr(obj), '<AMQPObject>')
+
+ def test_repr_items(self):
+ obj = amqp_object.AMQPObject()
+ setattr(obj, 'foo', 'bar')
+ setattr(obj, 'baz', 'qux')
+ self.assertEqual(repr(obj), "<AMQPObject(['foo=bar', 'baz=qux'])>")
+
+
+class ClassTests(unittest.TestCase):
+
+ def test_base_name(self):
+ self.assertEqual(amqp_object.Class().NAME, 'Unextended Class')
+
+class MethodTests(unittest.TestCase):
+
+ def test_base_name(self):
+ self.assertEqual(amqp_object.Method().NAME, 'Unextended Method')
+
+ def test_set_content_body(self):
+ properties = amqp_object.Properties()
+ body = 'This is a test'
+ obj = amqp_object.Method()
+ obj._set_content(properties, body)
+ self.assertEqual(obj._body, body)
+
+ def test_set_content_properties(self):
+ properties = amqp_object.Properties()
+ body = 'This is a test'
+ obj = amqp_object.Method()
+ obj._set_content(properties, body)
+ self.assertEqual(obj._properties, properties)
+
+ def test_get_body(self):
+ properties = amqp_object.Properties()
+ body = 'This is a test'
+ obj = amqp_object.Method()
+ obj._set_content(properties, body)
+ self.assertEqual(obj.get_body(), body)
+
+ def test_get_properties(self):
+ properties = amqp_object.Properties()
+ body = 'This is a test'
+ obj = amqp_object.Method()
+ obj._set_content(properties, body)
+ self.assertEqual(obj.get_properties(), properties)
+
+class PropertiesTests(unittest.TestCase):
+
+ def test_base_name(self):
+ self.assertEqual(amqp_object.Properties().NAME, 'Unextended Properties')
Please sign in to comment.
Something went wrong with that request. Please try again.