Advertisement
zamotivator

Untitled

Sep 7th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1.     def __init__(self):
  2.         super(Compare, self).__init__()
  3.         self._init_create()
  4.  
  5.     def _init_create(self):
  6.         def expected_parser_received_exception(expected, actual):
  7.             self.fail(msg='%s: expected parser, but received exception: %s' % (self.name, actual))
  8.         def expected_exception_received_parser(expected, actual):
  9.             self.fail(msg='%s: ')
  10.         def both_exception(expected, actual):
  11.             self.assertEquals(expected = actual, msg="expected exception '%s', but received '%s'" % (expected, actual))
  12.         self._create = {}
  13.         self._create[('PARSER', 'PARSER')] = self.parse_args
  14.         self._create[('PARSER', 'EXCEPTION')] = expected_parser_received_exception
  15.         self._create[('EXCEPTION', 'PARSER')] = expected_exception_received_parser
  16.         self._create[('EXCEPTION', 'EXCEPTION')] = both_exception
  17.  
  18.  
  19.     def check_parser(self, expected, actual):
  20.         def create_parser(self, callback):
  21.             try:
  22.                 result = callback()
  23.                 return 'PARSER', result
  24.             with BaseException, e:
  25.                 return 'EXCEPTION', repr(e)
  26.         expected_kind, expected_result = create_parser(expected)
  27.         actual_kind, actual_result  = create_parser(actual)
  28.         self._create[(expected_kind, actual_kind)](expected_result, actual_result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement