fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / convert / test_po2txt.py
blob20e8451bff42b836dd9215f78b4ad64952e9d70d
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 from translate.convert import po2txt
5 from translate.convert import test_convert
6 from translate.misc import wStringIO
8 class TestPO2Txt:
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()
14 if txttemplate:
15 templatefile = wStringIO.StringIO(txttemplate)
16 else:
17 templatefile = None
18 assert po2txt.converttxt(inputfile, outputfile, templatefile)
19 print outputfile.getvalue()
20 return outputfile.getvalue()
22 def test_basic(self):
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"}
53 def test_help(self):
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)