from textwrap import dedent
import unittest
-from imapclient.response_parser import parse_response, ParseError
+from imapclient.response_parser import parse_response, parse_fetch_response, ParseError
from imapclient.fixed_offset import FixedOffset
from pprint import pformat
#TODO: more response types
#TODO: clean up this file
-system_offset = FixedOffset.for_system()
-def datetime_to_native(dt):
- return dt.astimezone(system_offset).replace(tzinfo=None)
CRLF = '\r\n'
'got ParseError with wrong msg: %r' % str(err))
-#TODO convert the following are mainly FETCH specific tests
+system_offset = FixedOffset.for_system()
+def datetime_to_native(dt):
+ return dt.astimezone(system_offset).replace(tzinfo=None)
+
+class TestPatchFetchResponse(object):
+
+ def test_basic(self):
+ parse_fetch_response('4 FETCH ()', {'4': {}})
-# def testCharacterCase(self):
-# '''Test handling of varied case in the response type name
+ def test_non_fetch(self):
+ self.assertRaises(ParseError, parse_fetch_response, '4 OTHER ()')
+
+ def test_UID(self):
+ self.fail()
+# '''Test UID handling. The UID is returned instead of the given message
+# ID if present.
# '''
# self._parse_test(
-# [r'2 (flaGS (\Deleted Foo \Seen))'],
-# {2: {'FLAGS': [r'\Deleted', 'Foo', r'\Seen']}}
+# ['1 (UID 8)'],
+# {8: {}}
# )
-# def testGarbage(self):
-# self.assertRaises(ValueError, self.p, [r'2 (FLAGS (\Deleted) MORE)'])
+ def test_FLAGS(self):
+ self.fail()
-# def test_INTERNALDATE(self):
+ def test_INTERNALDATE(self):
+ self.fail()
# def check(date_str, expected_dt):
# output = self.p(['3 (INTERNALDATE "%s")' % date_str])
# dt = check(' 9-Dec-2007 17:08:08 +0000',
# datetime.datetime(2007, 12, 9, 17, 8, 8, 0, FixedOffset(0)))
+ def test_multiple_fields(self):
+ self.fail()
-# def testMultipleTypes(self):
-# '''Test multiple response types'''
+ def test_case_handling(self):
+ self.fail()
# self._parse_test(
-# [r'2 (FLAGS (\Deleted Foo \Seen) INTERNALDATE " 9-Feb-2007 17:08:08 +0000")'],
-# {2: {
-# 'FLAGS': [r'\Deleted', 'Foo', r'\Seen'],
-# 'INTERNALDATE': datetime_to_native(datetime.datetime(2007, 2, 9,
-# 17, 8, 8, 0,
-# FixedOffset(0)))
-# }
-# }
+# [r'2 (flaGS (\Deleted Foo \Seen))'],
+# {2: {'FLAGS': [r'\Deleted', 'Foo', r'\Seen']}}
# )
+
+ def test_invalid(self):
+ self.fail()
+# self.assertRaises(ValueError, self.p, [r'2 (FLAGS (\Deleted) MORE)'])
+# self.assertRaises(ValueError,
+# self.t.process_pairs, 'FOO 123 BAH "abc" WHAT?')
+# self.assertRaises(ValueError,
+# self.t.process_pairs, 'HMMM FOO 123 BAH "abc"')
+# self.assertRaises(ValueError,
+# self.t.process_pairs, 'FOO 123 BAD BAH "abc"')
+
+#TODO convert the following are mainly FETCH specific tests
+
+# def test_INTERNALDATE(self):
+
+
# def testMultipleMessages(self):
# '''Test with multple messages in the response
# '''
# }
# )
-# def testUID(self):
-# '''Test UID handling. The UID is returned instead of the given message
-# ID if present.
-# '''
-# self._parse_test(
-# ['1 (UID 8)'],
-# {8: {}}
-# )
def format_error(input_, output, expected):
return CRLF.join(text.splitlines()) + CRLF
-# class TestFetchTokeniser(unittest.TestCase):
-# def setUp(self):
-# self.t = FetchTokeniser()
-
-# def testEmptyList(self):
-# self._test_list('', [])
-
-# def testOneItemList(self):
-# self._test_list('123', [123])
-
-# def testWordsInList(self):
-# self._test_list('test stuff', ['test', 'stuff'])
-
-# def testQuotedStringInList(self):
-# self._test_list('"test stuff" and more', ['test stuff', 'and', 'more'])
-
-# def testNILInList(self):
-# self._test_list('test NIL stuff', ['test', None, 'stuff'])
-
-# def testEmptyListPair(self):
-# self._test_pairs('FOO ()', [('FOO', [])])
-
-# def testIntPair(self):
-# self._test_pairs('FOO 123', [('FOO', 123)])
-
-# def testQuotedStringPair(self):
-# self._test_pairs('FOO "abc def"', [('FOO', "abc def")])
-
-# def testComplexListPair(self):
-# self._test_pairs('FOO (123 "a b c" \\XYZ)', [('FOO', [123, "a b c", '\\XYZ'])])
-
-# def testMultiplePairs(self):
-# self._test_pairs('FOO 123 bar (def "XYZ") MORE "stuff"', [
-# ('FOO', 123),
-# ('bar', ['def', 'XYZ']),
-# ('MORE', 'stuff'),
-# ])
-
-# def testNoPairs(self):
-# self._test_pairs('', [])
-
-# def testGarbage(self):
-# self.assertRaises(ValueError,
-# self.t.process_pairs, 'FOO 123 BAH "abc" WHAT?')
-# self.assertRaises(ValueError,
-# self.t.process_pairs, 'HMMM FOO 123 BAH "abc"')
-# self.assertRaises(ValueError,
-# self.t.process_pairs, 'FOO 123 BAD BAH "abc"')
-
-# def testLiteral(self):
-# self._test_pairs('FOO {21}', [('FOO', Literal(21))])
-
-# def _test_pairs(self, input_, expected):
-# output = self.t.process_pairs(input_)
-# self.assert_(
-# output == expected,
-# format_error(input_, output, expected),
-# )
-# return output
-
-# def _test_list(self, input_, expected):
-# output = self.t.process_list(input_)
-# self.assert_(
-# output == expected,
-# format_error(input_, output, expected),
-# )
-# return output
-
if __name__ == '__main__':
unittest.main()