From: david-sarah Date: Sat, 17 Jul 2010 04:58:16 +0000 (-0700) Subject: stringutils: add test for when sys.stdout has no encoding attribute (fixes #1099). X-Git-Url: https://git.rkrishnan.org/vdrive/frontends/wapi.txt?a=commitdiff_plain;h=c59f9b162fece82c7868be7ee1789b53c7947075;p=tahoe-lafs%2Ftahoe-lafs.git stringutils: add test for when sys.stdout has no encoding attribute (fixes #1099). --- diff --git a/src/allmydata/test/test_encodingutil.py b/src/allmydata/test/test_encodingutil.py index a287bf41..10310ca6 100644 --- a/src/allmydata/test/test_encodingutil.py +++ b/src/allmydata/test/test_encodingutil.py @@ -35,7 +35,7 @@ if __name__ == "__main__": from twisted.trial import unittest from mock import patch -import sys +import sys, locale from allmydata.test.common_util import ReallyEqualMixin from allmydata.util.encodingutil import argv_to_unicode, unicode_to_url, \ @@ -64,7 +64,28 @@ class StringUtilsErrors(ReallyEqualMixin, unittest.TestCase): mock_stdout.encoding = 'nonexistent_encoding' self.failUnlessRaises(AssertionError, _reload) - # TODO: mock_stdout.encoding = None + @patch('locale.getpreferredencoding') + def test_get_output_encoding_not_from_stdout(self, mock_locale_getpreferredencoding): + locale # hush pyflakes + mock_locale_getpreferredencoding.return_value = 'koi8-r' + + class DummyStdout: + pass + old_stdout = sys.stdout + sys.stdout = DummyStdout() + try: + _reload() + self.failUnlessReallyEqual(get_output_encoding(), 'koi8-r') + + sys.stdout.encoding = None + _reload() + self.failUnlessReallyEqual(get_output_encoding(), 'koi8-r') + + mock_locale_getpreferredencoding.return_value = None + _reload() + self.failUnlessReallyEqual(get_output_encoding(), 'utf-8') + finally: + sys.stdout = old_stdout @patch('sys.stdout') def test_argv_to_unicode(self, mock):