Show
Ignore:
Timestamp:
01/25/11 17:48:43 (16 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Take advantage of unittest2 functionality in response parser tests

Less of our own scaffolding required.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/test/test_response_parser.py

    r198 r199  
    2424from imapclient.response_parser import parse_response, parse_fetch_response, ParseError 
    2525from imapclient.test.util import unittest 
    26 from pprint import pformat 
    2726 
    2827#TODO: tokenising tests 
     
    161160 
    162161    def test_incomplete_tuple(self): 
    163         self._test_parse_error('abc (1 2', 'Tuple incomplete before "(1 2"') 
     162        self._test_parse_error('abc (1 2', 'Tuple incomplete before "\(1 2"') 
    164163 
    165164    def test_incomplete_juxtaposed_tuples(self): 
    166165        self._test_parse_error('(1 2)(3 4', 
    167                                'Juxtaposed tuples incomplete before "(1 2)(3 4"') 
     166                               'Juxtaposed tuples incomplete before "\(1 2\)\(3 4"') 
    168167 
    169168    def test_bad_literal(self): 
     
    173172 
    174173    def test_bad_quoting(self): 
    175         self._test_parse_error('"abc next', "No closing '\"'") 
     174        self._test_parse_error('"abc next', """No closing '"'""") 
    176175 
    177176 
     
    183182            to_parse = [to_parse] 
    184183        output = parse_response(to_parse) 
    185         self.assert_(output == expected, 
    186                      format_error(to_parse, output, expected)) 
     184        self.assertSequenceEqual(output, expected) 
    187185 
    188186    def _test_parse_error(self, to_parse, expected_msg): 
    189187        if not isinstance(to_parse, list): 
    190188            to_parse = [to_parse] 
    191         try: 
    192             parse_response(to_parse) 
    193             self.fail("didn't raise an exception") 
    194         except ParseError, err: 
    195             actual_msg = str(err) 
    196             self.assert_(expected_msg == actual_msg[:len(expected_msg)], 
    197                          'got ParseError with wrong msg: %r' % actual_msg) 
    198  
     189        self.assertRaisesRegexp(ParseError, expected_msg, 
     190                                parse_response, to_parse) 
    199191 
    200192 
     
    332324 
    333325 
    334  
    335 def format_error(input_, output, expected): 
    336     return 'failed for:\n%s\ngot:\n%s\nexpected:\n%s' % ( 
    337                 pformat(input_), 
    338                 pformat(output), 
    339                 pformat(expected)) 
    340  
    341  
    342326def add_crlf(text): 
    343327    return CRLF.join(text.splitlines()) + CRLF 
     
    349333 
    350334 
    351 if __name__ == '__main__': 
    352     unittest.main()