annotate Lib/test/test_MimeWriter.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 1d84bf5f9478
children 07c7664f21a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """Test program for MimeWriter module.
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 The test program was too big to comfortably fit in the MimeWriter
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 class, so it's here in its own file.
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 This should generate Barry's example, modulo some quotes and newlines.
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 """
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 41915
diff changeset
10 import unittest, StringIO
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
11 from test.test_support import run_unittest
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
41915
5c29411a05a5 Have MimeWriter raise a DeprecationWarning as per PEP 4 and its documentation.
Brett Cannon <bcannon@gmail.com>
parents: 40284
diff changeset
13 import warnings
5c29411a05a5 Have MimeWriter raise a DeprecationWarning as per PEP 4 and its documentation.
Brett Cannon <bcannon@gmail.com>
parents: 40284
diff changeset
14 warnings.filterwarnings("ignore", "the MimeWriter module is deprecated.*",
5c29411a05a5 Have MimeWriter raise a DeprecationWarning as per PEP 4 and its documentation.
Brett Cannon <bcannon@gmail.com>
parents: 40284
diff changeset
15 DeprecationWarning)
5c29411a05a5 Have MimeWriter raise a DeprecationWarning as per PEP 4 and its documentation.
Brett Cannon <bcannon@gmail.com>
parents: 40284
diff changeset
16
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 from MimeWriter import MimeWriter
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 SELLER = '''\
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 INTERFACE Seller-1;
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 TYPE Seller = OBJECT
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 DOCUMENTATION "A simple Seller interface to test ILU"
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 METHODS
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
25 price():INTEGER,
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 END;
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 '''
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 BUYER = '''\
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 class Buyer:
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 def __setup__(self, maxprice):
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
32 self._maxprice = maxprice
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 def __main__(self, kos):
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
35 """Entry point upon arrival at a new KOS."""
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
36 broker = kos.broker()
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
37 # B4 == Barry's Big Bass Business :-)
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
38 seller = broker.lookup('Seller_1.Seller', 'B4')
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
39 if seller:
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
40 price = seller.price()
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
41 print 'Seller wants $', price, '... '
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
42 if price > self._maxprice:
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
43 print 'too much!'
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
44 else:
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
45 print "I'll take it!"
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
46 else:
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
47 print 'no seller found here'
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
48 ''' # Don't ask why this comment is here
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 STATE = '''\
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 # instantiate a buyer instance and put it in a magic place for the KOS
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 # to find.
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 __kp__ = Buyer()
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 __kp__.__setup__(500)
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 '''
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 SIMPLE_METADATA = [
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
58 ("Interpreter", "python"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
59 ("Interpreter-Version", "1.3"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
60 ("Owner-Name", "Barry Warsaw"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
61 ("Owner-Rendezvous", "bwarsaw@cnri.reston.va.us"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
62 ("Home-KSS", "kss.cnri.reston.va.us"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
63 ("Identifier", "hdl://cnri.kss/my_first_knowbot"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
64 ("Launch-Date", "Mon Feb 12 16:39:03 EST 1996"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
65 ]
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 COMPLEX_METADATA = [
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
68 ("Metadata-Type", "complex"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
69 ("Metadata-Key", "connection"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
70 ("Access", "read-only"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
71 ("Connection-Description", "Barry's Big Bass Business"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
72 ("Connection-Id", "B4"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
73 ("Connection-Direction", "client"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
74 ]
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 EXTERNAL_METADATA = [
8475
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
77 ("Metadata-Type", "complex"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
78 ("Metadata-Key", "generic-interface"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
79 ("Access", "read-only"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
80 ("Connection-Description", "Generic Interface for All Knowbots"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
81 ("Connection-Id", "generic-kp"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
82 ("Connection-Direction", "client"),
f8c6cf5cfa7d Untabified -- to satisfy the tab nanny.
Guido van Rossum <guido@python.org>
parents: 8118
diff changeset
83 ]
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
86 OUTPUT = '''\
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
87 From: bwarsaw@cnri.reston.va.us
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
88 Date: Mon Feb 12 17:21:48 EST 1996
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
89 To: kss-submit@cnri.reston.va.us
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
90 MIME-Version: 1.0
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
91 Content-Type: multipart/knowbot;
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
92 boundary="801spam999";
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
93 version="0.1"
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
95 This is a multi-part message in MIME format.
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
96
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
97 --801spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
98 Content-Type: multipart/knowbot-metadata;
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
99 boundary="802spam999"
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 8475
diff changeset
100
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
101
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
102 --802spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
103 Content-Type: message/rfc822
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
104 KP-Metadata-Type: simple
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
105 KP-Access: read-only
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
107 KPMD-Interpreter: python
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
108 KPMD-Interpreter-Version: 1.3
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
109 KPMD-Owner-Name: Barry Warsaw
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
110 KPMD-Owner-Rendezvous: bwarsaw@cnri.reston.va.us
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
111 KPMD-Home-KSS: kss.cnri.reston.va.us
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
112 KPMD-Identifier: hdl://cnri.kss/my_first_knowbot
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
113 KPMD-Launch-Date: Mon Feb 12 16:39:03 EST 1996
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
115 --802spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
116 Content-Type: text/isl
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
117 KP-Metadata-Type: complex
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
118 KP-Metadata-Key: connection
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
119 KP-Access: read-only
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
120 KP-Connection-Description: Barry's Big Bass Business
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
121 KP-Connection-Id: B4
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
122 KP-Connection-Direction: client
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
124 INTERFACE Seller-1;
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
126 TYPE Seller = OBJECT
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
127 DOCUMENTATION "A simple Seller interface to test ILU"
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
128 METHODS
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
129 price():INTEGER,
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
130 END;
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
132 --802spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
133 Content-Type: message/external-body;
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
134 access-type="URL";
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
135 URL="hdl://cnri.kss/generic-knowbot"
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
137 Content-Type: text/isl
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
138 KP-Metadata-Type: complex
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
139 KP-Metadata-Key: generic-interface
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
140 KP-Access: read-only
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
141 KP-Connection-Description: Generic Interface for All Knowbots
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
142 KP-Connection-Id: generic-kp
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
143 KP-Connection-Direction: client
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
146 --802spam999--
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
148 --801spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
149 Content-Type: multipart/knowbot-code;
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
150 boundary="803spam999"
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
151
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
152
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
153 --803spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
154 Content-Type: text/plain
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
155 KP-Module-Name: BuyerKP
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
157 class Buyer:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
158 def __setup__(self, maxprice):
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
159 self._maxprice = maxprice
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
161 def __main__(self, kos):
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
162 """Entry point upon arrival at a new KOS."""
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
163 broker = kos.broker()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
164 # B4 == Barry's Big Bass Business :-)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
165 seller = broker.lookup('Seller_1.Seller', 'B4')
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
166 if seller:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
167 price = seller.price()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
168 print 'Seller wants $', price, '... '
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
169 if price > self._maxprice:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
170 print 'too much!'
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
171 else:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
172 print "I'll take it!"
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
173 else:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
174 print 'no seller found here'
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
176 --803spam999--
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
178 --801spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
179 Content-Type: multipart/knowbot-state;
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
180 boundary="804spam999"
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
181 KP-Main-Module: main
8118
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
7cf51657b08c Add test for MimeWriter module
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
184 --804spam999
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
185 Content-Type: text/plain
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
186 KP-Module-Name: main
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
187
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
188 # instantiate a buyer instance and put it in a magic place for the KOS
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
189 # to find.
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
190 __kp__ = Buyer()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
191 __kp__.__setup__(500)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
192
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
193 --804spam999--
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
194
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
195 --801spam999--
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
196 '''
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
197
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
198 class MimewriterTest(unittest.TestCase):
40284
ff678669aa6e Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 40266
diff changeset
199
40266
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
200 def test(self):
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
201 buf = StringIO.StringIO()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
202
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
203 # Toplevel headers
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
204
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
205 toplevel = MimeWriter(buf)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
206 toplevel.addheader("From", "bwarsaw@cnri.reston.va.us")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
207 toplevel.addheader("Date", "Mon Feb 12 17:21:48 EST 1996")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
208 toplevel.addheader("To", "kss-submit@cnri.reston.va.us")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
209 toplevel.addheader("MIME-Version", "1.0")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
210
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
211 # Toplevel body parts
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
212
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
213 f = toplevel.startmultipartbody("knowbot", "801spam999",
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
214 [("version", "0.1")], prefix=0)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
215 f.write("This is a multi-part message in MIME format.\n")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
216
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
217 # First toplevel body part: metadata
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
218
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
219 md = toplevel.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
220 md.startmultipartbody("knowbot-metadata", "802spam999")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
221
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
222 # Metadata part 1
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
223
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
224 md1 = md.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
225 md1.addheader("KP-Metadata-Type", "simple")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
226 md1.addheader("KP-Access", "read-only")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
227 m = MimeWriter(md1.startbody("message/rfc822"))
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
228 for key, value in SIMPLE_METADATA:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
229 m.addheader("KPMD-" + key, value)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
230 m.flushheaders()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
231 del md1
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
232
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
233 # Metadata part 2
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
234
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
235 md2 = md.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
236 for key, value in COMPLEX_METADATA:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
237 md2.addheader("KP-" + key, value)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
238 f = md2.startbody("text/isl")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
239 f.write(SELLER)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
240 del md2
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
241
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
242 # Metadata part 3
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
243
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
244 md3 = md.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
245 f = md3.startbody("message/external-body",
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
246 [("access-type", "URL"),
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
247 ("URL", "hdl://cnri.kss/generic-knowbot")])
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
248 m = MimeWriter(f)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
249 for key, value in EXTERNAL_METADATA:
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
250 md3.addheader("KP-" + key, value)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
251 md3.startbody("text/isl")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
252 # Phantom body doesn't need to be written
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
253
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
254 md.lastpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
255
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
256 # Second toplevel body part: code
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
257
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
258 code = toplevel.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
259 code.startmultipartbody("knowbot-code", "803spam999")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
260
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
261 # Code: buyer program source
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
262
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
263 buyer = code.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
264 buyer.addheader("KP-Module-Name", "BuyerKP")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
265 f = buyer.startbody("text/plain")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
266 f.write(BUYER)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
267
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
268 code.lastpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
269
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
270 # Third toplevel body part: state
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
271
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
272 state = toplevel.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
273 state.addheader("KP-Main-Module", "main")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
274 state.startmultipartbody("knowbot-state", "804spam999")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
275
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
276 # State: a bunch of assignments
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
277
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
278 st = state.nextpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
279 st.addheader("KP-Module-Name", "main")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
280 f = st.startbody("text/plain")
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
281 f.write(STATE)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
282
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
283 state.lastpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
284
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
285 # End toplevel body parts
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
286
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
287 toplevel.lastpart()
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
288
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
289 self.assertEqual(buf.getvalue(), OUTPUT)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
290
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
291 def test_main():
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
292 run_unittest(MimewriterTest)
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
293
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
294 if __name__ == '__main__':
1007328f9db5 Convert test_MimeWriter to unittest.
Georg Brandl <georg@python.org>
parents: 15305
diff changeset
295 test_main()