changeset 541:4bdbc32c5b64

add actual unit tests for #227 and add missing changelog entry
author fschwarz
date Fri, 11 Mar 2011 16:48:36 +0000
parents 0fb55e21017c
children 1d386483ccb6
files ChangeLog babel/messages/tests/frontend.py
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)
 
 
--- 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'])
Copyright (C) 2012-2017 Edgewall Software