# HG changeset patch # User fschwarz # Date 1299862116 0 # Node ID f627cb879dc30ea10a4bdd545a1e73dcdd5f1acc # Parent 5984bffd557565216c95bdcdcd26c0bc10d57d53 add actual unit tests for #227 and add missing changelog entry diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,8 @@ string does not contain any string formattings (ticket #150). * Fix Serbian plural forms (ticket #213). * Small speed improvement in format_date() (ticket #216). + * Fix so frontend.CommandLineInterface.run does not accumulate logging + handlers (#227, reported with initial patch by dfraser) * Fix exception if environment contains an invalid locale setting (#200) @@ -59,6 +61,8 @@ items (ticket #217) * Fix bad check in format_time (ticket #257, reported with patch and tests by jomae) + * Fix so frontend.CommandLineInterface.run does not accumulate logging + handlers (#227, reported with initial patch by dfraser) * Fix exception if environment contains an invalid locale setting (#200) diff --git a/babel/messages/tests/frontend.py b/babel/messages/tests/frontend.py --- a/babel/messages/tests/frontend.py +++ b/babel/messages/tests/frontend.py @@ -541,6 +541,33 @@ pybabel: error: no valid command or option passed. try the -h/--help option for more information. """, sys.stderr.getvalue().lower()) + def _run_init_catalog(self): + i18n_dir = os.path.join(self.datadir, 'project', 'i18n') + pot_path = os.path.join(self.datadir, 'project', 'i18n', 'messages.pot') + init_argv = sys.argv + ['init', '--locale', 'en_US', '-d', i18n_dir, + '-i', pot_path] + self.cli.run(init_argv) + + def test_no_duplicated_output_for_multiple_runs(self): + self._run_init_catalog() + first_output = sys.stderr.getvalue() + self._run_init_catalog() + second_output = sys.stderr.getvalue()[len(first_output):] + + # in case the log message is not duplicated we should get the same + # output as before + self.assertEqual(first_output, second_output) + + def test_frontend_can_log_to_predefined_handler(self): + custom_stream = StringIO() + log = logging.getLogger('babel') + log.addHandler(logging.StreamHandler(custom_stream)) + + self._run_init_catalog() + self.assertNotEqual(id(sys.stderr), id(custom_stream)) + self.assertEqual('', sys.stderr.getvalue()) + assert len(custom_stream.getvalue()) > 0 + def test_help(self): try: self.cli.run(sys.argv + ['--help'])