Changeset 115:7aa870b75d11 for imapclient/test/test_response_parser.py
- Timestamp:
- 01/11/10 19:11:54 (2 years ago)
- Branch:
- default
- Files:
-
- 1 modified
-
imapclient/test/test_response_parser.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
imapclient/test/test_response_parser.py
r114 r115 74 74 '<hi.there>', 'foo', 'BASE64', 4554, 73), 'MIXED')) 75 75 76 def test_envelopey(self): 77 self._test('(UID 5 ENVELOPE ("internal_date" "subject" ' 78 '(("name" NIL "address1" "domain1.com")) ' 79 '((NIL NIL "address2" "domain2.com")) ' 80 '(("name" NIL "address3" "domain3.com")) ' 81 '((NIL NIL "address4" "domain4.com")) ' 82 'NIL NIL "<reply-to-id>" "<msg_id>"))', 83 ('UID', 84 5, 85 'ENVELOPE', 86 ('internal_date', 87 'subject', 88 (('name', None, 'address1', 'domain1.com'),), 89 ((None, None, 'address2', 'domain2.com'),), 90 (('name', None, 'address3', 'domain3.com'),), 91 ((None, None, 'address4', 'domain4.com'),), 92 None, 93 None, 94 '<reply-to-id>', 95 '<msg_id>'))) 96 97 def test_envelopey_quoted(self): 98 self._test('(UID 5 ENVELOPE ("internal_date" "subject with \\"quotes\\"" ' 99 '(("name" NIL "address1" "domain1.com")) ' 100 '((NIL NIL "address2" "domain2.com")) ' 101 '(("name" NIL "address3" "domain3.com")) ' 102 '((NIL NIL "address4" "domain4.com")) ' 103 'NIL NIL "<reply-to-id>" "<msg_id>"))', 104 ('UID', 105 5, 106 'ENVELOPE', 107 ('internal_date', 108 'subject with "quotes"', 109 (('name', None, 'address1', 'domain1.com'),), 110 ((None, None, 'address2', 'domain2.com'),), 111 (('name', None, 'address3', 'domain3.com'),), 112 ((None, None, 'address4', 'domain4.com'),), 113 None, 114 None, 115 '<reply-to-id>', 116 '<msg_id>'))) 76 117 77 118 def test_literal(self): … … 80 121 abc def XYZ 81 122 """)) 82 self._test( '{18}' + CRLF + literal_text, literal_text)123 self._test([('{18}', literal_text)], literal_text) 83 124 84 125 … … 88 129 abc def XYZ 89 130 """)) 90 response = add_crlf(dedent("""\ 91 (12 "foo" {18} 92 %s) 93 """) % literal_text) 131 response = [('(12 "foo" {18}', literal_text), ")"] 94 132 self._test(response, (12, 'foo', literal_text)) 95 133 96 134 97 135 def test_quoted_specials(self): 98 self._test(r'"foo \"bar\""', ('foo "bar"',))99 self._test(r'"foo\\bar"', (r'foo\bar',))136 self._test(r'"foo \"bar\""', 'foo "bar"') 137 self._test(r'"foo\\bar"', r'foo\bar') 100 138 101 139 … … 105 143 106 144 def test_bad_literal(self): 107 self._test_parse_error('{99} abc', 'No CRLF after {99}') 145 self._test_parse_error([('{99}', 'abc')], 146 'Expecting literal of size 99, got 3') 108 147 109 148 110 149 def test_bad_quoting(self): 111 self._test_parse_error('"abc next', 'No closing quotation: "abc next') 112 113 150 self._test_parse_error('"abc next', 'No closing quotation:') 114 151 115 152 … … 118 155 # convenience - expected value should be wrapped in another tuple 119 156 expected = (expected,) 157 if not isinstance(to_parse, list): 158 to_parse = [to_parse] 120 159 output = parse_response(to_parse) 121 160 self.assert_( … … 129 168 self.fail("didn't raise an exception") 130 169 except ParseError, err: 131 self.assert_(expected_msg == str(err) ,170 self.assert_(expected_msg == str(err)[:len(expected_msg)], 132 171 'got ParseError with wrong msg: %r' % str(err)) 133 172 … … 141 180 142 181 def test_basic(self): 143 self.assertEquals(parse_fetch_response('* 4 FETCH ()'), {4: {}}) 144 self.assertEquals(parse_fetch_response('* 4 fEtCh ()'), {4: {}}) 145 146 147 def test_non_fetch(self): 148 self.assertRaises(ParseError, parse_fetch_response, '* 4 OTHER ()') 182 self.assertEquals(parse_fetch_response('4 ()'), {4: {'SEQ': 4}}) 183 184 185 # def test_non_fetch(self): 186 # self.assertRaises(ParseError, parse_fetch_response, ['4 ()']) 149 187 150 188 151 189 def test_bad_msgid(self): 152 self.assertRaises(ParseError, parse_fetch_response, '* abc FETCH ()')190 self.assertRaises(ParseError, parse_fetch_response, ['abc ()']) 153 191 154 192 155 193 def test_bad_data(self): 156 self.assertRaises(ParseError, parse_fetch_response, '* 2 FETCH WHAT')194 self.assertRaises(ParseError, parse_fetch_response, ['2 WHAT']) 157 195 158 196 159 197 def test_missing_data(self): 160 self.assertRaises(ParseError, parse_fetch_response, '* 2 FETCH')198 self.assertRaises(ParseError, parse_fetch_response, ['2']) 161 199 162 200 163 201 def test_simple_pairs(self): 164 self.assertEquals(parse_fetch_response( '* 23 FETCH (ABC 123 StUfF "hello")'),202 self.assertEquals(parse_fetch_response(['23 (ABC 123 StUfF "hello")']), 165 203 {23: {'ABC': 123, 166 'STUFF': 'hello'}}) 204 'STUFF': 'hello', 205 'SEQ': 23}}) 167 206 168 207 169 208 def test_odd_pairs(self): 170 self.assertRaises(ParseError, parse_fetch_response, '* 2 FETCH (ONE)')171 self.assertRaises(ParseError, parse_fetch_response, '* 2 FETCH (ONE TWO THREE)')209 self.assertRaises(ParseError, parse_fetch_response, ['* 2 FETCH (ONE)']) 210 self.assertRaises(ParseError, parse_fetch_response, ['* 2 FETCH (ONE TWO THREE)']) 172 211 173 212 174 213 def test_UID(self): 175 self.assertEquals(parse_fetch_response( '* 23 FETCH (UID 76)'),176 {76: { }})177 self.assertEquals(parse_fetch_response( '* 23 FETCH (uiD 76)'),178 {76: { }})214 self.assertEquals(parse_fetch_response(['23 (UID 76)']), 215 {76: {'SEQ': 23}}) 216 self.assertEquals(parse_fetch_response(['23 (uiD 76)']), 217 {76: {'SEQ': 23}}) 179 218 180 219 … … 184 223 185 224 def test_FLAGS(self): 186 self.assertEquals(parse_fetch_response( '* 23 FETCH (FLAGS (\Seen Stuff))'),187 {23: {' FLAGS': (r'\Seen', 'Stuff')}})225 self.assertEquals(parse_fetch_response(['23 (FLAGS (\Seen Stuff))']), 226 {23: {'SEQ': 23, 'FLAGS': (r'\Seen', 'Stuff')}}) 188 227 189 228 190 229 def test_multiple_messages(self): 191 self.fail() 230 self.assertEquals(parse_fetch_response( 231 ["2 (FLAGS (Foo Bar)) ", 232 "7 (FLAGS (Baz Sneeve))"]), 233 { 234 2: {'FLAGS': ('Foo', 'Bar'), 'SEQ': 2}, 235 7: {'FLAGS': ('Baz', 'Sneeve'), 'SEQ': 7}, 236 }) 192 237 193 238 … … 217 262 # datetime.datetime(2007, 12, 9, 17, 8, 8, 0, FixedOffset(0))) 218 263 219 220 # def testMultipleMessages(self):221 # '''Test with multple messages in the response222 # '''223 # self._parse_test(224 # [225 # r'2 (FLAGS (Foo Bar))',226 # r'7 (FLAGS (Baz Sneeve))',227 # ],228 # {229 # 2: {'FLAGS': ['Foo', 'Bar']},230 # 7: {'FLAGS': ['Baz', 'Sneeve']},231 # }232 # )233 264 234 265 # def testLiteral(self):
