From 08f3117697c5e7ede2e54cbe767a0f8c5c9638af Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 22 Nov 2012 14:31:47 +0100 Subject: [PATCH] Add test for mutable default values in opcode parameters This is not comprehensive, since in Python one can't determine what is and what is not mutable; but I've added a few base cases (list, dict, set). The patch also improves (makes more uniform) the error messages in the parameter definitions. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- test/ganeti.opcodes_unittest.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/ganeti.opcodes_unittest.py b/test/ganeti.opcodes_unittest.py index c310ecc6c..3e2db17a5 100755 --- a/test/ganeti.opcodes_unittest.py +++ b/test/ganeti.opcodes_unittest.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -# Copyright (C) 2010, 2011 Google Inc. +# Copyright (C) 2010, 2011, 2012 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -193,13 +193,18 @@ class TestOpcodes(unittest.TestCase): if callable(aval): default_value = aval() self.assertFalse(callable(default_value), - msg="Default value returned by function is callable") + msg=("Default value of %s.%s returned by function" + " is callable" % (cls.OP_ID, attr_name))) else: + self.assertFalse(isinstance(aval, (list, dict, set)), + msg=("Default value of %s.%s is mutable (%s)" % + (cls.OP_ID, attr_name, repr(aval)))) + default_value = aval if aval is not ht.NoDefault and test is not ht.NoType: self.assertTrue(test(default_value), - msg=("Default value of '%s.%s' does not verify" % + msg=("Default value of %s.%s does not verify" % (cls.OP_ID, attr_name))) # If any parameter has documentation, all others need to have it as well -- GitLab