2 # -*- coding: utf-8 -*-
4 from translate
.convert
import po2txt
5 from translate
.convert
import test_convert
6 from translate
.misc
import wStringIO
9 def po2txt(self
, posource
, txttemplate
=None):
10 """helper that converts po source to txt source without requiring files"""
11 inputfile
= wStringIO
.StringIO(posource
)
12 print inputfile
.getvalue()
13 outputfile
= wStringIO
.StringIO()
15 templatefile
= wStringIO
.StringIO(txttemplate
)
18 assert po2txt
.converttxt(inputfile
, outputfile
, templatefile
)
19 print outputfile
.getvalue()
20 return outputfile
.getvalue()
23 """test basic conversion"""
24 txttemplate
= "Heading\n\nBody text"
25 posource
= 'msgid "Heading"\nmsgstr "Opskrif"\n\nmsgid "Body text"\nmsgstr "Lyfteks"\n'
26 assert self
.po2txt(posource
, txttemplate
) == "Opskrif\n\nLyfteks"
28 def test_nonascii(self
):
29 """test conversion with non-ascii text"""
30 txttemplate
= "Heading\n\nFile content"
31 posource
= 'msgid "Heading"\nmsgstr "Opskrif"\n\nmsgid "File content"\nmsgstr "LĂȘerinhoud"\n'
32 assert self
.po2txt(posource
, txttemplate
) == "Opskrif\n\nLĂȘerinhoud"
34 def test_blank_handling(self
):
35 """check that we discard blank messages"""
36 txttemplate
= "Heading\n\nBody text"
37 posource
= 'msgid "Heading"\nmsgstr "Opskrif"\n\nmsgid "Body text"\nmsgstr ""\n'
38 assert self
.po2txt(posource
) == "Opskrif\n\nBody text"
39 assert self
.po2txt(posource
, txttemplate
) == "Opskrif\n\nBody text"
41 def test_fuzzy_handling(self
):
42 """check that we handle fuzzy message correctly"""
43 txttemplate
= "Heading\n\nBody text"
44 posource
= '#, fuzzy\nmsgid "Heading"\nmsgstr "Opskrif"\n\nmsgid "Body text"\nmsgstr "Lyfteks"\n'
45 assert self
.po2txt(posource
) == "Heading\n\nLyfteks"
46 assert self
.po2txt(posource
, txttemplate
) == "Heading\n\nLyfteks"
48 class TestPO2TxtCommand(test_convert
.TestConvertCommand
, TestPO2Txt
):
49 """Tests running actual po2txt commands on files"""
50 convertmodule
= po2txt
51 defaultoptions
= {"progress": "none"}
54 """tests getting help"""
55 options
= test_convert
.TestConvertCommand
.test_help(self
)
56 options
= self
.help_check(options
, "-t TEMPLATE, --template=TEMPLATE")
57 options
= self
.help_check(options
, "--fuzzy")
58 options
= self
.help_check(options
, "--nofuzzy")
59 options
= self
.help_check(options
, "--encoding")
60 options
= self
.help_check(options
, "-w WRAP, --wrap=WRAP", last
=True)