Mercurial > babel > old > mirror
comparison 0.8.x/babel/messages/tests/extract.py @ 142:4a7af44e6695 stable
Create branch for 0.8.x releases.
author | cmlenz |
---|---|
date | Wed, 20 Jun 2007 10:09:07 +0000 |
parents | |
children | bdf9b34ed1e4 |
comparison
equal
deleted
inserted
replaced
1:bf36ec5f5e50 | 142:4a7af44e6695 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 # | |
3 # Copyright (C) 2007 Edgewall Software | |
4 # All rights reserved. | |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://babel.edgewall.org/wiki/License. | |
9 # | |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
12 # history and logs, available at http://babel.edgewall.org/log/. | |
13 | |
14 import doctest | |
15 from StringIO import StringIO | |
16 import unittest | |
17 | |
18 from babel.messages import extract | |
19 | |
20 | |
21 class ExtractPythonTestCase(unittest.TestCase): | |
22 | |
23 def test_unicode_string_arg(self): | |
24 buf = StringIO("msg = _(u'Foo Bar')") | |
25 messages = list(extract.extract_python(buf, ('_',), [], {})) | |
26 self.assertEqual('Foo Bar', messages[0][2]) | |
27 | |
28 def test_comment_tag(self): | |
29 buf = StringIO(""" | |
30 # NOTE: A translation comment | |
31 msg = _(u'Foo Bar') | |
32 """) | |
33 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
34 self.assertEqual('Foo Bar', messages[0][2]) | |
35 self.assertEqual(['A translation comment'], messages[0][3]) | |
36 | |
37 def test_comment_tag_multiline(self): | |
38 buf = StringIO(""" | |
39 # NOTE: A translation comment | |
40 # with a second line | |
41 msg = _(u'Foo Bar') | |
42 """) | |
43 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
44 self.assertEqual('Foo Bar', messages[0][2]) | |
45 self.assertEqual(['A translation comment', 'with a second line'], | |
46 messages[0][3]) | |
47 | |
48 def test_translator_comments_with_previous_non_translator_comments(self): | |
49 buf = StringIO(""" | |
50 # This shouldn't be in the output | |
51 # because it didn't start with a comment tag | |
52 # NOTE: A translation comment | |
53 # with a second line | |
54 msg = _(u'Foo Bar') | |
55 """) | |
56 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
57 self.assertEqual('Foo Bar', messages[0][2]) | |
58 self.assertEqual(['A translation comment', 'with a second line'], | |
59 messages[0][3]) | |
60 | |
61 def test_comment_tags_not_on_start_of_comment(self): | |
62 buf = StringIO(""" | |
63 # This shouldn't be in the output | |
64 # because it didn't start with a comment tag | |
65 # do NOTE: this will no be a translation comment | |
66 # NOTE: This one will be | |
67 msg = _(u'Foo Bar') | |
68 """) | |
69 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
70 self.assertEqual('Foo Bar', messages[0][2]) | |
71 self.assertEqual(['This one will be'], messages[0][3]) | |
72 | |
73 def test_multiple_comment_tags(self): | |
74 buf = StringIO(""" | |
75 # NOTE1: A translation comment for tag1 | |
76 # with a second line | |
77 msg = _(u'Foo Bar1') | |
78 | |
79 # NOTE2: A translation comment for tag2 | |
80 msg = _(u'Foo Bar2') | |
81 """) | |
82 messages = list(extract.extract_python(buf, ('_',), | |
83 ['NOTE1:', 'NOTE2:'], {})) | |
84 self.assertEqual('Foo Bar1', messages[0][2]) | |
85 self.assertEqual(['A translation comment for tag1', | |
86 'with a second line'], messages[0][3]) | |
87 self.assertEqual('Foo Bar2', messages[1][2]) | |
88 self.assertEqual(['A translation comment for tag2'], messages[1][3]) | |
89 | |
90 def test_two_succeeding_comments(self): | |
91 buf = StringIO(""" | |
92 # NOTE: one | |
93 # NOTE: two | |
94 msg = _(u'Foo Bar') | |
95 """) | |
96 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
97 self.assertEqual('Foo Bar', messages[0][2]) | |
98 self.assertEqual(['one', 'NOTE: two'], messages[0][3]) | |
99 | |
100 def test_invalid_translator_comments(self): | |
101 buf = StringIO(""" | |
102 # NOTE: this shouldn't apply to any messages | |
103 hello = 'there' | |
104 | |
105 msg = _(u'Foo Bar') | |
106 """) | |
107 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
108 self.assertEqual('Foo Bar', messages[0][2]) | |
109 self.assertEqual([], messages[0][3]) | |
110 | |
111 def test_invalid_translator_comments2(self): | |
112 buf = StringIO(""" | |
113 # NOTE: Hi! | |
114 hithere = _('Hi there!') | |
115 | |
116 # NOTE: you should not be seeing this in the .po | |
117 rows = [[v for v in range(0,10)] for row in range(0,10)] | |
118 | |
119 # this (NOTE:) should not show up either | |
120 hello = _('Hello') | |
121 """) | |
122 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
123 self.assertEqual('Hi there!', messages[0][2]) | |
124 self.assertEqual(['Hi!'], messages[0][3]) | |
125 self.assertEqual('Hello', messages[1][2]) | |
126 self.assertEqual([], messages[1][3]) | |
127 | |
128 def test_invalid_translator_comments3(self): | |
129 buf = StringIO(""" | |
130 # NOTE: Hi, | |
131 | |
132 # there! | |
133 hithere = _('Hi there!') | |
134 """) | |
135 messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {})) | |
136 self.assertEqual('Hi there!', messages[0][2]) | |
137 self.assertEqual([], messages[0][3]) | |
138 | |
139 def suite(): | |
140 suite = unittest.TestSuite() | |
141 suite.addTest(doctest.DocTestSuite(extract)) | |
142 suite.addTest(unittest.makeSuite(ExtractPythonTestCase)) | |
143 return suite | |
144 | |
145 if __name__ == '__main__': | |
146 unittest.main(defaultTest='suite') |