Am 5. Januar 2011 09:27 schrieb Iustin Pop <ius...@google.com>:
> One thing that is not tested and that I would like to ensure is that
> even with the metaclass, __slots__ works as expected. Can you add a
> self.assertRaises(setattr, …)?

Thanks for the review. Will commit with interdiff below.

Michael

---
diff --git a/lib/opcodes.py b/lib/opcodes.py
index 3f93577..44026fd 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -131,7 +131,7 @@ class _AutoOpParamSlots(type):
     @param name: Name of created class
     @param bases: Base classes
     @type attrs: dict
-    @param attrs: Instance attributes
+    @param attrs: Class attributes

     """
     assert "__slots__" not in attrs, \
diff --git a/test/ganeti.opcodes_unittest.py b/test/ganeti.opcodes_unittest.py
index e6bf793..5269fc8 100755
--- a/test/ganeti.opcodes_unittest.py
+++ b/test/ganeti.opcodes_unittest.py
@@ -70,6 +70,11 @@ class TestOpcodes(unittest.TestCase):
         self.assert_(isinstance(restored, cls))
         self._checkSummary(restored)

+        for name in ["x_y_z", "hello_world"]:
+          assert name not in cls._all_slots()
+          for value in [None, True, False, [], "Hello World"]:
+            self.assertRaises(AttributeError, setattr, op, name, value)
+
   def _checkSummary(self, op):
     summary = op.Summary()

@@ -82,6 +87,9 @@ class TestOpcodes(unittest.TestCase):
   def testParams(self):
     supported_by_all = set(["debug_level", "dry_run", "priority"])

+    self.assert_(opcodes.BaseOpCode not in opcodes.OP_MAPPING.values())
+    self.assert_(opcodes.OpCode in opcodes.OP_MAPPING.values())
+
     for cls in opcodes.OP_MAPPING.values():
       all_slots = cls._all_slots()

Reply via email to