@@ -247,6 +247,29 @@ def test_resize(self):
247
247
# CRASHES resize(NULL, 0, False)
248
248
# CRASHES resize(NULL, 3, False)
249
249
250
+ def test_join (self ):
251
+ """Test PyBytes_Join()"""
252
+ bytes_join = _testcapi .bytes_join
253
+
254
+ self .assertEqual (bytes_join (b'' , []), b'' )
255
+ self .assertEqual (bytes_join (b'sep' , []), b'' )
256
+
257
+ self .assertEqual (bytes_join (b'' , [b'a' , b'b' , b'c' ]), b'abc' )
258
+ self .assertEqual (bytes_join (b'-' , [b'a' , b'b' , b'c' ]), b'a-b-c' )
259
+ self .assertEqual (bytes_join (b' - ' , [b'a' , b'b' , b'c' ]), b'a - b - c' )
260
+
261
+ # invalid 'sep' argument type
262
+ with self .assertRaises (TypeError ):
263
+ bytes_join ('unicode' , [])
264
+ with self .assertRaises (TypeError ):
265
+ bytes_join (123 , [])
266
+
267
+ # invalid 'iterable' argument type
268
+ with self .assertRaises (TypeError ):
269
+ bytes_join (b'' , [b'bytes' , 'unicode' ])
270
+ with self .assertRaises (TypeError ):
271
+ bytes_join (b'' , [b'bytes' , 123 ])
272
+
250
273
251
274
if __name__ == "__main__" :
252
275
unittest .main ()
0 commit comments