From: <mr...@bl...> - 2004-09-28 00:58:52
|
Author: mrowe Date: 2004-09-28 12:58:42 +1200 (Tue, 28 Sep 2004) New Revision: 246 Added: branches/libmsn-experimental/python/test/ branches/libmsn-experimental/python/test/test_Message.py branches/libmsn-experimental/python/test/test__MIMEMessage.py branches/libmsn-experimental/python/test/test_util.py Removed: branches/libmsn-experimental/python/test_Message.py branches/libmsn-experimental/python/test__MIMEMessage.py branches/libmsn-experimental/python/test_util.py Modified: branches/libmsn-experimental/python/Jamfile Log: Move tests to their own subdirectory for cleanliness. Modified: branches/libmsn-experimental/python/Jamfile =================================================================== --- branches/libmsn-experimental/python/Jamfile 2004-09-27 13:24:23 UTC (rev 245) +++ branches/libmsn-experimental/python/Jamfile 2004-09-28 00:58:42 UTC (rev 246) @@ -20,9 +20,10 @@ boost-python-runtest testMSN : # Python test driver test.py - test_Message.py - test__MIMEMessage.py - test_util.py + test/test_util.py + test/test__MIMEMessage.py + test/test_Message.py + # extension modules to use <pyd>MSN ; \ No newline at end of file Copied: branches/libmsn-experimental/python/test/test_Message.py (from rev 238, branches/libmsn-experimental/python/test_Message.py) Copied: branches/libmsn-experimental/python/test/test__MIMEMessage.py (from rev 241, branches/libmsn-experimental/python/test__MIMEMessage.py) Copied: branches/libmsn-experimental/python/test/test_util.py (from rev 245, branches/libmsn-experimental/python/test_util.py) Deleted: branches/libmsn-experimental/python/test_Message.py =================================================================== --- branches/libmsn-experimental/python/test_Message.py 2004-09-27 13:24:23 UTC (rev 245) +++ branches/libmsn-experimental/python/test_Message.py 2004-09-28 00:58:42 UTC (rev 246) @@ -1,114 +0,0 @@ -import unittest, MSN - -validMessage = """\ -Content-Type: text/plain; charset=UTF-8 -MIME-Version: 1.0 -X-MMS-IM-Format: FN=Lucida%20Grande; CO=000000; EF=; PF=00 - -Hi -This is the message""" - -anotherValidMessage = """\ -Content-Type: text/plain; charset=UTF-8 -MIME-Version: 1.0 -X-MMS-IM-Format: CO=000000; EF=; PF=00; FN=Lucida%20Grande - -Hi -This is the message""" - - -class TestInitialization(unittest.TestCase): - def testInitWithNoArgs(self): - """ - MSN.Message should create a message with correct Content-Type and MIME-Version headers, and an empty body. - - This test is currently dependent on the generated order of headers. - """ - m = MSN.Message() - self.assertEquals(m.rawMessage(), "Content-Type: text/plain; charset=UTF-8\nMIME-Version: 1.0\n\n") - self.assertEquals(m.getBody(), "") - - def testInitWithArgs(self): - """ - Parsing a message should result in the correct message body being returned. - """ - m = MSN.Message(validMessage) - self.assertEquals(m.getBody(), "Hi\nThis is the message") - -class TestFormatting(unittest.TestCase): - def setUp(self): - self.m1 = MSN.Message(validMessage) - self.m2 = MSN.Message(anotherValidMessage) - self.m3 = MSN.Message() - - def testGetColor(self): - """ - Parsing message format header should return correct color if present, or the empty string if not. - """ - self.assertEquals(self.m1.hasColor, True) - self.assertEquals(self.m1.getColor(), "000000") - - self.assertEquals(self.m3.hasColor, False) - self.assertEquals(self.m3.getColor(), "") - - def testSetColor(self): - """ - Setting the color should work: - a) When there was no format header - b) When there was a format header but no color - c) When there was a format header with a color specified - """ - color = "133337" - self.assertEquals(self.m3.getColor(), "") - self.m3.setColor(color) - self.assertEquals(self.m3.getColor(), color) - - self.assertEquals(self.m1.getColor(), "000000") - self.m1.setColor(color) - self.assertEquals(self.m1.getColor(), color) - - self.m2['X-MMS-IM-Format'] = '' - self.m2.setColor(color) - self.assertEquals(self.m2.getColor(), color) - - def testGetFontName(self): - """ - Parsing message format header should return correct font name if present, or the empty string if not. - - Three cases to consider: - a) font name is first in format header - b) font header is in middle - c) font header is last - """ - self.assertEquals(self.m1.hasFontName, True) - self.assertEquals(self.m1.getFontName(), "Lucida Grande") - self.assertEquals(self.m2.hasFontName, True) - self.assertEquals(self.m2.getFontName(), "Lucida Grande") - - self.assertEquals(self.m3.hasFontName, False) - self.assertEquals(self.m3.getFontName(), "") - - def testSetFontName(self): - """ - Setting the font name should work: - a) When there was no format header - b) When there was a format header but no font name - c) When there was a format header with a font name specified - """ - fontName = "Courier New" - self.assertEquals(self.m3.getFontName(), "") - self.m3.setFontName(fontName) - self.assertEquals(self.m3.getFontName(), fontName) - - self.assertEquals(self.m1.getFontName(), "Lucida Grande") - self.m1.setFontName(fontName) - self.assertEquals(self.m1.getFontName(), fontName) - - self.m2['X-MMS-IM-Format'] = '' - self.m2.setFontName(fontName) - self.assertEquals(self.m2.getFontName(), fontName) - self.assertEquals(self.m2['X-MMS-IM-Format'], 'FN=Courier%20New') - - -if __name__ == '__main__': - unittest.main() Deleted: branches/libmsn-experimental/python/test__MIMEMessage.py =================================================================== --- branches/libmsn-experimental/python/test__MIMEMessage.py 2004-09-27 13:24:23 UTC (rev 245) +++ branches/libmsn-experimental/python/test__MIMEMessage.py 2004-09-28 00:58:42 UTC (rev 246) @@ -1,70 +0,0 @@ -import unittest, MSN - -validMessage = """\ -Content-Type: text/plain; charset=UTF-8 -MIME-Version: 1.0 -X-MMS-IM-Format: FN=Lucida%20Grande; CO=000000; EF=; PF=00 - -Hi -This is the message""" - -class TestInitialization(unittest.TestCase): - def testInitWithNoArgs(self): - m = MSN._MIMEMessage() - self.assertEquals(m.rawMessage(), "\n") - self.assertEquals(m.getBody(), "") - - def testInitWithArgs(self): - m = MSN._MIMEMessage(validMessage) - self.assertEquals(m.rawMessage(), validMessage) - self.assertEquals(m.getBody(), "Hi\nThis is the message") - - def testInitWithInvalidMessage(self): - invalidMessage = """\ -Content-Type: text/plain; charset=UTF-8""" - self.assertRaises(MSN._MIMEParsingError, MSN._MIMEMessage, invalidMessage) - -class TestIndexing(unittest.TestCase): - def setUp(self): - self.m = MSN._MIMEMessage(validMessage) - - def testReading(self): - self.assertEquals(self.m["MIME-Version"], "1.0") - self.assertEquals(self.m["Content-Type"], "text/plain; charset=UTF-8") - - def testWriting(self): - self.m["aHeader"] = "1" - self.assertEquals(self.m["aHeader"], "1") - self.m["aHeader"] = "2" - self.assertEquals(self.m["aHeader"], "2") - - def testReadingInvalidKey(self): - """ - Verify correct behaviour when reading non-existant header. - """ - self.assertRaises(KeyError, lambda: self.m["aNonExistantHeader"]) - - def testWritingInvalidKey(self): - """ - It makes no sense to set headers with the following properties: - a) Empty name - b) ??? Containing whitespace in the name - """ - self.assertRaises(RuntimeError, self.m.__setitem__, "", "aValue") - -class TestManipulatingBody(unittest.TestCase): - def setUp(self): - self.m = MSN._MIMEMessage(validMessage) - - def testFunctions(self): - self.assertEquals(self.m.getBody(), "Hi\nThis is the message") - self.m.setBody("Body") - self.assertEquals(self.m.getBody(), "Body") - - def testAttributes(self): - self.assertEquals(self.m.body, "Hi\nThis is the message") - self.m.body = "Body" - self.assertEquals(self.m.body, "Body") - -if __name__ == '__main__': - unittest.main() Deleted: branches/libmsn-experimental/python/test_util.py =================================================================== --- branches/libmsn-experimental/python/test_util.py 2004-09-27 13:24:23 UTC (rev 245) +++ branches/libmsn-experimental/python/test_util.py 2004-09-28 00:58:42 UTC (rev 246) @@ -1,140 +0,0 @@ -import unittest, MSN - -class TestEncodeURL(unittest.TestCase): - def testSimple(self): - enc = MSN.encodeURL - self.assertEquals('a', enc('a')) - self.assertEquals('abcdef', enc('abcdef')) - self.assertEquals('%20', enc(' ')) - self.assertEquals('a%20b', enc('a b')) - self.assert_('.' not in enc('a.b')) - - def testComplex(self): - enc = MSN.encodeURL - encodeable = [chr(c) for c in range(256) if not chr(c).isalnum()] - for c in encodeable: - self.assertNotEquals(c, enc(c)) - -class TestDecodeURL(unittest.TestCase): - def testSimple(self): - dec = MSN.decodeURL - self.assertEquals('a', dec('a')) - self.assertEquals('abcdef', dec('abcdef')) - self.assertEquals(' ', dec('%20')) - self.assertEquals('a b', dec('a%20b')) - self.assert_('.' in dec('a%2eb')) - - def testComplex(self): - dec = MSN.decodeURL - decodeable = ['%%%02x' % (i, ) for i in range(256)] - for c in decodeable: - self.assertNotEquals(c, dec(c)) - self.assert_('%' not in dec(c) or dec(c) == '%') - - def testDecodeInvalid(self): - self.assertRaises(RuntimeError, MSN.decodeURL, "%g") - self.assertRaises(RuntimeError, MSN.decodeURL, "%gg") - self.assertRaises(RuntimeError, MSN.decodeURL, "%") - self.assertRaises(RuntimeError, MSN.decodeURL, "%f") - -class TestEncodeAndDecodeURL(unittest.TestCase): - def testRoundTripSimple(self): - enc = MSN.encodeURL - dec = MSN.decodeURL - for s in ('a', 'abcdef', 'a b c', - './{}# '): - self.assertEquals(s, dec(enc(s))) - - def testRoundTripComplex(self): - enc = MSN.encodeURL - dec = MSN.decodeURL - encodeable = [chr(c) for c in range(256) if not chr(c).isalnum()] - for c in encodeable: - self.assertEquals(c, dec(enc(c))) - -class TestSplitServerAddress(unittest.TestCase): - def testSplitServerAddress(self): - """ - A valid server address is a string of the format 'host[:port]', with - port defaulting to 1863 if not specified. - - It needs to be determined if host can be a domain name, or should only - be an IP. - """ - split = MSN.splitServerAddress - for addr, result in [('123.123.123.123', ('123.123.123.123', 1863)), - ('123.123.123.123:1863', ('123.123.123.123', 1863)), - ('123.123.123.123:123', ('123.123.123.123', 123)),]: - self.assertEquals(result, split(addr)) - - def testSplitServerAddressFails(self): - """ - Server addresses that result in an empty host portion are invalid. - Server addresses with missing or negative port numbers are invalid. - """ - split = MSN.splitServerAddress - for addr in ['', ':1863', ':123', '123.123.123.123:', '123.123.123.123:-100']: - self.assertRaises(RuntimeError, split, addr) - -class TestSplitString(unittest.TestCase): - """ - Test for correct results when splitting strings. - """ - def testSuppressBlanks(self): - for s, result in [('a', ['a']), - ('abcd', ['abcd']), - ('a:b', ['a', 'b']), - ('a::b', ['a', 'b']), - ('a:b:c', ['a', 'b', 'c']), - ('a::b::c', ['a', 'b', 'c']), - ('a:b::c', ['a', 'b', 'c']), - ('ab:cd:ef', ['ab', 'cd', 'ef']), - ('ab:cd:', ['ab', 'cd']), - (':ab:cd', ['ab', 'cd']), - ('', [])]: - self.assertEquals(result, MSN.splitString(s, ':')) - - for s, result in [('a', ['a']), - ('abcd', ['abcd']), - ('a:b', ['a:b']), - ('a::c', ['a::c']), - ('ab:::cd', ['ab', 'cd']), - ('ab::::', ['ab', ':']), - ('ab:::', ['ab']), - (':::ab', ['ab']), - ('::::ab', [':ab']), - ('', [])]: - self.assertEquals(result, MSN.splitString(s, ':::')) - - self.assertEquals(['a', 'b', 'c', 'd'], MSN.splitString('abcd', '')) - - def testDoNotSuppressBlanks(self): - for s, result in [('a', ['a']), - ('abcd', ['abcd']), - ('a:b', ['a', 'b']), - ('a::b', ['a', '', 'b']), - ('a:b:c', ['a', 'b', 'c']), - ('a::b::c', ['a', '', 'b', '', 'c']), - ('a:b::c', ['a', 'b', '', 'c']), - ('ab:cd:ef', ['ab', 'cd', 'ef']), - ('ab:cd:', ['ab', 'cd', '']), - (':ab:cd', ['', 'ab', 'cd']), - ('', [''])]: - self.assertEquals(result, MSN.splitString(s, ':', False)) - - for s, result in [('a', ['a']), - ('abcd', ['abcd']), - ('a:b', ['a:b']), - ('a::c', ['a::c']), - ('ab:::cd', ['ab', 'cd']), - ('ab::::::cd', ['ab', '', 'cd']), - ('ab:::', ['ab', '']), - ('ab::::', ['ab', ':']), - (':::ab', ['', 'ab']), - ('::::ab', ['', ':ab']), - ('', [''])]: - self.assertEquals(result, MSN.splitString(s, ':::', False)) - - self.assertEquals(['a', 'b', 'c', 'd'], MSN.splitString('abcd', '', False)) -if __name__ == '__main__': - unittest.main() |