@@ -1122,19 +1122,22 @@ class mydialect(csv.Dialect):
1122
1122
with self .assertRaises (csv .Error ) as cm :
1123
1123
mydialect ()
1124
1124
self .assertEqual (str (cm .exception ),
1125
- '"quotechar" must be a 1-character string' )
1125
+ '"quotechar" must be a unicode character or None, '
1126
+ 'not a string of length 0' )
1126
1127
1127
1128
mydialect .quotechar = "''"
1128
1129
with self .assertRaises (csv .Error ) as cm :
1129
1130
mydialect ()
1130
1131
self .assertEqual (str (cm .exception ),
1131
- '"quotechar" must be a 1-character string' )
1132
+ '"quotechar" must be a unicode character or None, '
1133
+ 'not a string of length 2' )
1132
1134
1133
1135
mydialect .quotechar = 4
1134
1136
with self .assertRaises (csv .Error ) as cm :
1135
1137
mydialect ()
1136
1138
self .assertEqual (str (cm .exception ),
1137
- '"quotechar" must be string or None, not int' )
1139
+ '"quotechar" must be a unicode character or None, '
1140
+ 'not int' )
1138
1141
1139
1142
def test_delimiter (self ):
1140
1143
class mydialect (csv .Dialect ):
@@ -1151,31 +1154,32 @@ class mydialect(csv.Dialect):
1151
1154
with self .assertRaises (csv .Error ) as cm :
1152
1155
mydialect ()
1153
1156
self .assertEqual (str (cm .exception ),
1154
- '"delimiter" must be a 1-character string' )
1157
+ '"delimiter" must be a unicode character, '
1158
+ 'not a string of length 3' )
1155
1159
1156
1160
mydialect .delimiter = ""
1157
1161
with self .assertRaises (csv .Error ) as cm :
1158
1162
mydialect ()
1159
1163
self .assertEqual (str (cm .exception ),
1160
- '"delimiter" must be a 1- character string' )
1164
+ '"delimiter" must be a unicode character, not a string of length 0 ' )
1161
1165
1162
1166
mydialect .delimiter = b","
1163
1167
with self .assertRaises (csv .Error ) as cm :
1164
1168
mydialect ()
1165
1169
self .assertEqual (str (cm .exception ),
1166
- '"delimiter" must be string , not bytes' )
1170
+ '"delimiter" must be a unicode character , not bytes' )
1167
1171
1168
1172
mydialect .delimiter = 4
1169
1173
with self .assertRaises (csv .Error ) as cm :
1170
1174
mydialect ()
1171
1175
self .assertEqual (str (cm .exception ),
1172
- '"delimiter" must be string , not int' )
1176
+ '"delimiter" must be a unicode character , not int' )
1173
1177
1174
1178
mydialect .delimiter = None
1175
1179
with self .assertRaises (csv .Error ) as cm :
1176
1180
mydialect ()
1177
1181
self .assertEqual (str (cm .exception ),
1178
- '"delimiter" must be string , not NoneType' )
1182
+ '"delimiter" must be a unicode character , not NoneType' )
1179
1183
1180
1184
def test_escapechar (self ):
1181
1185
class mydialect (csv .Dialect ):
@@ -1189,20 +1193,32 @@ class mydialect(csv.Dialect):
1189
1193
self .assertEqual (d .escapechar , "\\ " )
1190
1194
1191
1195
mydialect .escapechar = ""
1192
- with self .assertRaisesRegex (csv .Error , '"escapechar" must be a 1-character string' ) :
1196
+ with self .assertRaises (csv .Error ) as cm :
1193
1197
mydialect ()
1198
+ self .assertEqual (str (cm .exception ),
1199
+ '"escapechar" must be a unicode character or None, '
1200
+ 'not a string of length 0' )
1194
1201
1195
1202
mydialect .escapechar = "**"
1196
- with self .assertRaisesRegex (csv .Error , '"escapechar" must be a 1-character string' ) :
1203
+ with self .assertRaises (csv .Error ) as cm :
1197
1204
mydialect ()
1205
+ self .assertEqual (str (cm .exception ),
1206
+ '"escapechar" must be a unicode character or None, '
1207
+ 'not a string of length 2' )
1198
1208
1199
1209
mydialect .escapechar = b"*"
1200
- with self .assertRaisesRegex (csv .Error , '"escapechar" must be string or None, not bytes' ) :
1210
+ with self .assertRaises (csv .Error ) as cm :
1201
1211
mydialect ()
1212
+ self .assertEqual (str (cm .exception ),
1213
+ '"escapechar" must be a unicode character or None, '
1214
+ 'not bytes' )
1202
1215
1203
1216
mydialect .escapechar = 4
1204
- with self .assertRaisesRegex (csv .Error , '"escapechar" must be string or None, not int' ) :
1217
+ with self .assertRaises (csv .Error ) as cm :
1205
1218
mydialect ()
1219
+ self .assertEqual (str (cm .exception ),
1220
+ '"escapechar" must be a unicode character or None, '
1221
+ 'not int' )
1206
1222
1207
1223
def test_lineterminator (self ):
1208
1224
class mydialect (csv .Dialect ):
@@ -1223,7 +1239,13 @@ class mydialect(csv.Dialect):
1223
1239
with self .assertRaises (csv .Error ) as cm :
1224
1240
mydialect ()
1225
1241
self .assertEqual (str (cm .exception ),
1226
- '"lineterminator" must be a string' )
1242
+ '"lineterminator" must be a string, not int' )
1243
+
1244
+ mydialect .lineterminator = None
1245
+ with self .assertRaises (csv .Error ) as cm :
1246
+ mydialect ()
1247
+ self .assertEqual (str (cm .exception ),
1248
+ '"lineterminator" must be a string, not NoneType' )
1227
1249
1228
1250
def test_invalid_chars (self ):
1229
1251
def create_invalid (field_name , value , ** kwargs ):
0 commit comments