Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97877102
ut_attribute.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jan 7, 02:15
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Jan 9, 02:15 (2 d)
Engine
blob
Format
Raw Data
Handle
23425596
Attached To
R3596 pybliographer
ut_attribute.py
View Options
This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
# -*- coding: latin-1 -*-
import
os
,
pybut
,
sys
import
StringIO
from
Pyblio
import
Attribute
class
TestAttribute
(
pybut
.
TestCase
):
""" Perform tests on the Pyblio.Attribute module """
def
_check
(
self
,
o
,
txt
):
xml
=
StringIO
.
StringIO
()
o
.
xmlwrite
(
xml
)
xml
=
xml
.
getvalue
()
txt
=
txt
.
encode
(
'utf-8'
)
assert
xml
==
txt
,
'unexpected:
%s
(expecting
%s
)'
%
(
xml
,
txt
)
return
def
testPerson
(
self
):
""" Check the XML output of a person """
self
.
_check
(
Attribute
.
Person
(
last
=
u'Gobry'
,
first
=
u'Frédéric'
),
u'<person first="Frédéric" last="Gobry"/>'
)
self
.
_check
(
Attribute
.
Person
(
honorific
=
u'Dr.'
,
last
=
u'Gobry'
,
first
=
u'Frédéric'
,
lineage
=
u'Jr.'
),
u'<person honorific="Dr." first="Frédéric" '
'last="Gobry" lineage="Jr."/>'
)
return
def
testDate
(
self
):
txt
=
u'héhé
\n
huhu'
self
.
_check
(
Attribute
.
Date
(
year
=
2003
),
u'<date year="2003"/>'
)
self
.
_check
(
Attribute
.
Date
(
year
=
2003
,
month
=
12
),
u'<date year="2003" month="12"/>'
)
self
.
_check
(
Attribute
.
Date
(
year
=
2003
,
month
=
12
,
day
=
25
),
u'<date year="2003" month="12" day="25"/>'
)
assert
Attribute
.
Date
(
year
=
2000
)
>
None
assert
None
<
Attribute
.
Date
(
year
=
2000
)
return
def
testText
(
self
):
self
.
_check
(
Attribute
.
Text
(
u'héhé
\n
huhu'
),
u'<text>héhé
\n
huhu</text>'
)
return
def
testURL
(
self
):
self
.
_check
(
Attribute
.
URL
(
'http://pybliographer.org/'
),
u'<url href="http://pybliographer.org/"/>'
)
return
def
testID
(
self
):
self
.
_check
(
Attribute
.
ID
(
u'87657ejh#{[|é<'
),
u'<id value="87657ejh#{[|é<"/>'
)
return
def
testTxo
(
self
):
from
Pyblio.Schema
import
TxoItem
i
=
TxoItem
()
i
.
id
=
123
i
.
group
=
'a'
self
.
_check
(
Attribute
.
Txo
(
i
),
u'<txo group="a" id="123"/>'
)
return
def
testIndex
(
self
):
idx
=
Attribute
.
Text
(
u"HÉHÉ les Gens, s'il vous plaît."
)
.
index
()
assert
idx
==
[
u'héhé'
,
'les'
,
'gens'
,
's'
,
'il'
,
'vous'
,
u'plaît'
],
`idx`
idx
=
Attribute
.
Person
(
first
=
u'Jean-Albert'
,
last
=
u'Dââ Schnock'
)
.
index
()
assert
idx
==
[
'jean'
,
'albert'
,
u'dââ'
,
'schnock'
]
idx
=
Attribute
.
URL
(
'http://www.pybliographer.org/faq/toto.html'
)
.
index
()
assert
idx
==
[
'www'
,
'pybliographer'
,
'org'
,
'faq'
,
'toto'
]
assert
Attribute
.
Date
(
year
=
2003
)
.
index
()
==
[]
return
def
testSort
(
self
):
coll
=
Attribute
.
Text
(
u"HÉHÉ les Gens, s'il vous plaît."
)
.
sort
()
assert
coll
==
u"héhé les gens, s'il vous plaît."
coll
=
Attribute
.
Person
(
first
=
u'Jean-Albert'
,
last
=
u'Dââ Schnock'
)
.
sort
()
assert
coll
==
u"dââ schnock
\0
jean-albert"
for
d
,
c
in
(((
2003
,
None
,
None
),
'20030000'
),
((
2003
,
11
,
None
),
'20031100'
),
((
2003
,
11
,
13
),
'20031113'
)):
coll
=
Attribute
.
Date
(
year
=
d
[
0
],
month
=
d
[
1
],
day
=
d
[
2
])
.
sort
()
assert
coll
==
c
coll
=
Attribute
.
URL
(
'http://pybliographer.org/FAQ/'
)
.
sort
()
assert
coll
==
'http://pybliographer.org/FAQ/'
return
suite
=
pybut
.
suite
(
TestAttribute
)
if
__name__
==
'__main__'
:
pybut
.
run
(
suite
)
Event Timeline
Log In to Comment