0955ded1ecaa5bc4979ff75ce19ecb67f0d8903d
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 language
= self
.connection
.query(tables
.Language
).filter_by(
40 identifier
=lang
).one()
41 assert pkmn
.name_map
[language
] == name
44 def test_bad_lang(self
):
45 q
= self
.connection
.query(tables
.Pokemon
).filter(
46 tables
.Pokemon
.name
== u
"Mightyena")
48 pkmn
.names
["identifier of a language that doesn't exist"]
50 def test_mutating(self
):
51 item
= self
.connection
.query(tables
.Item
).filter_by(
52 identifier
=u
"jade-orb").one()
53 language
= self
.connection
.query(tables
.Language
).filter_by(
54 identifier
=u
"de").one()
55 item
.name_map
[language
] = u
"foo"
56 assert item
.name_map
[language
] == "foo"
57 item
.name_map
[language
] = u
"xyzzy"
58 assert item
.name_map
[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
.name_map
) == len(item
.names
)
70 for lang
in item
.names
:
71 assert item
.name_map
[lang
] == item
.names
[lang
].name
72 assert lang
in item
.name_map
73 assert "language that doesn't exist" not in item
.name_map
74 assert tables
.Language() not in item
.name_map
76 def test_new_language(self
):
77 item
= self
.connection
.query(tables
.Item
).filter_by(
78 identifier
=u
"jade-orb").one()
79 language
= tables
.Language()
81 language
.identifier
= u
'test'
82 language
.iso639
= language
.iso3166
= u
'--'
83 language
.official
= False
84 self
.connection
.add(language
)
85 item
.name_map
[language
] = u
"foo"
86 assert item
.name_map
[language
] == "foo"
87 assert language
in item
.name_map
88 item
.name_map
[language
] = u
"xyzzy"
89 assert item
.name_map
[language
] == "xyzzy"
91 @raises(AssertionError)
92 def test_delstring(self
):
93 item
= self
.connection
.query(tables
.Item
).filter_by(
94 identifier
=u
"jade-orb").one()
95 language
= self
.connection
.query(tables
.Language
).filter_by(
96 identifier
=u
"en").one()
97 del item
.name_map
[language
]
98 self
.connection
.commit()
100 def test_markdown(self
):
101 move
= self
.connection
.query(tables
.Move
).filter_by(
102 identifier
=u
"thunderbolt").one()
103 language
= self
.connection
.query(tables
.Language
).filter_by(
104 identifier
=u
"en").one()
105 assert '10%' in move
.effect
.as_text
106 assert '10%' in move
.effect_map
[language
].as_text