| OLD | NEW |
| 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, *args, **kwargs): |
| 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 if 'ignore_previous' not in kwargs.keys(): |
| 25 kwargs['ignore_previous'] = True |
| 26 pot2po.convertpot(potfile, pooutfile, pofile, *args, **kwargs) |
| 25 pooutfile.seek(0) | 27 pooutfile.seek(0) |
| 26 return po.pofile(pooutfile.read()) | 28 return po.pofile(pooutfile.read()) |
| 27 | 29 |
| 28 def singleunit(self, pofile): | 30 def singleunit(self, pofile): |
| 29 """checks that the pofile contains a single non-header unit, and returns
it""" | 31 """checks that the pofile contains a single non-header unit, and returns
it""" |
| 30 assert len(pofile.units) == 2 | 32 assert len(pofile.units) == 2 |
| 31 assert pofile.units[0].isheader() | 33 assert pofile.units[0].isheader() |
| 32 print pofile.units[1] | 34 print pofile.units[1] |
| 33 return pofile.units[1] | 35 return pofile.units[1] |
| 34 | 36 |
| 35 def test_convertpot_blank(self): | 37 def test_convertpot_blank(self): |
| 36 """checks that the convertpot function is working for a simple file init
ialisation""" | 38 """checks that the convertpot function is working for a simple file init
ialisation""" |
| 37 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 39 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep |
| 38 newpo = self.convertpot(potsource) | 40 newpo = self.convertpot(potsource) |
| 39 assert str(self.singleunit(newpo)) == potsource | 41 assert str(self.singleunit(newpo)) == potsource |
| 40 | 42 |
| 41 def test_convertpot_blank_plurals(self): | 43 def test_convertpot_blank_plurals(self): |
| 42 """checks that the convertpot function is working for initialising plura
ls correctly""" | 44 """checks that the convertpot function is working for initialising plura
ls correctly""" |
| 43 potsource = r'''msgid "" | 45 potsource = r'''msgid "" |
| 44 msgstr"" | 46 msgstr"" |
| 45 | 47 |
| 46 msgid "%d manual" | 48 msgid "%d manual" |
| 47 msgid_plural "%d manuals" | 49 msgid_plural "%d manuals" |
| 48 msgstr[0] "" | 50 msgstr[0] "" |
| 49 msgstr[1] "" | 51 msgstr[1] "" |
| 50 ''' | 52 ''' |
| 51 posource = r'''msgid "" | 53 posource = r'''msgid "" |
| 52 msgstr"" | 54 msgstr"" |
| 53 "Plural-Forms: nplurals=1; plural=0;\n" | 55 "Plural-Forms: nplurals=1; plural=0;\n" |
| 54 ''' | 56 ''' |
| 55 | 57 |
| 56 poexpected = r'''msgid "%d manual" | 58 poexpected = r'''msgid "%d manual" |
| 57 msgid_plural "%d manuals" | 59 msgid_plural "%d manuals" |
| 58 msgstr[0] "" | 60 msgstr[0] "" |
| 59 ''' | 61 ''' |
| 60 newpo = self.convertpot(potsource, posource) | 62 newpo = self.convertpot(potsource, posource) |
| 61 assert str(self.singleunit(newpo)) == poexpected | 63 assert str(self.singleunit(newpo)) == poexpected |
| 62 | 64 |
| 63 def test_merging_simple(self): | 65 def test_merging_simple(self): |
| 64 """checks that the convertpot function is working for a simple merge""" | 66 """checks that the convertpot function is working for a simple merge""" |
| 65 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 67 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep |
| 66 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded ne
wline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 68 posource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded ne
wline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 67 newpo = self.convertpot(potsource, posource) | 69 newpo = self.convertpot(potsource, posource) |
| 68 assert str(self.singleunit(newpo)) == posource | 70 assert str(self.singleunit(newpo)) == posource |
| 69 | 71 |
| 70 def test_merging_messages_marked_fuzzy(self): | 72 def test_merging_messages_marked_fuzzy(self): |
| 71 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" | 73 """test that when we merge PO files with a fuzzy message that it remains
fuzzy""" |
| 72 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep | 74 potsource = '''#: simple.label%ssimple.accesskey\nmsgid "A &hard coded n
ewline.\\n"\nmsgstr ""\n''' % po.lsep |
| 73 posource = '''#: simple.label%ssimple.accesskey\n#, fuzzy\nmsgid "A &har
d coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep | 75 posource = '''#: simple.label%ssimple.accesskey\n#, fuzzy\nmsgid "A &har
d coded newline.\\n"\nmsgstr "&Hart gekoeerde nuwe lyne\\n"\n''' % po.lsep |
| 74 newpo = self.convertpot(potsource, posource) | 76 newpo = self.convertpot(potsource, posource) |
| (...skipping 288 matching lines...) Show 10 above Show 10 below |
| 363 "Content-Transfer-Encoding: 8bit\n" | 365 "Content-Transfer-Encoding: 8bit\n" |
| 364 "Plural-Forms: nplurals=2; plural=(n != 1);\n" | 366 "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
| 365 "X-Generator: Translate Toolkit 0.9\n" | 367 "X-Generator: Translate Toolkit 0.9\n" |
| 366 ''' | 368 ''' |
| 367 expected = r'''msgid "" | 369 expected = r'''msgid "" |
| 368 msgstr "" | 370 msgstr "" |
| 369 "Project-Id-Version: Pootle 0.10\n" | 371 "Project-Id-Version: Pootle 0.10\n" |
| 370 "Report-Msgid-Bugs-To: new@example.com\n" | 372 "Report-Msgid-Bugs-To: new@example.com\n" |
| 371 "POT-Creation-Date: 2006-11-11 11:11+0000\n" | 373 "POT-Creation-Date: 2006-11-11 11:11+0000\n" |
| 372 "PO-Revision-Date: 2006-09-09 09:09+0900\n" | 374 "PO-Revision-Date: 2006-09-09 09:09+0900\n" |
| 373 "Last-Translator: Joe Translate <joe@example.com>\n" | 375 "Last-Translator: Joe Translate <joe@example.com>\n" |
| 374 "Language-Team: Pig Latin <piglatin@example.com>\n" | 376 "Language-Team: Pig Latin <piglatin@example.com>\n" |
| 375 "MIME-Version: 1.0\n" | 377 "MIME-Version: 1.0\n" |
| 376 "Content-Type: text/plain; charset=UTF-8\n" | 378 "Content-Type: text/plain; charset=UTF-8\n" |
| 377 "Content-Transfer-Encoding: 8bit\n" | 379 "Content-Transfer-Encoding: 8bit\n" |
| 378 "Plural-Forms: nplurals=2; plural=(n != 1);\n" | 380 "Plural-Forms: nplurals=2; plural=(n != 1);\n" |
| 379 "X-Generator: Translate Toolkit 0.10rc2\n" | 381 "X-Generator: Translate Toolkit 0.10rc2\n" |
| 380 ''' | 382 ''' |
| 381 newpo = self.convertpot(potsource, posource) | 383 newpo = self.convertpot(potsource, posource) |
| 382 print 'Output Header:\n%s' % newpo | 384 print 'Output Header:\n%s' % newpo |
| 383 print 'Expected Header:\n%s' % expected | 385 print 'Expected Header:\n%s' % expected |
| 384 assert str(newpo) == expected | 386 assert str(newpo) == expected |
| 385 | 387 |
| 386 def test_merging_comments(self): | 388 def test_merging_comments(self): |
| 387 """Test that we can merge comments correctly""" | 389 """Test that we can merge comments correctly""" |
| 388 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n''
' | 390 potsource = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr ""\n''
' |
| 389 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n
''' | 391 posource = '''#. Don't do it!\n#: file.py:2\nmsgid "One"\nmsgstr "Een"\n
''' |
| 390 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een"
\n''' | 392 poexpected = '''#. Don't do it!\n#: file.py:1\nmsgid "One"\nmsgstr "Een"
\n''' |
| 391 newpo = self.convertpot(potsource, posource) | 393 newpo = self.convertpot(potsource, posource) |
| 392 print newpo | 394 print newpo |
| 393 newpounit = self.singleunit(newpo) | 395 newpounit = self.singleunit(newpo) |
| 394 assert str(newpounit) == poexpected | 396 assert str(newpounit) == poexpected |
| 395 | 397 |
| 396 def test_merging_typecomments(self): | 398 def test_merging_typecomments(self): |
| 397 """Test that we can merge with typecomments""" | 399 """Test that we can merge with typecomments""" |
| 398 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n''
' | 400 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr ""\n''
' |
| 399 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n''' | 401 posource = '''#: file.c:2\nmsgid "%d pipes"\nmsgstr "%d pype"\n''' |
| 400 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p
ype"\n''' | 402 poexpected = '''#: file.c:1\n#, c-format\nmsgid "%d pipes"\nmsgstr "%d p
ype"\n''' |
| 401 newpo = self.convertpot(potsource, posource) | 403 newpo = self.convertpot(potsource, posource) |
| 402 newpounit = self.singleunit(newpo) | 404 newpounit = self.singleunit(newpo) |
| 403 print newpounit | 405 print newpounit |
| 404 assert str(newpounit) == poexpected | 406 assert str(newpounit) == poexpected |
| 405 | 407 |
| 406 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr ""
\n''' | 408 potsource = '''#: file.c:1\n#, c-format\nmsgid "%d computers"\nmsgstr ""
\n''' |
| 407 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "%
s-rekenaars"\n''' | 409 posource = '''#: file.c:2\n#, c-format\nmsgid "%s computers "\nmsgstr "%
s-rekenaars"\n''' |
| 408 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm
sgstr "%s-rekenaars"\n''' | 410 poexpected = '''#: file.c:1\n#, fuzzy, c-format\nmsgid "%d computers"\nm
sgstr "%s-rekenaars"\n''' |
| 409 newpo = self.convertpot(potsource, posource) | 411 newpo = self.convertpot(potsource, posource) |
| 410 newpounit = self.singleunit(newpo) | 412 newpounit = self.singleunit(newpo) |
| 411 assert newpounit.isfuzzy() | 413 assert newpounit.isfuzzy() |
| 412 assert newpounit.hastypecomment("c-format") | 414 assert newpounit.hastypecomment("c-format") |
| 415 |
| 416 def test_previous_message_without_msgstr(self): |
| 417 potsource = '#: a.c:1\nmsgid "%d units"\nmsgstr ""\n' |
| 418 posource = '#: a.c:1\nmsgid "%s units"\nmsgstr ""\n' |
| 419 poexpected = potsource |
| 420 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 421 newpounit = self.singleunit(newpo) |
| 422 assert str(newpounit) == poexpected |
| 423 assert not newpounit.isfuzzy() |
| 424 |
| 425 def test_previous_message_singular(self): |
| 426 potsource = '#: a.c:1\nmsgid "%d unit"\nmsgstr "%d unidade"\n' |
| 427 posource = '#: a.c:1\nmsgid "%s unit"\nmsgstr "%s unidade"\n' |
| 428 poexpected = '''#: a.c:1\n#, fuzzy\n#| msgid "%d unit"\nmsgid "%s unit" |
| 429 msgstr "%d unidade"\n''' |
| 430 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 431 newpounit = self.singleunit(newpo) |
| 432 assert str(newpounit) == poexpected |
| 433 assert newpounit.isfuzzy() |
| 434 |
| 435 def test_previous_message_with_plural(self): |
| 436 potsource = '''#: a.c:1\nmsgid "%d unit"\nmsgid_plural "%d units" |
| 437 msgstr[0] "%d unidade"\nmsgstr[1] "%d unidades"''' |
| 438 posource = '''#: a.c:1\nmsgid "%s unit"\nmsgid_plural "%s units" |
| 439 msgstr[0] "%s unidade"\nmsgstr[1] "%s unidades"''' |
| 440 poexpected = '''#: a.c:1 |
| 441 #, fuzzy |
| 442 #| msgid "%d unit" |
| 443 #| msgid_plural "%d units" |
| 444 msgid "%s unit" |
| 445 msgid_plural "%s units" |
| 446 msgstr[0] "%d unidade" |
| 447 msgstr[1] "%d unidades"\n''' |
| 448 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 449 newpounit = self.singleunit(newpo) |
| 450 assert str(newpounit) == poexpected |
| 451 assert newpounit.isfuzzy() |
| 452 |
| 453 def test_previous_message_with_only_pot_plural(self): |
| 454 potsource = '''#: a.c:1\nmsgid "plural"\nmsgid_plural "plurals" |
| 455 msgstr[0] "plural"\nmsgstr[1] "plurais"''' |
| 456 posource = '#: a.c:1\nmsgid "plural"\nmsgstr "plural"\n' |
| 457 poexpected = '''#: a.c:1 |
| 458 #, fuzzy |
| 459 #| msgid "plural" |
| 460 #| msgid_plural "plurals" |
| 461 msgid "plural" |
| 462 msgstr "plural"\n''' |
| 463 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 464 newpounit = self.singleunit(newpo) |
| 465 print str(newpounit) |
| 466 print 'Expected' |
| 467 print poexpected |
| 468 assert str(newpounit) == poexpected |
| 469 assert newpounit.isfuzzy() |
| 470 |
| 471 def test_previous_message_with_only_po_plural(self): |
| 472 #XXX: broken test - missing msgstr[1] |
| 473 # in msgmerge it just copy the msgstr[0] to msgstr[1] (?) |
| 474 potsource = '#: a.c:1\nmsgid "unit"\n msgstr "unidade"\n' |
| 475 posource = '''#: a.c:1\nmsgid "unit"\nmsgid_plural "units" |
| 476 msgstr[0] "unidade"\nmsgstr[1] "unidades"''' |
| 477 poexpected = '''#: a.c:1 |
| 478 #, fuzzy |
| 479 #| msgid "unit" |
| 480 msgid "unit" |
| 481 msgid_plural "units" |
| 482 msgstr[0] "unidade" |
| 483 msgstr[1] "unidades"\n''' |
| 484 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 485 newpounit = self.singleunit(newpo) |
| 486 #XXX: remove this later |
| 487 print str(newpounit) |
| 488 print 'Expected' |
| 489 print poexpected |
| 490 assert str(newpounit) == poexpected |
| 491 assert newpounit.isfuzzy() |
| 492 |
| 493 def test_previous_message_with_fuzzy_state_set(self): |
| 494 potsource = '#: a.c:1\n#, fuzzy\nmsgid "%d units"\nmsgstr "%d unidades"\
n' |
| 495 posource = '#: a.c:1\nmsgid "%s units"\nmsgstr "%s unidades"\n' |
| 496 poexpected = '#: a.c:1\n#, fuzzy\nmsgid "%s units"\nmsgstr "%d unidades"
\n' |
| 497 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 498 newpounit = self.singleunit(newpo) |
| 499 assert str(newpounit) == poexpected |
| 500 assert newpounit.isfuzzy() |
| 501 |
| 502 def test_previous_message_with_context(self): |
| 503 potsource = '''#: a.c:1\nmsgctxt "Testing"\nmsgid "%d unit" |
| 504 msgstr "%d unidade"''' |
| 505 posource = '''#: a.c:1\nmsgctxt "Testing"\nmsgid "%s unit" |
| 506 msgstr "%s unidade"''' |
| 507 poexpected = '''#: a.c:1 |
| 508 #, fuzzy |
| 509 #| msgctxt "Testing" |
| 510 #| msgid "%d unit" |
| 511 msgctxt "Testing" |
| 512 msgid "%s unit" |
| 513 msgstr "%d unidade"\n''' |
| 514 newpo = self.convertpot(potsource, posource, ignore_previous=False) |
| 515 newpounit = self.singleunit(newpo) |
| 516 assert str(newpounit) == poexpected |
| 517 assert newpounit.isfuzzy() |
| 518 |
| 413 | 519 |
| 414 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO): | 520 class TestPOT2POCommand(test_convert.TestConvertCommand, TestPOT2PO): |
| 415 """Tests running actual pot2po commands on files""" | 521 """Tests running actual pot2po commands on files""" |
| 416 convertmodule = pot2po | 522 convertmodule = pot2po |
| 417 | 523 |
| 418 def test_help(self): | 524 def test_help(self): |
| 419 """tests getting help""" | 525 """tests getting help""" |
| 420 options = test_convert.TestConvertCommand.test_help(self) | 526 options = test_convert.TestConvertCommand.test_help(self) |
| 421 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") | 527 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") |
| 422 options = self.help_check(options, "-P, --pot") | 528 options = self.help_check(options, "-P, --pot") |
| 423 options = self.help_check(options, "--tm") | 529 options = self.help_check(options, "--tm") |
| 424 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_
SIMILARITY") | 530 options = self.help_check(options, "-s MIN_SIMILARITY, --similarity=MIN_
SIMILARITY") |
| 425 options = self.help_check(options, "--nofuzzymatching", last=True) | 531 options = self.help_check(options, "--nofuzzymatching") |
| 532 options = self.help_check(options, "--ignore-previous", last=True) |
| 426 | 533 |
| OLD | NEW |