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