Show
Ignore:
Timestamp:
03/06/11 16:19:08 (12 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

added BODY and BODYSTRUCTURE fetch response parser tests and removed juxtaposed tuples tests (going to handle this differently)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/test/test_response_parser.py

    r204 r228  
    5151        self._test('(123 "foo" ((0 1 2) "more" NIL) 66)', 
    5252                   (123, "foo", ((0, 1, 2), "more", None), 66)) 
    53  
    54     def test_juxtatposed_tuples(self): 
    55         # Tuples with no whitespace between them should be returned as 
    56         # a list of tuples 
    57         self._test('(12 "foo")(34 NIL 0)', 
    58                    [(12, "foo"), (34, None, 0)]) 
    59         self._test('(12 "foo")(34 NIL 0)(5 66)', 
    60                    [(12, "foo"), (34, None, 0), (5, 66)]) 
    61         self._test('((12 "foo")(34 NIL 0) "foo")', 
    62                    ([(12, "foo"), (34, None, 0)], "foo")) 
    63         self._test('((12 "foo")(34 NIL 0)(4 55 6) "foo")', 
    64                    ([(12, "foo"), (34, None, 0), (4, 55, 6)], "foo")) 
    65         self._test('((12 "foo")(34 (NIL 1 2) 0)(4 55 6) "foo")', 
    66                    ([(12, "foo"), (34, (None, 1, 2), 0), (4, 55, 6)], "foo")) 
    67         self._test('(12 "foo")(34 NIL ("a" "b")("c" "d"))', 
    68                    [(12, "foo"), (34, None, [('a', 'b'), ('c', 'd')])]) 
    6953 
    7054    def test_complex_mixed(self): 
     
    150134        self._test_parse_error('abc (1 2', 'Tuple incomplete before "\(1 2"') 
    151135 
    152     def test_incomplete_juxtaposed_tuples(self): 
    153         self._test_parse_error('(1 2)(3 4', 
    154                                'Juxtaposed tuples incomplete before "\(1 2\)\(3 4"') 
    155  
    156136    def test_bad_literal(self): 
    157137        self._test_parse_error([('{99}', 'abc')], 
    158138                               'Expecting literal of size 99, got 3') 
    159139 
    160  
    161140    def test_bad_quoting(self): 
    162141        self._test_parse_error('"abc next', """No closing '"'""") 
    163  
    164142 
    165143    def _test(self, to_parse, expected, wrap=True): 
     
    272250                      'SEQ': 123}}) 
    273251 
     252    def test_BODY(self): 
     253         self.check_BODYish_single_part('BODY') 
     254         self.check_BODYish_multipart('BODY') 
     255 
     256    def test_BODYSTRUCTURE(self): 
     257         self.check_BODYish_single_part('BODYSTRUCTURE') 
     258         self.check_BODYish_multipart('BODYSTRUCTURE') 
     259     
     260    def check_BODYish_single_part(self, respType): 
     261        resp =  '123 (UID 317 %s ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 16 1))' % respType 
     262        self.assertEquals(parse_fetch_response([resp]), 
     263            { 317: {respType: ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 16, 1), 
     264                    'SEQ': 123 } 
     265            }) 
     266 
     267    def check_BODYish_multipart(self, respType): 
     268        resp = '123 (UID 269 %s (("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 55 3)' \ 
     269                                '("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 26 1) "MIXED"))' \ 
     270                                % respType 
     271        self.assertEquals(parse_fetch_response([resp]), 
     272             {269: {respType: ([('TEXT', 'HTML', ('CHARSET', 'us-ascii'), None, None, 'QUOTED-PRINTABLE', 55, 3), 
     273                                ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 26, 1)], 
     274                                'MIXED'), 
     275                    'SEQ': 123} 
     276            }) 
    274277 
    275278    def test_partial_fetch(self):