Mercurial > babel > old > mirror
comparison babel/messages/tests/frontend.py @ 543:1d386483ccb6
fix a couple of frontend tests so they actually test something (fixes #260)
author | fschwarz |
---|---|
date | Wed, 16 Mar 2011 14:31:44 +0000 |
parents | 4bdbc32c5b64 |
children | 3c306c1f842f |
comparison
equal
deleted
inserted
replaced
541:4bdbc32c5b64 | 543:1d386483ccb6 |
---|---|
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) |
591 update update existing message catalogs from a pot file | 594 update update existing message catalogs from a pot file |
592 """, sys.stdout.getvalue().lower()) | 595 """, sys.stdout.getvalue().lower()) |
593 | 596 |
594 def test_extract_with_default_mapping(self): | 597 def test_extract_with_default_mapping(self): |
595 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | 598 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
596 try: | 599 self.cli.run(sys.argv + ['extract', |
597 self.cli.run(sys.argv + ['extract', | 600 '--copyright-holder', 'FooBar, Inc.', |
598 '--copyright-holder', 'FooBar, Inc.', | 601 '--project', 'TestProject', '--version', '0.1', |
599 '--msgid-bugs-address', 'bugs.address@email.tld', | 602 '--msgid-bugs-address', 'bugs.address@email.tld', |
600 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | 603 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
601 '-o', pot_file, os.path.join(self.datadir, 'project')]) | 604 '-o', pot_file, 'project']) |
602 except SystemExit, e: | 605 assert os.path.isfile(pot_file) |
603 self.assertEqual(0, e.code) | 606 self.assertEqual( |
604 assert os.path.isfile(pot_file) | |
605 self.assertEqual( | |
606 r"""# Translations template for TestProject. | 607 r"""# Translations template for TestProject. |
607 # Copyright (C) %(year)s FooBar, Inc. | 608 # Copyright (C) %(year)s FooBar, Inc. |
608 # This file is distributed under the same license as the TestProject | 609 # This file is distributed under the same license as the TestProject |
609 # project. | 610 # project. |
610 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | 611 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
621 "MIME-Version: 1.0\n" | 622 "MIME-Version: 1.0\n" |
622 "Content-Type: text/plain; charset=utf-8\n" | 623 "Content-Type: text/plain; charset=utf-8\n" |
623 "Content-Transfer-Encoding: 8bit\n" | 624 "Content-Transfer-Encoding: 8bit\n" |
624 "Generated-By: Babel %(version)s\n" | 625 "Generated-By: Babel %(version)s\n" |
625 | 626 |
626 #. This will be a translator coment, | 627 #. TRANSLATOR: This will be a translator coment, |
627 #. that will include several lines | 628 #. that will include several lines |
628 #: project/file1.py:8 | 629 #: project/file1.py:8 |
629 msgid "bar" | 630 msgid "bar" |
630 msgstr "" | 631 msgstr "" |
631 | 632 |
647 tzinfo=LOCALTZ, locale='en')}, | 648 tzinfo=LOCALTZ, locale='en')}, |
648 open(pot_file, 'U').read()) | 649 open(pot_file, 'U').read()) |
649 | 650 |
650 def test_extract_with_mapping_file(self): | 651 def test_extract_with_mapping_file(self): |
651 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') | 652 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') |
652 try: | 653 self.cli.run(sys.argv + ['extract', |
653 self.cli.run(sys.argv + ['extract', | 654 '--copyright-holder', 'FooBar, Inc.', |
654 '--copyright-holder', 'FooBar, Inc.', | 655 '--project', 'TestProject', '--version', '0.1', |
655 '--msgid-bugs-address', 'bugs.address@email.tld', | 656 '--msgid-bugs-address', 'bugs.address@email.tld', |
656 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), | 657 '--mapping', os.path.join(self.datadir, 'mapping.cfg'), |
657 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', | 658 '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', |
658 '-o', pot_file, os.path.join(self.datadir, 'project')]) | 659 '-o', pot_file, 'project']) |
659 except SystemExit, e: | 660 assert os.path.isfile(pot_file) |
660 self.assertEqual(0, e.code) | 661 self.assertEqual( |
661 assert os.path.isfile(pot_file) | |
662 self.assertEqual( | |
663 r"""# Translations template for TestProject. | 662 r"""# Translations template for TestProject. |
664 # Copyright (C) %(year)s FooBar, Inc. | 663 # Copyright (C) %(year)s FooBar, Inc. |
665 # This file is distributed under the same license as the TestProject | 664 # This file is distributed under the same license as the TestProject |
666 # project. | 665 # project. |
667 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. | 666 # FIRST AUTHOR <EMAIL@ADDRESS>, %(year)s. |
678 "MIME-Version: 1.0\n" | 677 "MIME-Version: 1.0\n" |
679 "Content-Type: text/plain; charset=utf-8\n" | 678 "Content-Type: text/plain; charset=utf-8\n" |
680 "Content-Transfer-Encoding: 8bit\n" | 679 "Content-Transfer-Encoding: 8bit\n" |
681 "Generated-By: Babel %(version)s\n" | 680 "Generated-By: Babel %(version)s\n" |
682 | 681 |
683 #. This will be a translator coment, | 682 #. TRANSLATOR: This will be a translator coment, |
684 #. that will include several lines | 683 #. that will include several lines |
685 #: project/file1.py:8 | 684 #: project/file1.py:8 |
686 msgid "bar" | 685 msgid "bar" |
687 msgstr "" | 686 msgstr "" |
688 | 687 |
699 open(pot_file, 'U').read()) | 698 open(pot_file, 'U').read()) |
700 | 699 |
701 def test_init_with_output_dir(self): | 700 def test_init_with_output_dir(self): |
702 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | 701 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', |
703 'LC_MESSAGES', 'messages.po') | 702 'LC_MESSAGES', 'messages.po') |
704 try: | 703 self.cli.run(sys.argv + ['init', |
705 self.cli.run(sys.argv + ['init', | 704 '--locale', 'en_US', |
706 '--locale', 'en_US', | 705 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
707 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 706 '-i', os.path.join(self.datadir, 'project', 'i18n', 'messages.pot')]) |
708 '-i', os.path.join(self.datadir, 'project', 'i18n', | 707 assert os.path.isfile(po_file) |
709 'messages.pot')]) | 708 self.assertEqual( |
710 except SystemExit, e: | |
711 self.assertEqual(0, e.code) | |
712 assert os.path.isfile(po_file) | |
713 self.assertEqual( | |
714 r"""# English (United States) translations for TestProject. | 709 r"""# English (United States) translations for TestProject. |
715 # Copyright (C) 2007 FooBar, Inc. | 710 # Copyright (C) 2007 FooBar, Inc. |
716 # This file is distributed under the same license as the TestProject | 711 # This file is distributed under the same license as the TestProject |
717 # project. | 712 # project. |
718 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | 713 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
750 open(po_file, 'U').read()) | 745 open(po_file, 'U').read()) |
751 | 746 |
752 def test_init_singular_plural_forms(self): | 747 def test_init_singular_plural_forms(self): |
753 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', | 748 po_file = os.path.join(self.datadir, 'project', 'i18n', 'ja_JP', |
754 'LC_MESSAGES', 'messages.po') | 749 'LC_MESSAGES', 'messages.po') |
755 try: | 750 self.cli.run(sys.argv + ['init', |
756 self.cli.run(sys.argv + ['init', | 751 '--locale', 'ja_JP', |
757 '--locale', 'ja_JP', | 752 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
758 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 753 '-i', os.path.join(self.datadir, 'project', 'i18n', |
759 '-i', os.path.join(self.datadir, 'project', 'i18n', | 754 'messages.pot')]) |
760 'messages.pot')]) | |
761 except SystemExit, e: | |
762 self.assertEqual(0, e.code) | |
763 assert os.path.isfile(po_file) | 755 assert os.path.isfile(po_file) |
764 self.assertEqual( | 756 self.assertEqual( |
765 r"""# Japanese (Japan) translations for TestProject. | 757 r"""# Japanese (Japan) translations for TestProject. |
766 # Copyright (C) 2007 FooBar, Inc. | 758 # Copyright (C) 2007 FooBar, Inc. |
767 # This file is distributed under the same license as the TestProject | 759 # This file is distributed under the same license as the TestProject |
800 open(po_file, 'U').read()) | 792 open(po_file, 'U').read()) |
801 | 793 |
802 def test_init_more_than_2_plural_forms(self): | 794 def test_init_more_than_2_plural_forms(self): |
803 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', | 795 po_file = os.path.join(self.datadir, 'project', 'i18n', 'lv_LV', |
804 'LC_MESSAGES', 'messages.po') | 796 'LC_MESSAGES', 'messages.po') |
805 try: | 797 self.cli.run(sys.argv + ['init', |
806 self.cli.run(sys.argv + ['init', | 798 '--locale', 'lv_LV', |
807 '--locale', 'lv_LV', | 799 '-d', os.path.join(self.datadir, 'project', 'i18n'), |
808 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 800 '-i', os.path.join(self.datadir, 'project', 'i18n', |
809 '-i', os.path.join(self.datadir, 'project', 'i18n', | 801 'messages.pot')]) |
810 'messages.pot')]) | |
811 except SystemExit, e: | |
812 self.assertEqual(0, e.code) | |
813 assert os.path.isfile(po_file) | 802 assert os.path.isfile(po_file) |
814 self.assertEqual( | 803 self.assertEqual( |
815 r"""# Latvian (Latvia) translations for TestProject. | 804 r"""# Latvian (Latvia) translations for TestProject. |
816 # Copyright (C) 2007 FooBar, Inc. | 805 # Copyright (C) 2007 FooBar, Inc. |
817 # This file is distributed under the same license as the TestProject | 806 # This file is distributed under the same license as the TestProject |