hurp durp default language
[zzz-pokedex.git] / pokedex / tests / test_strings.py
1 # Encoding: UTF-8
2
3 from nose.tools import *
4
5 from pokedex.db import tables, connect
6
7 class TestStrings(object):
8 def setup(self):
9 self.connection = connect()
10
11 def teardown(self):
12 self.connection.rollback()
13
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'
18
19 def test_languages(self):
20 q = self.connection.query(tables.Pokemon).filter(
21 tables.Pokemon.name == u"Mightyena")
22 pkmn = q.one()
23 for lang, name in (
24 ('en', u'Mightyena'),
25 ('ja', u'グラエナ'),
26 ('roomaji', u'Guraena'),
27 ('fr', u'Grahyèna'),
28 ):
29 language = self.connection.query(tables.Language).filter_by(
30 identifier=lang).one()
31 assert pkmn.name_map[language] == name
32
33 @raises(KeyError)
34 def test_bad_lang(self):
35 q = self.connection.query(tables.Pokemon).filter(
36 tables.Pokemon.name == u"Mightyena")
37 pkmn = q.one()
38 pkmn.names["identifier of a language that doesn't exist"]
39
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"
49
50 def test_mutating_default(self):
51 item = self.connection.query(tables.Item).filter_by(
52 identifier=u"jade-orb").one()
53 item.name = u"foo"
54 assert item.name == "foo"
55
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
65
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()
70 language.id = -1
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"
80
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