Mercurial > babel > old > babel-test
comparison babel/messages/tests/frontend.py @ 542:0c7c739ac8d6 stable-0.9.x
merge r593 from trunk
author | fschwarz |
---|---|
date | Wed, 16 Mar 2011 14:32:34 +0000 |
parents | d71a490c11df |
children |
comparison
equal
deleted
inserted
replaced
540:d71a490c11df | 542:0c7c739ac8d6 |
---|---|
502 | 502 |
503 class CommandLineInterfaceTestCase(unittest.TestCase): | 503 class CommandLineInterfaceTestCase(unittest.TestCase): |
504 | 504 |
505 def setUp(self): | 505 def setUp(self): |
506 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | 506 self.datadir = os.path.join(os.path.dirname(__file__), 'data') |
507 self.orig_working_dir = os.getcwd() | |
507 self.orig_argv = sys.argv | 508 self.orig_argv = sys.argv |
508 self.orig_stdout = sys.stdout | 509 self.orig_stdout = sys.stdout |
509 self.orig_stderr = sys.stderr | 510 self.orig_stderr = sys.stderr |
510 sys.argv = ['pybabel'] | 511 sys.argv = ['pybabel'] |
511 sys.stdout = StringIO() | 512 sys.stdout = StringIO() |
512 sys.stderr = StringIO() | 513 sys.stderr = StringIO() |
514 os.chdir(self.datadir) | |
513 | 515 |
514 # Logging handlers will be reused if possible (#227). This breaks the | 516 # Logging handlers will be reused if possible (#227). This breaks the |
515 # implicit assumption that our newly created StringIO for sys.stderr | 517 # implicit assumption that our newly created StringIO for sys.stderr |
516 # contains the console output. Removing the old handler ensures that a | 518 # contains the console output. Removing the old handler ensures that a |
517 # new handler with our new StringIO instance will be used. | 519 # new handler with our new StringIO instance will be used. |
519 for handler in log.handlers: | 521 for handler in log.handlers: |
520 log.removeHandler(handler) | 522 log.removeHandler(handler) |
521 self.cli = frontend.CommandLineInterface() | 523 self.cli = frontend.CommandLineInterface() |
522 | 524 |
523 def tearDown(self): | 525 def tearDown(self): |
526 os.chdir(self.orig_working_dir) | |
524 sys.argv = self.orig_argv | 527 sys.argv = self.orig_argv |
525 sys.stdout = self.orig_stdout | 528 sys.stdout = self.orig_stdout |
526 sys.stderr = self.orig_stderr | 529 sys.stderr = self.orig_stderr |
527 for dirname in ['lv_LV', 'ja_JP']: | 530 for dirname in ['lv_LV', 'ja_JP']: |
528 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) | 531 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) |
598 update update existing message catalogs from a pot file | 601 update update existing message catalogs from a pot file |
599 """, sys.stdout.getvalue().lower()) | 602 """, sys.stdout.getvalue().lower()) |
600 | 603 |
601 def test_extract_with_default_mapping(self): | 604 def test_extract_with_default_mapping(self): |
602 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | 605 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
603 try: | 606 self.cli.run(sys.argv + ['extract', |
604 self.cli.run(sys.argv + ['extract', | 607 '--copyright-holder', 'FooBar, Inc.', |
605 '--copyright-holder', 'FooBar, Inc.', | 608 '--project', 'TestProject', '--version', '0.1', |
606 '--msgid-bugs-address', 'bugs.address@email.tld', | 609 '--msgid-bugs-address', 'bugs.address@email.tld', |
607 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | 610 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
608 '-o', pot_file, os.path.join(self.datadir, 'project')]) | 611 '-o', pot_file, 'project']) |
609 except SystemExit, e: | 612 assert os.path.isfile(pot_file) |
610 self.assertEqual(0, e.code) | 613 self.assertEqual( |
611 assert os.path.isfile(pot_file) | |
612 self.assertEqual( | |
613 r"""# Translations template for TestProject. | 614 r"""# Translations template for TestProject. |
614 # Copyright (C) %(year)s FooBar, Inc. | 615 # Copyright (C) %(year)s FooBar, Inc. |
615 # This file is distributed under the same license as the TestProject | 616 # This file is distributed under the same license as the TestProject |
616 # project. | 617 # project. |
617 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | 618 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
628 "MIME-Version: 1.0\n" | 629 "MIME-Version: 1.0\n" |
629 "Content-Type: text/plain; charset=utf-8\n" | 630 "Content-Type: text/plain; charset=utf-8\n" |
630 "Content-Transfer-Encoding: 8bit\n" | 631 "Content-Transfer-Encoding: 8bit\n" |
631 "Generated-By: Babel %(version)s\n" | 632 "Generated-By: Babel %(version)s\n" |
632 | 633 |
633 #. This will be a translator coment, | 634 #. TRANSLATOR: This will be a translator coment, |
634 #. that will include several lines | 635 #. that will include several lines |
635 #: project/file1.py:8 | 636 #: project/file1.py:8 |
636 msgid "bar" | 637 msgid "bar" |
637 msgstr "" | 638 msgstr "" |
638 | 639 |
654 tzinfo=LOCALTZ, locale='en')}, | 655 tzinfo=LOCALTZ, locale='en')}, |
655 open(pot_file, 'U').read()) | 656 open(pot_file, 'U').read()) |
656 | 657 |
657 def test_extract_with_mapping_file(self): | 658 def test_extract_with_mapping_file(self): |
658 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | 659 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
659 try: | 660 self.cli.run(sys.argv + ['extract', |
660 self.cli.run(sys.argv + ['extract', | 661 '--copyright-holder', 'FooBar, Inc.', |
661 '--copyright-holder', 'FooBar, Inc.', | 662 '--project', 'TestProject', '--version', '0.1', |
662 '--msgid-bugs-address', 'bugs.address@email.tld', | 663 '--msgid-bugs-address', 'bugs.address@email.tld', |
663 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | 664 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), |
664 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | 665 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
665 '-o', pot_file, os.path.join(self.datadir, 'project')]) | 666 '-o', pot_file, 'project']) |
666 except SystemExit, e: | 667 assert os.path.isfile(pot_file) |
667 self.assertEqual(0, e.code) | 668 self.assertEqual( |
668 assert os.path.isfile(pot_file) | |
669 self.assertEqual( | |
670 r"""# Translations template for TestProject. | 669 r"""# Translations template for TestProject. |
671 # Copyright (C) %(year)s FooBar, Inc. | 670 # Copyright (C) %(year)s FooBar, Inc. |
672 # This file is distributed under the same license as the TestProject | 671 # This file is distributed under the same license as the TestProject |
673 # project. | 672 # project. |
674 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | 673 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
685 "MIME-Version: 1.0\n" | 684 "MIME-Version: 1.0\n" |
686 "Content-Type: text/plain; charset=utf-8\n" | 685 "Content-Type: text/plain; charset=utf-8\n" |
687 "Content-Transfer-Encoding: 8bit\n" | 686 "Content-Transfer-Encoding: 8bit\n" |
688 "Generated-By: Babel %(version)s\n" | 687 "Generated-By: Babel %(version)s\n" |
689 | 688 |
690 #. This will be a translator coment, | 689 #. TRANSLATOR: This will be a translator coment, |
691 #. that will include several lines | 690 #. that will include several lines |
692 #: project/file1.py:8 | 691 #: project/file1.py:8 |
693 msgid "bar" | 692 msgid "bar" |
694 msgstr "" | 693 msgstr "" |
695 | 694 |
706 open(pot_file, 'U').read()) | 705 open(pot_file, 'U').read()) |
707 | 706 |
708 def test_init_with_output_dir(self): | 707 def test_init_with_output_dir(self): |
709 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | 708 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', |
710 'LC_MESSAGES', 'messages.po') | 709 'LC_MESSAGES', 'messages.po') |
711 try: | 710 self.cli.run(sys.argv + ['init', |
712 self.cli.run(sys.argv + ['init', | 711 '--locale', 'en_US', |
713 '--locale', 'en_US', | 712 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
714 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 713 '-i', os.path.join(self.datadir, 'project', 'i18n', 'messages.pot')]) |
715 '-i', os.path.join(self.datadir, 'project', 'i18n', | 714 assert os.path.isfile(po_file) |
716 'messages.pot')]) | 715 self.assertEqual( |
717 except SystemExit, e: | |
718 self.assertEqual(0, e.code) | |
719 assert os.path.isfile(po_file) | |
720 self.assertEqual( | |
721 r"""# English (United States) translations for TestProject. | 716 r"""# English (United States) translations for TestProject. |
722 # Copyright (C) 2007 FooBar, Inc. | 717 # Copyright (C) 2007 FooBar, Inc. |
723 # This file is distributed under the same license as the TestProject | 718 # This file is distributed under the same license as the TestProject |
724 # project. | 719 # project. |
725 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | 720 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
757 open(po_file, 'U').read()) | 752 open(po_file, 'U').read()) |
758 | 753 |
759 def test_init_singular_plural_forms(self): | 754 def test_init_singular_plural_forms(self): |
760 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', | 755 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', |
761 'LC_MESSAGES', 'messages.po') | 756 'LC_MESSAGES', 'messages.po') |
762 try: | 757 self.cli.run(sys.argv + ['init', |
763 self.cli.run(sys.argv + ['init', | 758 '--locale', 'ja_JP', |
764 '--locale', 'ja_JP', | 759 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
765 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 760 '-i', os.path.join(self.datadir, 'project', 'i18n', |
766 '-i', os.path.join(self.datadir, 'project', 'i18n', | 761 'messages.pot')]) |
767 'messages.pot')]) | |
768 except SystemExit, e: | |
769 self.assertEqual(0, e.code) | |
770 assert os.path.isfile(po_file) | 762 assert os.path.isfile(po_file) |
771 self.assertEqual( | 763 self.assertEqual( |
772 r"""# Japanese (Japan) translations for TestProject. | 764 r"""# Japanese (Japan) translations for TestProject. |
773 # Copyright (C) 2007 FooBar, Inc. | 765 # Copyright (C) 2007 FooBar, Inc. |
774 # This file is distributed under the same license as the TestProject | 766 # This file is distributed under the same license as the TestProject |
807 open(po_file, 'U').read()) | 799 open(po_file, 'U').read()) |
808 | 800 |
809 def test_init_more_than_2_plural_forms(self): | 801 def test_init_more_than_2_plural_forms(self): |
810 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', | 802 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', |
811 'LC_MESSAGES', 'messages.po') | 803 'LC_MESSAGES', 'messages.po') |
812 try: | 804 self.cli.run(sys.argv + ['init', |
813 self.cli.run(sys.argv + ['init', | 805 '--locale', 'lv_LV', |
814 '--locale', 'lv_LV', | 806 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
815 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 807 '-i', os.path.join(self.datadir, 'project', 'i18n', |
816 '-i', os.path.join(self.datadir, 'project', 'i18n', | 808 'messages.pot')]) |
817 'messages.pot')]) | |
818 except SystemExit, e: | |
819 self.assertEqual(0, e.code) | |
820 assert os.path.isfile(po_file) | 809 assert os.path.isfile(po_file) |
821 self.assertEqual( | 810 self.assertEqual( |
822 r"""# Latvian (Latvia) translations for TestProject. | 811 r"""# Latvian (Latvia) translations for TestProject. |
823 # Copyright (C) 2007 FooBar, Inc. | 812 # Copyright (C) 2007 FooBar, Inc. |
824 # This file is distributed under the same license as the TestProject | 813 # This file is distributed under the same license as the TestProject |