1
2
3 from translate.storage import dtd
4 from translate.storage import test_monolingual
5 from translate.misc import wStringIO
6
8 specials = ['Fish & chips', 'five < six', 'six > five',
9 'Use ', 'Use &nbsp;'
10 'A "solution"', "skop 'n bal", '"""', "'''",
11 '\n', '\t', '\r',
12 'Escape at end \\',
13 '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\']
14 for special in specials:
15 quoted_special = dtd.quotefordtd(special)
16 unquoted_special = dtd.unquotefromdtd(quoted_special)
17 print "special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_special, unquoted_special)
18 assert special == unquoted_special
19
20 -class TestDTDUnit(test_monolingual.TestMonolingualUnit):
22
23
24 -class TestDTD(test_monolingual.TestMonolingualStore):
25 StoreClass = dtd.dtdfile
31
33 """helper that converts dtd source to dtdfile object and back"""
34 return str(self.dtdparse(dtdsource))
35
37 """checks that a simple dtd entity definition is parsed correctly"""
38 dtdsource = '<!ENTITY test.me "bananas for sale">\n'
39 dtdfile = self.dtdparse(dtdsource)
40 assert len(dtdfile.units) == 1
41 dtdunit = dtdfile.units[0]
42 assert dtdunit.entity == "test.me"
43 assert dtdunit.definition == '"bananas for sale"'
44
46 """checks that blank lines don't break the parsing or regeneration"""
47 dtdsource = '<!ENTITY test.me "bananas for sale">\n\n'
48 dtdregen = self.dtdregen(dtdsource)
49 assert dtdsource == dtdregen
50
52 """checks that a simple dtd entity definition can be regenerated as source"""
53 dtdsource = '<!ENTITY test.me "bananas for sale">\n'
54 dtdregen = self.dtdregen(dtdsource)
55 assert dtdsource == dtdregen
56
62
68
78
80 """tests that we can handle newlines in the entity itself"""
81 dtdsource = '''<!ENTITY fileNotFound.longDesc "
82 <ul>
83 <li>Check the file name for capitalisation or other typing errors.</li>
84 <li>Check to see if the file was moved, renamed or deleted.</li>
85 </ul>
86 ">
87 '''
88 dtdregen = self.dtdregen(dtdsource)
89 print dtdregen
90 print dtdsource
91 assert dtdsource == dtdregen
92
100
102 """test to ensure that we retain the localisation note correctly"""
103 dtdsource = '''<!--LOCALIZATION NOTE (publishFtp.label): Edit box appears beside this label -->
104 <!ENTITY publishFtp.label "If publishing to a FTP site, enter the HTTP address to browse to:">
105 '''
106 dtdregen = self.dtdregen(dtdsource)
107 assert dtdsource == dtdregen
108
110 """checks that an &entity; in the source is retained"""
111 dtdsource = '<!ENTITY % realBrandDTD SYSTEM "chrome://branding/locale/brand.dtd">\n%realBrandDTD;\n'
112 dtdregen = self.dtdregen(dtdsource)
113 print dtdsource
114 print dtdregen
115 assert dtdsource == dtdregen
116
122
128
130 """checks that invalid quoting doesn't work - quotes can't be reopened"""
131
132 dtdsource = '<!ENTITY test.me "bananas for sale""room">\n'
133 assert dtd.unquotefromdtd(dtdsource[dtdsource.find('"'):]) == 'bananas for sale'
134 dtdfile = self.dtdparse(dtdsource)
135 assert len(dtdfile.units) == 1
136 dtdunit = dtdfile.units[0]
137 assert dtdunit.definition == '"bananas for sale"'
138 assert str(dtdfile) == '<!ENTITY test.me "bananas for sale">\n'
139
141 """test that we fail graacefully when a message without quotes is found (bug #161)"""
142 dtdsource = '<!ENTITY bad no quotes">\n<!ENTITY good "correct quotes">\n'
143 dtdfile = self.dtdparse(dtdsource)
144
145 assert len(dtdfile.units) == 1
146