9
9
from collections import OrderedDict
10
10
import csv
11
11
from datetime import datetime
12
+ from io import TextIOWrapper
12
13
import os
13
14
import platform
14
15
from tempfile import TemporaryFile
@@ -75,9 +76,6 @@ def _set_noconvert_columns(self):
75
76
76
77
77
78
def test_bytes_io_input (all_parsers ):
78
- if compat .PY2 :
79
- pytest .skip ("Bytes-related test does not need to work on Python 2.x" )
80
-
81
79
encoding = "cp1255"
82
80
parser = all_parsers
83
81
@@ -112,8 +110,7 @@ def test_bad_stream_exception(all_parsers, csv_dir_path):
112
110
utf8 = codecs .lookup ('utf-8' )
113
111
parser = all_parsers
114
112
115
- msg = ("'utf-8' codec can't decode byte" if compat .PY3
116
- else "'utf8' codec can't decode byte" )
113
+ msg = "'utf-8' codec can't decode byte"
117
114
118
115
# Stream must be binary UTF8.
119
116
with open (path , "rb" ) as handle , codecs .StreamRecoder (
@@ -124,7 +121,6 @@ def test_bad_stream_exception(all_parsers, csv_dir_path):
124
121
parser .read_csv (stream )
125
122
126
123
127
- @pytest .mark .skipif (compat .PY2 , reason = "PY3-only test" )
128
124
def test_read_csv_local (all_parsers , csv1 ):
129
125
prefix = u ("file:///" ) if compat .is_platform_windows () else u ("file://" )
130
126
parser = all_parsers
@@ -963,10 +959,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
963
959
f .write (bytes_data )
964
960
965
961
bytes_buffer = BytesIO (data .encode (utf8 ))
966
-
967
- if compat .PY3 :
968
- from io import TextIOWrapper
969
- bytes_buffer = TextIOWrapper (bytes_buffer , encoding = utf8 )
962
+ bytes_buffer = TextIOWrapper (bytes_buffer , encoding = utf8 )
970
963
971
964
result = parser .read_csv (path , encoding = encoding , ** kwargs )
972
965
expected = parser .read_csv (bytes_buffer , encoding = utf8 , ** kwargs )
@@ -978,7 +971,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
978
971
@pytest .mark .parametrize ("buffer" , [
979
972
False ,
980
973
pytest .param (True , marks = pytest .mark .skipif (
981
- compat . PY3 , reason = "Not supported on PY3 " ))])
974
+ True , reason = "Not supported" ))])
982
975
def test_utf16_example (all_parsers , csv_dir_path , buffer ):
983
976
path = os .path .join (csv_dir_path , "utf16_ex.txt" )
984
977
parser = all_parsers
@@ -1565,22 +1558,17 @@ def test_iteration_open_handle(all_parsers):
1565
1558
kwargs = dict (squeeze = True , header = None )
1566
1559
1567
1560
with tm .ensure_clean () as path :
1568
- with open (path , "wb" if compat . PY2 else " w" ) as f :
1561
+ with open (path , "w" ) as f :
1569
1562
f .write ("AAA\n BBB\n CCC\n DDD\n EEE\n FFF\n GGG" )
1570
1563
1571
- with open (path , "rb" if compat . PY2 else " r" ) as f :
1564
+ with open (path , "r" ) as f :
1572
1565
for line in f :
1573
1566
if "CCC" in line :
1574
1567
break
1575
1568
1576
- if parser .engine == "c" and compat .PY2 :
1577
- msg = "Mixing iteration and read methods would lose data"
1578
- with pytest .raises (ValueError , match = msg ):
1579
- parser .read_csv (f , ** kwargs )
1580
- else :
1581
- result = parser .read_csv (f , ** kwargs )
1582
- expected = Series (["DDD" , "EEE" , "FFF" , "GGG" ], name = 0 )
1583
- tm .assert_series_equal (result , expected )
1569
+ result = parser .read_csv (f , ** kwargs )
1570
+ expected = Series (["DDD" , "EEE" , "FFF" , "GGG" ], name = 0 )
1571
+ tm .assert_series_equal (result , expected )
1584
1572
1585
1573
1586
1574
@pytest .mark .parametrize ("data,thousands,decimal" , [
0 commit comments