Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(89)

Delta Between Two Patch Sets: translate/convert/test_pot2po.py

Issue 81: Fix CPO memory leak SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
Left Patch Set: Added some tests workarounds Created 1 year, 4 months ago
Right Patch Set: Added tests Created 1 year, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: View regular side by side diff
Right: View regular side by side diff
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from translate.convert import pot2po 3 from translate.convert import pot2po
4 from translate.convert import test_convert 4 from translate.convert import test_convert
5 from translate.misc import wStringIO 5 from translate.misc import wStringIO
6 from translate.storage import po 6 from translate.storage import po
7 import warnings 7 import warnings
8 8
9 class TestPOT2PO: 9 class TestPOT2PO:
10 def setup_method(self, method): 10 def setup_method(self, method):
11 warnings.resetwarnings() 11 warnings.resetwarnings()
12 12
13 def teardown_method(self, method): 13 def teardown_method(self, method):
14 warnings.resetwarnings() 14 warnings.resetwarnings()
15 15
16 def convertpot(self, potsource, posource=None): 16 def convertpot(self, potsource, posource=None):
17 """helper that converts pot source to po source without requiring files" "" 17 """helper that converts pot source to po source without requiring files" ""
18 potfile = wStringIO.StringIO(potsource) 18 potfile = wStringIO.StringIO(potsource)
19 if posource: 19 if posource:
20 pofile = wStringIO.StringIO(posource) 20 pofile = wStringIO.StringIO(posource)
21 else: 21 else:
22 pofile = None 22 pofile = None
23 pooutfile = wStringIO.StringIO() 23 pooutfile = wStringIO.StringIO()
24 pot2po.convertpot(potfile, pooutfile, pofile) 24 pot2po.convertpot(potfile, pooutfile, pofile)
25 pooutfile.seek(0) 25 pooutfile.seek(0)
26 return po.pofile(pooutfile.read()) 26 return po.pofile(pooutfile.read())
27 27
28 def singleunit(self, pofile): 28 def singleunit(self, pofile):
29 """checks that the pofile contains a single non-header unit, and returns it""" 29 """checks that the pofile contains a single non-header unit, and returns it"""
30 assert len(pofile.units) == 2 30 assert len(pofile.units) == 2
31 assert pofile.units[0].isheader() 31 assert pofile.units[0].isheader()
32 print pofile.units[1] 32 print pofile.units[1]
33 return pofile.units[1] 33 return pofile.units[1]
34 34
35 def test_convertpot_blank(self): 35 def test_convertpot_blank(self):
36 """checks that the convertpot function is working for a simple file init ialisation""" 36 """checks that the convertpot function is working for a simple file init ialisation"""
37 potsource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard cod ed newline.\\n"\nmsgstr ""\n''' % po.lsep 37 potsource = '''#: simple.label:1%ssimple.accesskey:1\nmsgid "A &hard cod ed newline.\\n"\nmsgstr ""\n''' % po.lsep
38 newpo = self.convertpot(potsource) 38 newpo = self.convertpot(potsource)
39 assert str(self.singleunit(newpo)) == potsource 39 assert str(self.singleunit(newpo)) == potsource
40 40
41 def test_convertpot_blank_plurals(self): 41 def test_convertpot_blank_plurals(self):
42 """checks that the convertpot function is working for initialising plura ls correctly""" 42 """checks that the convertpot function is working for initialising plura ls correctly"""
43 potsource = r'''msgid "" 43 potsource = r'''msgid ""
44 msgstr"" 44 msgstr""
45 45
46 msgid "%d manual" 46 msgid "%d manual"
47 msgid_plural "%d manuals" 47 msgid_plural "%d manuals"
48 msgstr[0] "" 48 msgstr[0] ""
49 msgstr[1] "" 49 msgstr[1] ""
50 ''' 50 '''
(...skipping 325 matching lines...) Show 10 above Show 10 below
376 "Content-Transfer-Encoding: 8bit\n" 376 "Content-Transfer-Encoding: 8bit\n"
377 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 377 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
378 "X-Generator: Translate Toolkit 0.10rc2\n" 378 "X-Generator: Translate Toolkit 0.10rc2\n"
379 ''' 379 '''
380 newpo = self.convertpot(potsource, posource) 380 newpo = self.convertpot(potsource, posource)
381 print 'Output Header:\n%s' % newpo 381 print 'Output Header:\n%s' % newpo
382 print 'Expected Header:\n%s' % expected 382 print 'Expected Header:\n%s' % expected
383 assert str(newpo) == expected 383 assert str(newpo) == expected
384 384
385 def test_merging_comments(self): 385 def test_merging_comments(self):
386 """Test that we can merge comments correctly""" 386 """Test that we can merge comments correctly"""
387 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n'' ' 387 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n'' '
388 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n ''' 388 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n '''
389 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een" \n''' 389 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een" \n'''
390 newpo = self.convertpot(potsource, posource) 390 newpo = self.convertpot(potsource, posource)
391 print newpo 391 print newpo
392 newpounit = self.singleunit(newpo) 392 newpounit = self.singleunit(newpo)
393 assert str(newpounit) == poexpected 393 assert str(newpounit) == poexpected
394 394
395 def test_merging_typecomments(self): 395 def test_merging_typecomments(self):
396 """Test that we can merge with typecomments""" 396 """Test that we can merge with typecomments"""
397 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n'' ' 397 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n'' '
398 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n''' 398 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n'''
399 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p ype"\n''' 399 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p ype"\n'''
400 newpo = self.convertpot(potsource, posource) 400 newpo = self.convertpot(potsource, posource)
401 newpounit = self.singleunit(newpo) 401 newpounit = self.singleunit(newpo)
402 print newpounit 402 print newpounit
403 assert str(newpounit) == poexpected 403 assert str(newpounit) == poexpected
404 404
405 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr "" \n''' 405 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr "" \n'''
406 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "% s-rekenaars"\n''' 406 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "% s-rekenaars"\n'''
407 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm sgstr "%s-rekenaars"\n''' 407 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm sgstr "%s-rekenaars"\n'''
408 newpo = self.convertpot(potsource, posource) 408 newpo = self.convertpot(potsource, posource)
409 newpounit = self.singleunit(newpo) 409 newpounit = self.singleunit(newpo)
410 assert newpounit.isfuzzy() 410 assert newpounit.isfuzzy()
411 assert newpounit.hastypecomment("c-format") 411 assert newpounit.hastypecomment("c-format")
412 412
413 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO): 413 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO):
414 """Tests running actual pot2po commands on files""" 414 """Tests running actual pot2po commands on files"""
415 convertmodule = pot2po 415 convertmodule = pot2po
416 416
417 def test_help(self): 417 def test_help(self):
418 """tests getting help""" 418 """tests getting help"""
419 options = test_convert.TestConvertCommand.test_help(self) 419 options = test_convert.TestConvertCommand.test_help(self)
420 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") 420 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE")
421 options = self.help_check(options, "-P, --pot") 421 options = self.help_check(options, "-P, --pot")
422 options = self.help_check(options, "--tm") 422 options = self.help_check(options, "--tm")
423 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_ SIMILARITY") 423 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_ SIMILARITY")
424 options = self.help_check(options, "--nofuzzymatching", last=True) 424 options = self.help_check(options, "--nofuzzymatching", last=True)
425 425
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r159