BIND 10 #1990: customize EqualityFunc of python tests

BIND 10 Development do-not-reply at isc.org
Wed May 23 22:26:06 UTC 2012


#1990: customize EqualityFunc of python tests
-------------------------------------+-------------------------------------
            Reporter:  jinmei        |                        Owner:
                Type:  enhancement   |                       Status:  new
            Priority:  medium        |                    Milestone:  Next-
           Component:  Unclassified  |  Sprint-Proposed
           Sensitive:  0             |                     Keywords:
         Sub-Project:  Core          |              Defect Severity:  N/A
Estimated Difficulty:  0             |  Feature Depending on Ticket:
         Total Hours:  0             |          Add Hours to Ticket:  0
                                     |                    Internal?:  0
-------------------------------------+-------------------------------------
 assertEqual() of python tests are not helpful for user defined
 classes.  See, e.g. this: http://bind10.isc.org/ticket/1512#comment:15

 I've looked into the unittest implementation and found that we need to
 customize the builtin equality-check method.

 The following diff is an example for such customization.

 {{{#!diff
 diff --git a/src/lib/python/isc/ddns/tests/session_tests.py
 b/src/lib/python/isc/ddns/tests/session_tests.py
 index 1bf4e40..caefa97 100644
 --- a/src/lib/python/isc/ddns/tests/session_tests.py
 +++ b/src/lib/python/isc/ddns/tests/session_tests.py
 @@ -67,9 +67,13 @@ class SessionTest(unittest.TestCase):

      def check_response(self, msg, expected_rcode):
          '''Perform common checks on update resposne message.'''
 +        def opcode_equality_func(opcode1, opcode2, msg):
 +            if not opcode1 == opcode2:
 +                raise AssertionError(str(opcode1) + ' != ' +
 str(opcode2))
          self.assertTrue(msg.get_header_flag(Message.HEADERFLAG_QR))
          # note: we convert opcode to text it'd be more helpful on
 failure.
 -        self.assertEqual(Opcode.UPDATE().to_text(),
 msg.get_opcode().to_text())
 +        self.addTypeEqualityFunc(Opcode, opcode_equality_func)
 +        self.assertEqual(Opcode.UPDATE(), msg.get_opcode())
          self.assertEqual(expected_rcode.to_text(),
 msg.get_rcode().to_text())
          # All sections should be cleared
          self.assertEqual(0, msg.get_rr_count(SECTION_ZONE))
 }}}

 I propose defining such customized functions for some major isc.dns
 (and some other) classes such as Name, RRType, RRClass, introduce an
 easy to use it (some kind of mixin), and use it for some of existing
 tests.

-- 
Ticket URL: <http://bind10.isc.org/ticket/1990>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list