Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: tests/fix_encoding_test.py

Issue 6721029: Fix locale.getlocale() exception. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_support.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/fix_encoding_test.py
diff --git a/tests/fix_encoding_test.py b/tests/fix_encoding_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..a6ee18627121c1efacf0160e6c265439a817086d
--- /dev/null
+++ b/tests/fix_encoding_test.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+# coding=utf8
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for fix_encoding.py."""
+
+import os
+import sys
+import unittest
+
+ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+sys.path.insert(0, ROOT_DIR)
+
+import fix_encoding
+
+
+class FixEncodingTest(unittest.TestCase):
+ # Nice mix of latin, hebrew, arabic and chinese. Doesn't mean anything.
+ text = u'Héllô 偉大 سيد'
+
+ def test_code_page(self):
+ # Make sure printing garbage won't throw.
+ print self.text.encode() + '\xff'
+ print >> sys.stderr, self.text.encode() + '\xff'
+
+ def test_utf8(self):
+ # Make sure printing utf-8 works.
+ print self.text.encode('utf-8')
+ print >> sys.stderr, self.text.encode('utf-8')
+
+ def test_unicode(self):
+ # Make sure printing unicode works.
+ print self.text
+ print >> sys.stderr, self.text
+
+ def test_default_encoding(self):
+ self.assertEquals('utf-8', sys.getdefaultencoding())
+
+ def test_win_console(self):
+ if sys.platform != 'win32':
+ return
+ # This should fail if redirected. Can be checked with:
+ # python fix_encoding_test.py > a
+ self.assertEquals(
+ sys.stdout.__class__, fix_encoding.WinUnicodeConsoleOutput)
+ self.assertEquals(
+ sys.stderr.__class__, fix_encoding.WinUnicodeConsoleOutput)
+ self.assertEquals(sys.stdout.encoding, sys.getdefaultencoding())
+ self.assertEquals(sys.stderr.encoding, sys.getdefaultencoding())
+
+ def test_multiple_calls(self):
+ # Shouldn't do anything.
+ self.assertEquals(False, fix_encoding.fix_encoding())
+
+
+if __name__ == '__main__':
+ assert fix_encoding.fix_encoding()
+ unittest.main()
« no previous file with comments | « presubmit_support.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698