From 65ffb3732e5b42d8617e37e6fe491b1ece46457d Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 31 Dec 2010 16:42:49 +0100 Subject: [PATCH] Improve opcode summary tests Test full summary instead of just format. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- test/ganeti.opcodes_unittest.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/ganeti.opcodes_unittest.py b/test/ganeti.opcodes_unittest.py index 65c515e26..ff52381f9 100755 --- a/test/ganeti.opcodes_unittest.py +++ b/test/ganeti.opcodes_unittest.py @@ -87,6 +87,34 @@ class TestOpcodes(unittest.TestCase): else: self.assertEqual("OP_%s" % summary, op.OP_ID) + def testSummary(self): + class _TestOp(opcodes.OpCode): + OP_ID = "OP_TEST" + OP_DSC_FIELD = "data" + OP_PARAMS = [ + ("data", ht.NoDefault, ht.TString), + ] + + self.assertEqual(_TestOp(data="").Summary(), "TEST()") + self.assertEqual(_TestOp(data="Hello World").Summary(), + "TEST(Hello World)") + self.assertEqual(_TestOp(data="node1.example.com").Summary(), + "TEST(node1.example.com)") + + def testListSummary(self): + class _TestOp(opcodes.OpCode): + OP_ID = "OP_TEST" + OP_DSC_FIELD = "data" + OP_PARAMS = [ + ("data", ht.NoDefault, ht.TList), + ] + + self.assertEqual(_TestOp(data=["a", "b", "c"]).Summary(), + "TEST(a,b,c)") + self.assertEqual(_TestOp(data=["a", None, "c"]).Summary(), + "TEST(a,None,c)") + self.assertEqual(_TestOp(data=[1, 2, 3, 4]).Summary(), "TEST(1,2,3,4)") + def testOpId(self): self.assertFalse(utils.FindDuplicates(cls.OP_ID for cls in opcodes._GetOpList())) -- GitLab