Show More
@@ -5,28 +5,35 b' import nose.tools as nt' | |||
|
5 | 5 | from IPython.utils import openpy |
|
6 | 6 | |
|
7 | 7 | mydir = os.path.dirname(__file__) |
|
8 |
nonascii_path = os.path.join(mydir, |
|
|
8 | nonascii_path = os.path.join(mydir, "../../core/tests/nonascii.py") | |
|
9 | ||
|
9 | 10 | |
|
10 | 11 | def test_detect_encoding(): |
|
11 |
with open(nonascii_path, |
|
|
12 | with open(nonascii_path, "rb") as f: | |
|
12 | 13 | enc, lines = openpy.detect_encoding(f.readline) |
|
13 |
nt.assert_equal(enc, |
|
|
14 | nt.assert_equal(enc, "iso-8859-5") | |
|
15 | ||
|
14 | 16 | |
|
15 | 17 | def test_read_file(): |
|
16 |
with io.open(nonascii_path, encoding= |
|
|
18 | with io.open(nonascii_path, encoding="iso-8859-5") as f: | |
|
17 | 19 | read_specified_enc = f.read() |
|
18 | 20 | read_detected_enc = openpy.read_py_file(nonascii_path, skip_encoding_cookie=False) |
|
19 | 21 | nt.assert_equal(read_detected_enc, read_specified_enc) |
|
20 |
assert |
|
|
22 | assert "coding: iso-8859-5" in read_detected_enc | |
|
23 | ||
|
24 | read_strip_enc_cookie = openpy.read_py_file( | |
|
25 | nonascii_path, skip_encoding_cookie=True | |
|
26 | ) | |
|
27 | assert "coding: iso-8859-5" not in read_strip_enc_cookie | |
|
21 | 28 | |
|
22 | read_strip_enc_cookie = openpy.read_py_file(nonascii_path, skip_encoding_cookie=True) | |
|
23 | assert 'coding: iso-8859-5' not in read_strip_enc_cookie | |
|
24 | 29 | |
|
25 | 30 | def test_source_to_unicode(): |
|
26 |
with io.open(nonascii_path, |
|
|
31 | with io.open(nonascii_path, "rb") as f: | |
|
27 | 32 | source_bytes = f.read() |
|
28 | nt.assert_equal(openpy.source_to_unicode(source_bytes, skip_encoding_cookie=False).splitlines(), | |
|
29 | source_bytes.decode('iso-8859-5').splitlines()) | |
|
33 | nt.assert_equal( | |
|
34 | openpy.source_to_unicode(source_bytes, skip_encoding_cookie=False).splitlines(), | |
|
35 | source_bytes.decode("iso-8859-5").splitlines(), | |
|
36 | ) | |
|
30 | 37 | |
|
31 | 38 | source_no_cookie = openpy.source_to_unicode(source_bytes, skip_encoding_cookie=True) |
|
32 |
nt.assert_not_in( |
|
|
39 | nt.assert_not_in("coding: iso-8859-5", source_no_cookie) |
General Comments 0
You need to be logged in to leave comments.
Login now