Permalink
Browse files

Add tests for IPython.utils.openpy

  • Loading branch information...
1 parent 6811272 commit b9b8a6f0bcfdf2f0c828dd8badaf310a305c5a8c @takluyver committed Apr 14, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 IPython/utils/tests/test_openpy.py
@@ -0,0 +1,23 @@
+import io
+import os.path
+import nose.tools as nt
+
+from IPython.utils import openpy
+
+mydir = os.path.dirname(__file__)
+nonascii_path = os.path.join(mydir, '../../core/tests/nonascii.py')
+
+def test_detect_encoding():
+ f = open(nonascii_path, 'rb')
+ enc, lines = openpy.detect_encoding(f.readline)
+ nt.assert_equal(enc, 'iso-8859-5')
+
+def test_read_file():
+ read_specified_enc = io.open(nonascii_path, encoding='iso-8859-5').read()
+ read_detected_enc = openpy.read_py_file(nonascii_path, skip_encoding_cookie=False)
+ nt.assert_equal(read_detected_enc, read_specified_enc)
+ assert u'encoding: iso-8859-5' in read_detected_enc
+
+ read_strip_enc_cookie = openpy.read_py_file(nonascii_path, skip_encoding_cookie=True)
+ assert u'encoding: iso-8859-5' not in read_strip_enc_cookie
+

0 comments on commit b9b8a6f

Please sign in to comment.