eba081958aa81d24496e78f5aa7f9f07e4e20597
3 from nose
.tools
import *
5 from pokedex
.db
import tables
, connect
7 class TestStrings(object):
9 self
.connection
= connect()
12 self
.connection
.rollback()
14 def test_filter(self
):
15 q
= self
.connection
.query(tables
.Pokemon
).filter(
16 tables
.Pokemon
.name
== u
"Marowak")
17 assert q
.one().identifier
== 'marowak'
20 # Assuming that the identifiers are just lowercase names
21 q1
= self
.connection
.query(tables
.Pokemon
).filter(
22 tables
.Pokemon
.name
> u
"Xatu").order_by(
24 q2
= self
.connection
.query(tables
.Pokemon
).filter(
25 tables
.Pokemon
.identifier
> u
"xatu").order_by(
27 assert q1
.all() == q2
.all()
29 def test_languages(self
):
30 q
= self
.connection
.query(tables
.Pokemon
).filter(
31 tables
.Pokemon
.name
== u
"Mightyena")
36 ('roomaji', u
'Guraena'),
39 assert pkmn
.names
[lang
] == name
42 def test_bad_lang(self
):
43 q
= self
.connection
.query(tables
.Pokemon
).filter(
44 tables
.Pokemon
.name
== u
"Mightyena")
46 pkmn
.names
["identifier of a language that doesn't exist"]
48 def test_mutating(self
):
49 item
= self
.connection
.query(tables
.Item
).filter_by(
50 identifier
=u
"jade-orb").one()
51 language
= self
.connection
.query(tables
.Language
).filter_by(
52 identifier
=u
"de").one()
53 item
.names
['de'] = u
"foo"
54 assert item
.names
['de'] == "foo"
55 assert item
.names
[language
] == "foo"
56 item
.names
[language
] = u
"xyzzy"
57 assert item
.names
['de'] == "xyzzy"
58 assert item
.names
[language
] == "xyzzy"
60 def test_mutating_default(self
):
61 item
= self
.connection
.query(tables
.Item
).filter_by(
62 identifier
=u
"jade-orb").one()
64 assert item
.name
== "foo"
66 def test_string_mapping(self
):
67 item
= self
.connection
.query(tables
.Item
).filter_by(
68 identifier
=u
"jade-orb").one()
69 assert len(item
.names
) == len(item
.texts
)
70 for lang
in item
.texts
:
71 assert item
.names
[lang
] == item
.texts
[lang
].name
72 assert item
.names
[lang
] == item
.names
[lang
.identifier
]
73 assert lang
in item
.names
74 assert lang
.identifier
in item
.names
75 assert "language that doesn't exist" not in item
.names
76 assert tables
.Language() not in item
.names
78 def test_new_language(self
):
79 item
= self
.connection
.query(tables
.Item
).filter_by(
80 identifier
=u
"jade-orb").one()
81 language
= tables
.Language()
83 language
.identifier
= u
'test'
84 language
.iso639
= language
.iso3166
= u
'--'
85 language
.official
= False
86 self
.connection
.add(language
)
87 item
.names
[u
'test'] = u
"foo"
88 assert item
.names
[language
] == "foo"
89 assert item
.names
['test'] == "foo"
90 assert 'de' in item
.names
91 assert language
in item
.names
92 item
.names
[language
] = u
"xyzzy"
93 assert item
.names
[language
] == "xyzzy"
94 assert item
.names
['test'] == "xyzzy"
96 @raises(NotImplementedError)
97 def test_delstring(self
):
98 item
= self
.connection
.query(tables
.Item
).filter_by(
99 identifier
=u
"jade-orb").one()
102 def test_markdown(self
):
103 move
= self
.connection
.query(tables
.Move
).filter_by(
104 identifier
=u
"thunderbolt").one()
105 assert '10%' in move
.effect
.as_text
106 assert '10%' in move
.effects
['en'].as_text