Commits

Felix Schwarz committed 33b039d

add actual unit tests for #227 and add missing changelog entry

Comments (0)

Files changed (2)

    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)
 
 
    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)
 
 

babel/messages/tests/frontend.py

 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'])