2 from nose
.tools
import *
4 from sqlalchemy
.orm
import class_mapper
6 from pokedex
.db
import tables
, markdown
8 def test_variable_names():
9 """We want pokedex.db.tables to export tables using the class name"""
10 for varname
in dir(tables
):
11 if not varname
[0].isupper():
13 table
= getattr(tables
, varname
)
15 if not issubclass(table
, tables
.TableBase
) or table
is tables
.TableBase
:
19 classname
= table
.__name__
20 if classname
and varname
[0].isupper():
21 assert varname
== classname
, '%s refers to %s' %
(varname
, classname
)
22 for table
in tables
.all_tables():
23 assert getattr(tables
, table
.__name__
) is table
26 """Check DB schema for integrity of text columns & translations.
28 Mostly protects against copy/paste oversights and rebase hiccups.
29 If there's a reason to relax the tests, do it
31 for table
in sorted(tables
.all_tables(), key
=lambda t
: t
.__name__
):
32 if issubclass(table
, tables
.LanguageSpecific
):
33 good_formats
= 'markdown plaintext gametext'.split()
34 assert_text
= '%s is language-specific'
36 good_formats
= 'identifier latex'.split()
37 assert_text
= '%s is not language-specific'
38 mapper
= class_mapper(table
)
39 for column
in sorted(mapper
.c
, key
=lambda c
: c
.name
):
40 format
= column
.info
.get('format', None)
41 if format
is not None:
42 if format
not in good_formats
:
43 raise AssertionError(assert_text % column
)
44 is_markdown
= isinstance(column
.type, markdown
.MarkdownColumn
)
45 if is_markdown
!= (format
== 'markdown'):
46 raise AssertionError('%s: markdown format/column type mismatch' % column
)
47 if (format
!= 'identifier') and (column
.name
== 'identifier'):
48 raise AssertionError('%s: identifier column name/type mismatch' % column
)
49 if column
.info
.get('official', None) and format
not in 'gametext plaintext':
50 raise AssertionError('%s: official text with bad format' % column
)
52 if isinstance(column
.type, (markdown
.MarkdownColumn
, tables
.Unicode
)):
53 raise AssertionError('%s: text column without format' % column
)
54 if column
.name
== 'name' and format
!= 'plaintext':
55 raise AssertionError('%s: non-plaintext name' % column
)
56 # No mention of English in the description
57 assert 'English' not in column
.info
['description'], column
59 def test_identifiers_with_names():
60 """Test that named tables have identifiers, and non-named tables don't
62 ...have either names or identifiers.
64 for table
in sorted(tables
.all_tables(), key
=lambda t
: t
.__name__
):
65 if issubclass(table
, tables
.Named
):
66 assert issubclass(table
, tables
.OfficiallyNamed
) or issubclass(table
, tables
.UnofficiallyNamed
), table
67 assert hasattr(table
, 'identifier'), table
69 assert not hasattr(table
, 'identifier'), table
70 if not issubclass(table
, tables
.LanguageSpecific
):
71 assert not hasattr(table
, 'name'), table