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'
19 def test_languages(self
):
20 q
= self
.connection
.query(tables
.Pokemon
).filter(
21 tables
.Pokemon
.name
== u
"Mightyena")
26 ('roomaji', u
'Guraena'),
29 language
= self
.connection
.query(tables
.Language
).filter_by(
30 identifier
=lang
).one()
31 assert pkmn
.name_map
[language
] == name
34 def test_bad_lang(self
):
35 q
= self
.connection
.query(tables
.Pokemon
).filter(
36 tables
.Pokemon
.name
== u
"Mightyena")
38 pkmn
.names
["identifier of a language that doesn't exist"]
40 def test_mutating(self
):
41 item
= self
.connection
.query(tables
.Item
).filter_by(
42 identifier
=u
"jade-orb").one()
43 language
= self
.connection
.query(tables
.Language
).filter_by(
44 identifier
=u
"de").one()
45 item
.name_map
[language
] = u
"foo"
46 assert item
.name_map
[language
] == "foo"
47 item
.name_map
[language
] = u
"xyzzy"
48 assert item
.name_map
[language
] == "xyzzy"
50 def test_mutating_default(self
):
51 item
= self
.connection
.query(tables
.Item
).filter_by(
52 identifier
=u
"jade-orb").one()
54 assert item
.name
== "foo"
56 def test_string_mapping(self
):
57 item
= self
.connection
.query(tables
.Item
).filter_by(
58 identifier
=u
"jade-orb").one()
59 assert len(item
.name_map
) == len(item
.names
)
60 for lang
in item
.names
:
61 assert item
.name_map
[lang
] == item
.names
[lang
].name
62 assert lang
in item
.name_map
63 assert "language that doesn't exist" not in item
.name_map
64 assert tables
.Language() not in item
.name_map
66 def test_new_language(self
):
67 item
= self
.connection
.query(tables
.Item
).filter_by(
68 identifier
=u
"jade-orb").one()
69 language
= tables
.Language()
71 language
.identifier
= u
'test'
72 language
.iso639
= language
.iso3166
= u
'--'
73 language
.official
= False
74 self
.connection
.add(language
)
75 item
.name_map
[language
] = u
"foo"
76 assert item
.name_map
[language
] == "foo"
77 assert language
in item
.name_map
78 item
.name_map
[language
] = u
"xyzzy"
79 assert item
.name_map
[language
] == "xyzzy"
81 def test_markdown(self
):
82 move
= self
.connection
.query(tables
.Move
).filter_by(
83 identifier
=u
"thunderbolt").one()
84 language
= self
.connection
.query(tables
.Language
).filter_by(
85 identifier
=u
"en").one()
86 assert '10%' in move
.effect
.as_text
87 assert '10%' in move
.effect_map
[language
].as_text