2 # -*- coding: utf-8 -*-
4 from translate
.convert
import mozfunny2prop
5 from translate
.misc
import wStringIO
6 from translate
.storage
import po
9 def inc2po(self
, incsource
, inctemplate
=None):
10 """helper that converts .inc source to po source without requiring files"""
11 inputfile
= wStringIO
.StringIO(incsource
)
13 templatefile
= wStringIO
.StringIO(inctemplate
)
16 outputfile
= wStringIO
.StringIO()
17 result
= mozfunny2prop
.inc2po(inputfile
, outputfile
, templatefile
)
18 outputpo
= outputfile
.getvalue()
19 outputpofile
= po
.pofile(wStringIO
.StringIO(outputpo
))
22 def singleelement(self
, pofile
):
23 """checks that the pofile contains a single non-header element, and returns it"""
24 assert len(pofile
.units
) == 2
25 assert pofile
.units
[0].isheader()
27 return pofile
.units
[1]
29 def countelements(self
, pofile
):
30 """counts the number of non-header entries"""
31 assert pofile
.units
[0].isheader()
33 return len(pofile
.units
) - 1
35 def test_simpleentry(self
):
36 """checks that a simple inc entry converts properly to a po entry"""
37 incsource
= '#define MOZ_LANGPACK_CREATOR mozilla.org\n'
38 pofile
= self
.inc2po(incsource
)
39 pounit
= self
.singleelement(pofile
)
40 assert pounit
.getlocations() == ["MOZ_LANGPACK_CREATOR"]
41 assert pounit
.source
== "mozilla.org"
42 assert pounit
.target
== ""
44 def test_uncomment_contributors(self
):
45 """checks that the contributors entry is automatically uncommented"""
46 incsource
= '''# If non-English locales wish to credit multiple contributors, uncomment this
47 # variable definition and use the format specified.
48 # #define MOZ_LANGPACK_CONTRIBUTORS <em:contributor>Joe Solon</em:contributor> <em:contributor>Suzy Solon</em:contributor>'''
49 pofile
= self
.inc2po(incsource
)
50 pounit
= self
.singleelement(pofile
)
51 assert pounit
.getlocations() == ["MOZ_LANGPACK_CONTRIBUTORS"]
52 assert "Joe Solon" in pounit
.source