Mercurial > babel > old > mirror
comparison babel/messages/tests/frontend.py @ 234:541b6d630575
Use logging module for output from CLI frontend.
author | cmlenz |
---|---|
date | Mon, 30 Jul 2007 20:28:43 +0000 |
parents | d3bde66ac8a9 |
children | 72351fd5fc29 |
comparison
equal
deleted
inserted
replaced
233:451aac9888f5 | 234:541b6d630575 |
---|---|
428 def setUp(self): | 428 def setUp(self): |
429 self.datadir = os.path.join(os.path.dirname(__file__), 'data') | 429 self.datadir = os.path.join(os.path.dirname(__file__), 'data') |
430 self.orig_argv = sys.argv | 430 self.orig_argv = sys.argv |
431 self.orig_stdout = sys.stdout | 431 self.orig_stdout = sys.stdout |
432 self.orig_stderr = sys.stderr | 432 self.orig_stderr = sys.stderr |
433 sys.argv = ['babel'] | 433 sys.argv = ['pybabel'] |
434 sys.stdout = StringIO() | 434 sys.stdout = StringIO() |
435 sys.stderr = StringIO() | 435 sys.stderr = StringIO() |
436 self.cli = frontend.CommandLineInterface() | 436 self.cli = frontend.CommandLineInterface() |
437 | 437 |
438 def tearDown(self): | 438 def tearDown(self): |
445 self.cli.run(sys.argv) | 445 self.cli.run(sys.argv) |
446 self.fail('Expected SystemExit') | 446 self.fail('Expected SystemExit') |
447 except SystemExit, e: | 447 except SystemExit, e: |
448 self.assertEqual(2, e.code) | 448 self.assertEqual(2, e.code) |
449 self.assertEqual("""\ | 449 self.assertEqual("""\ |
450 usage: babel command [options] [args] | 450 usage: pybabel command [options] [args] |
451 | 451 |
452 babel: error: incorrect number of arguments | 452 pybabel: error: incorrect number of arguments |
453 """, sys.stderr.getvalue().lower()) | 453 """, sys.stderr.getvalue().lower()) |
454 | 454 |
455 def test_help(self): | 455 def test_help(self): |
456 try: | 456 try: |
457 self.cli.run(sys.argv + ['--help']) | 457 self.cli.run(sys.argv + ['--help']) |
458 self.fail('Expected SystemExit') | 458 self.fail('Expected SystemExit') |
459 except SystemExit, e: | 459 except SystemExit, e: |
460 self.assertEqual(0, e.code) | 460 self.assertEqual(0, e.code) |
461 self.assertEqual("""\ | 461 self.assertEqual("""\ |
462 usage: babel command [options] [args] | 462 usage: pybabel command [options] [args] |
463 | 463 |
464 options: | 464 options: |
465 --version show program's version number and exit | 465 --version show program's version number and exit |
466 -h, --help show this help message and exit | 466 -h, --help show this help message and exit |
467 --list-locales print all known locales and exit | 467 --list-locales print all known locales and exit |
468 -v, --verbose print as much as possible | |
469 -q, --quiet print as little as possible | |
468 | 470 |
469 commands: | 471 commands: |
470 compile compile message catalogs to mo files | 472 compile compile message catalogs to mo files |
471 extract extract messages from source files and generate a pot file | 473 extract extract messages from source files and generate a pot file |
472 init create new message catalogs from a pot file | 474 init create new message catalogs from a pot file |
630 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', | 632 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', |
631 tzinfo=LOCALTZ, locale='en')}, | 633 tzinfo=LOCALTZ, locale='en')}, |
632 open(po_file, 'U').read()) | 634 open(po_file, 'U').read()) |
633 | 635 |
634 def test_compile_catalog(self): | 636 def test_compile_catalog(self): |
635 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | 637 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', |
636 'LC_MESSAGES', 'messages.po') | 638 'LC_MESSAGES', 'messages.po') |
637 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'messages.pot') | 639 mo_file = po_file.replace('.po', '.mo') |
638 try: | 640 self.cli.run(sys.argv + ['compile', |
639 self.cli.run(sys.argv + ['init', | 641 '--locale', 'de_DE', |
640 '--locale', 'en_US', | 642 '-d', os.path.join(self.datadir, 'project', 'i18n')]) |
641 '-d', os.path.join(self.datadir, 'project', 'i18n'), | 643 assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file |
642 '-i', pot_file]) | 644 self.assertEqual("""\ |
643 except SystemExit, e: | 645 catalog %r is marked as fuzzy, skipping |
644 self.assertEqual(0, e.code) | 646 """ % (po_file), sys.stderr.getvalue()) |
645 assert os.path.isfile(po_file) | 647 |
648 def test_compile_fuzzy_catalog(self): | |
649 po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', | |
650 'LC_MESSAGES', 'messages.po') | |
651 mo_file = po_file.replace('.po', '.mo') | |
646 try: | 652 try: |
647 self.cli.run(sys.argv + ['compile', | 653 self.cli.run(sys.argv + ['compile', |
648 '--locale', 'en_US', | 654 '--locale', 'de_DE', '--use-fuzzy', |
649 '-d', os.path.join(self.datadir, 'project', 'i18n')]) | 655 '-d', os.path.join(self.datadir, 'project', 'i18n')]) |
650 except SystemExit, e: | 656 assert os.path.isfile(mo_file) |
651 self.assertEqual(0, e.code) | |
652 mo_file = po_file.replace('.po', '.mo') | |
653 assert not os.path.isfile(mo_file) | |
654 self.assertEqual("""\ | 657 self.assertEqual("""\ |
655 creating catalog %r based on %r | |
656 catalog is marked as fuzzy, not compiling it | |
657 """ % (po_file, pot_file), sys.stdout.getvalue()) | |
658 shutil.rmtree(os.path.join(self.datadir, 'project', 'i18n', | |
659 'en_US')) | |
660 | |
661 def test_compile_fuzzy_catalog(self): | |
662 self.setUp() | |
663 po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', | |
664 'LC_MESSAGES', 'messages.po') | |
665 pot_file = os.path.join(self.datadir, 'project', 'i18n', 'messages.pot') | |
666 try: | |
667 self.cli.run(sys.argv + ['init', | |
668 '--locale', 'en_US', | |
669 '-d', os.path.join(self.datadir, 'project', 'i18n'), | |
670 '-i', pot_file]) | |
671 except SystemExit, e: | |
672 self.assertEqual(0, e.code) | |
673 assert os.path.isfile(po_file) | |
674 self.cli.run(sys.argv + ['compile', | |
675 '--locale', 'en_US', '--use-fuzzy', | |
676 '-d', os.path.join(self.datadir, 'project', 'i18n')]) | |
677 mo_file = po_file.replace('.po', '.mo') | |
678 assert os.path.isfile(mo_file) | |
679 self.assertEqual("""\ | |
680 creating catalog %r based on %r | |
681 compiling catalog %r to %r | 658 compiling catalog %r to %r |
682 """ % (po_file, pot_file, po_file, mo_file), sys.stdout.getvalue()) | 659 """ % (po_file, mo_file), sys.stderr.getvalue()) |
683 shutil.rmtree(os.path.join(self.datadir, 'project', 'i18n', 'en_US')) | 660 finally: |
661 if os.path.isfile(mo_file): | |
662 os.unlink(mo_file) | |
684 | 663 |
685 | 664 |
686 def suite(): | 665 def suite(): |
687 suite = unittest.TestSuite() | 666 suite = unittest.TestSuite() |
688 suite.addTest(doctest.DocTestSuite(frontend)) | 667 suite.addTest(doctest.DocTestSuite(frontend)) |