Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e8328ba7
Kaydet (Commit)
e8328ba7
authored
Eki 29, 2006
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Convert test_MimeWriter to unittest.
üst
71a20897
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
174 deletions
+185
-174
test_MimeWriter
Lib/test/output/test_MimeWriter
+0
-110
test_MimeWriter.py
Lib/test/test_MimeWriter.py
+185
-64
No files found.
Lib/test/output/test_MimeWriter
deleted
100644 → 0
Dosyayı görüntüle @
71a20897
test_MimeWriter
From: bwarsaw@cnri.reston.va.us
Date: Mon Feb 12 17:21:48 EST 1996
To: kss-submit@cnri.reston.va.us
MIME-Version: 1.0
Content-Type: multipart/knowbot;
boundary="801spam999";
version="0.1"
This is a multi-part message in MIME format.
--801spam999
Content-Type: multipart/knowbot-metadata;
boundary="802spam999"
--802spam999
Content-Type: message/rfc822
KP-Metadata-Type: simple
KP-Access: read-only
KPMD-Interpreter: python
KPMD-Interpreter-Version: 1.3
KPMD-Owner-Name: Barry Warsaw
KPMD-Owner-Rendezvous: bwarsaw@cnri.reston.va.us
KPMD-Home-KSS: kss.cnri.reston.va.us
KPMD-Identifier: hdl://cnri.kss/my_first_knowbot
KPMD-Launch-Date: Mon Feb 12 16:39:03 EST 1996
--802spam999
Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: connection
KP-Access: read-only
KP-Connection-Description: Barry's Big Bass Business
KP-Connection-Id: B4
KP-Connection-Direction: client
INTERFACE Seller-1;
TYPE Seller = OBJECT
DOCUMENTATION "A simple Seller interface to test ILU"
METHODS
price():INTEGER,
END;
--802spam999
Content-Type: message/external-body;
access-type="URL";
URL="hdl://cnri.kss/generic-knowbot"
Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: generic-interface
KP-Access: read-only
KP-Connection-Description: Generic Interface for All Knowbots
KP-Connection-Id: generic-kp
KP-Connection-Direction: client
--802spam999--
--801spam999
Content-Type: multipart/knowbot-code;
boundary="803spam999"
--803spam999
Content-Type: text/plain
KP-Module-Name: BuyerKP
class Buyer:
def __setup__(self, maxprice):
self._maxprice = maxprice
def __main__(self, kos):
"""Entry point upon arrival at a new KOS."""
broker = kos.broker()
# B4 == Barry's Big Bass Business :-)
seller = broker.lookup('Seller_1.Seller', 'B4')
if seller:
price = seller.price()
print 'Seller wants $', price, '... '
if price > self._maxprice:
print 'too much!'
else:
print "I'll take it!"
else:
print 'no seller found here'
--803spam999--
--801spam999
Content-Type: multipart/knowbot-state;
boundary="804spam999"
KP-Main-Module: main
--804spam999
Content-Type: text/plain
KP-Module-Name: main
# instantiate a buyer instance and put it in a magic place for the KOS
# to find.
__kp__ = Buyer()
__kp__.__setup__(500)
--804spam999--
--801spam999--
Lib/test/test_MimeWriter.py
Dosyayı görüntüle @
e8328ba7
...
...
@@ -7,6 +7,8 @@ This should generate Barry's example, modulo some quotes and newlines.
"""
import
unittest
,
sys
,
StringIO
from
test.test_support
import
run_unittest
from
MimeWriter
import
MimeWriter
...
...
@@ -77,94 +79,213 @@ EXTERNAL_METADATA = [
]
def
main
():
import
sys
OUTPUT
=
'''
\
From: bwarsaw@cnri.reston.va.us
Date: Mon Feb 12 17:21:48 EST 1996
To: kss-submit@cnri.reston.va.us
MIME-Version: 1.0
Content-Type: multipart/knowbot;
boundary="801spam999";
version="0.1"
This is a multi-part message in MIME format.
--801spam999
Content-Type: multipart/knowbot-metadata;
boundary="802spam999"
--802spam999
Content-Type: message/rfc822
KP-Metadata-Type: simple
KP-Access: read-only
KPMD-Interpreter: python
KPMD-Interpreter-Version: 1.3
KPMD-Owner-Name: Barry Warsaw
KPMD-Owner-Rendezvous: bwarsaw@cnri.reston.va.us
KPMD-Home-KSS: kss.cnri.reston.va.us
KPMD-Identifier: hdl://cnri.kss/my_first_knowbot
KPMD-Launch-Date: Mon Feb 12 16:39:03 EST 1996
--802spam999
Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: connection
KP-Access: read-only
KP-Connection-Description: Barry's Big Bass Business
KP-Connection-Id: B4
KP-Connection-Direction: client
# Toplevel headers
INTERFACE Seller-1;
TYPE Seller = OBJECT
DOCUMENTATION "A simple Seller interface to test ILU"
METHODS
price():INTEGER,
END;
--802spam999
Content-Type: message/external-body;
access-type="URL";
URL="hdl://cnri.kss/generic-knowbot"
Content-Type: text/isl
KP-Metadata-Type: complex
KP-Metadata-Key: generic-interface
KP-Access: read-only
KP-Connection-Description: Generic Interface for All Knowbots
KP-Connection-Id: generic-kp
KP-Connection-Direction: client
--802spam999--
--801spam999
Content-Type: multipart/knowbot-code;
boundary="803spam999"
--803spam999
Content-Type: text/plain
KP-Module-Name: BuyerKP
class Buyer:
def __setup__(self, maxprice):
self._maxprice = maxprice
def __main__(self, kos):
"""Entry point upon arrival at a new KOS."""
broker = kos.broker()
# B4 == Barry's Big Bass Business :-)
seller = broker.lookup('Seller_1.Seller', 'B4')
if seller:
price = seller.price()
print 'Seller wants $', price, '... '
if price > self._maxprice:
print 'too much!'
else:
print "I'll take it!"
else:
print 'no seller found here'
--803spam999--
--801spam999
Content-Type: multipart/knowbot-state;
boundary="804spam999"
KP-Main-Module: main
--804spam999
Content-Type: text/plain
KP-Module-Name: main
# instantiate a buyer instance and put it in a magic place for the KOS
# to find.
__kp__ = Buyer()
__kp__.__setup__(500)
--804spam999--
--801spam999--
'''
class
MimewriterTest
(
unittest
.
TestCase
):
def
test
(
self
):
buf
=
StringIO
.
StringIO
()
# Toplevel headers
toplevel
=
MimeWriter
(
buf
)
toplevel
.
addheader
(
"From"
,
"bwarsaw@cnri.reston.va.us"
)
toplevel
.
addheader
(
"Date"
,
"Mon Feb 12 17:21:48 EST 1996"
)
toplevel
.
addheader
(
"To"
,
"kss-submit@cnri.reston.va.us"
)
toplevel
.
addheader
(
"MIME-Version"
,
"1.0"
)
toplevel
=
MimeWriter
(
sys
.
stdout
)
toplevel
.
addheader
(
"From"
,
"bwarsaw@cnri.reston.va.us"
)
toplevel
.
addheader
(
"Date"
,
"Mon Feb 12 17:21:48 EST 1996"
)
toplevel
.
addheader
(
"To"
,
"kss-submit@cnri.reston.va.us"
)
toplevel
.
addheader
(
"MIME-Version"
,
"1.0"
)
# Toplevel body parts
# Toplevel body parts
f
=
toplevel
.
startmultipartbody
(
"knowbot"
,
"801spam999"
,
[(
"version"
,
"0.1"
)],
prefix
=
0
)
f
.
write
(
"This is a multi-part message in MIME format.
\n
"
)
f
=
toplevel
.
startmultipartbody
(
"knowbot"
,
"801spam999"
,
[(
"version"
,
"0.1"
)],
prefix
=
0
)
f
.
write
(
"This is a multi-part message in MIME format.
\n
"
)
# First toplevel body part: metadata
# First toplevel body part: metadata
md
=
toplevel
.
nextpart
()
md
.
startmultipartbody
(
"knowbot-metadata"
,
"802spam999"
)
md
=
toplevel
.
nextpart
()
md
.
startmultipartbody
(
"knowbot-metadata"
,
"802spam999"
)
# Metadata part 1
# Metadata part 1
md1
=
md
.
nextpart
()
md1
.
addheader
(
"KP-Metadata-Type"
,
"simple"
)
md1
.
addheader
(
"KP-Access"
,
"read-only"
)
m
=
MimeWriter
(
md1
.
startbody
(
"message/rfc822"
))
for
key
,
value
in
SIMPLE_METADATA
:
m
.
addheader
(
"KPMD-"
+
key
,
value
)
m
.
flushheaders
()
del
md1
md1
=
md
.
nextpart
()
md1
.
addheader
(
"KP-Metadata-Type"
,
"simple"
)
md1
.
addheader
(
"KP-Access"
,
"read-only"
)
m
=
MimeWriter
(
md1
.
startbody
(
"message/rfc822"
))
for
key
,
value
in
SIMPLE_METADATA
:
m
.
addheader
(
"KPMD-"
+
key
,
value
)
m
.
flushheaders
()
del
md1
# Metadata part 2
# Metadata part 2
md2
=
md
.
nextpart
()
for
key
,
value
in
COMPLEX_METADATA
:
md2
.
addheader
(
"KP-"
+
key
,
value
)
f
=
md2
.
startbody
(
"text/isl"
)
f
.
write
(
SELLER
)
del
md2
md2
=
md
.
nextpart
()
for
key
,
value
in
COMPLEX_METADATA
:
md2
.
addheader
(
"KP-"
+
key
,
value
)
f
=
md2
.
startbody
(
"text/isl"
)
f
.
write
(
SELLER
)
del
md2
# Metadata part 3
# Metadata part 3
md3
=
md
.
nextpart
()
f
=
md3
.
startbody
(
"message/external-body"
,
[(
"access-type"
,
"URL"
),
(
"URL"
,
"hdl://cnri.kss/generic-knowbot"
)])
m
=
MimeWriter
(
f
)
for
key
,
value
in
EXTERNAL_METADATA
:
md3
.
addheader
(
"KP-"
+
key
,
value
)
md3
.
startbody
(
"text/isl"
)
# Phantom body doesn't need to be written
md3
=
md
.
nextpart
()
f
=
md3
.
startbody
(
"message/external-body"
,
[(
"access-type"
,
"URL"
),
(
"URL"
,
"hdl://cnri.kss/generic-knowbot"
)])
m
=
MimeWriter
(
f
)
for
key
,
value
in
EXTERNAL_METADATA
:
md3
.
addheader
(
"KP-"
+
key
,
value
)
md3
.
startbody
(
"text/isl"
)
# Phantom body doesn't need to be written
md
.
lastpart
()
md
.
lastpart
()
# Second toplevel body part: code
# Second toplevel body part: code
code
=
toplevel
.
nextpart
()
code
.
startmultipartbody
(
"knowbot-code"
,
"803spam999"
)
code
=
toplevel
.
nextpart
()
code
.
startmultipartbody
(
"knowbot-code"
,
"803spam999"
)
# Code: buyer program source
# Code: buyer program source
buyer
=
code
.
nextpart
()
buyer
.
addheader
(
"KP-Module-Name"
,
"BuyerKP"
)
f
=
buyer
.
startbody
(
"text/plain"
)
f
.
write
(
BUYER
)
buyer
=
code
.
nextpart
()
buyer
.
addheader
(
"KP-Module-Name"
,
"BuyerKP"
)
f
=
buyer
.
startbody
(
"text/plain"
)
f
.
write
(
BUYER
)
code
.
lastpart
()
code
.
lastpart
()
# Third toplevel body part: state
# Third toplevel body part: state
state
=
toplevel
.
nextpart
()
state
.
addheader
(
"KP-Main-Module"
,
"main"
)
state
.
startmultipartbody
(
"knowbot-state"
,
"804spam999"
)
state
=
toplevel
.
nextpart
()
state
.
addheader
(
"KP-Main-Module"
,
"main"
)
state
.
startmultipartbody
(
"knowbot-state"
,
"804spam999"
)
# State: a bunch of assignments
# State: a bunch of assignments
st
=
state
.
nextpart
()
st
.
addheader
(
"KP-Module-Name"
,
"main"
)
f
=
st
.
startbody
(
"text/plain"
)
f
.
write
(
STATE
)
st
=
state
.
nextpart
()
st
.
addheader
(
"KP-Module-Name"
,
"main"
)
f
=
st
.
startbody
(
"text/plain"
)
f
.
write
(
STATE
)
state
.
lastpart
()
state
.
lastpart
()
# End toplevel body parts
# End toplevel body parts
toplevel
.
lastpart
()
toplevel
.
lastpart
(
)
self
.
assertEqual
(
buf
.
getvalue
(),
OUTPUT
)
def
test_main
():
run_unittest
(
MimewriterTest
)
main
()
if
__name__
==
'__main__'
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment