Mercurial > babel > old > babel-test
comparison babel/messages/tests/frontend.py @ 548:59db0f962e00
test refactoring: clear global babel logger handlers to decrease test interdependencies (follow-up on #227)
author | fschwarz |
---|---|
date | Sat, 19 Mar 2011 21:13:34 +0000 |
parents | aa471d38bcde |
children |
comparison
equal
deleted
inserted
replaced
547:bf8b876cb8c7 | 548:59db0f962e00 |
---|---|
511 sys.argv = ['pybabel'] | 511 sys.argv = ['pybabel'] |
512 sys.stdout = StringIO() | 512 sys.stdout = StringIO() |
513 sys.stderr = StringIO() | 513 sys.stderr = StringIO() |
514 os.chdir(self.datadir) | 514 os.chdir(self.datadir) |
515 | 515 |
516 # Logging handlers will be reused if possible (#227). This breaks the | 516 self._remove_log_handlers() |
517 # implicit assumption that our newly created StringIO for sys.stderr | |
518 # contains the console output. Removing the old handler ensures that a | |
519 # new handler with our new StringIO instance will be used. | |
520 log = logging.getLogger('babel') | |
521 for handler in log.handlers: | |
522 log.removeHandler(handler) | |
523 self.cli = frontend.CommandLineInterface() | 517 self.cli = frontend.CommandLineInterface() |
524 | 518 |
525 def tearDown(self): | 519 def tearDown(self): |
526 os.chdir(self.orig_working_dir) | 520 os.chdir(self.orig_working_dir) |
527 sys.argv = self.orig_argv | 521 sys.argv = self.orig_argv |
529 sys.stderr = self.orig_stderr | 523 sys.stderr = self.orig_stderr |
530 for dirname in ['lv_LV', 'ja_JP']: | 524 for dirname in ['lv_LV', 'ja_JP']: |
531 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) | 525 locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) |
532 if os.path.isdir(locale_dir): | 526 if os.path.isdir(locale_dir): |
533 shutil.rmtree(locale_dir) | 527 shutil.rmtree(locale_dir) |
528 self._remove_log_handlers() | |
529 | |
530 def _remove_log_handlers(self): | |
531 # Logging handlers will be reused if possible (#227). This breaks the | |
532 # implicit assumption that our newly created StringIO for sys.stderr | |
533 # contains the console output. Removing the old handler ensures that a | |
534 # new handler with our new StringIO instance will be used. | |
535 log = logging.getLogger('babel') | |
536 for handler in log.handlers: | |
537 log.removeHandler(handler) | |
534 | 538 |
535 def test_usage(self): | 539 def test_usage(self): |
536 try: | 540 try: |
537 self.cli.run(sys.argv) | 541 self.cli.run(sys.argv) |
538 self.fail('Expected SystemExit') | 542 self.fail('Expected SystemExit') |