@@ -397,7 +397,8 @@ def test_get_files_with_length(self) -> None:
397
397
name_bytes = b"\xe8 \xaf \xad \xe8 \xa8 \x80 \xe5 \xa4 \x84 \xe7 \x90 \x86 "
398
398
name_unicode = name_bytes .decode ()
399
399
tdef = TorrentDef (metainfo = {b"info" : {b"files" : [{b"path.utf-8" : [name_bytes ], b"length" : 123 },
400
- {b"path.utf-8" : [b"file.txt" ], b"length" : 456 }]}})
400
+ {b"path.utf-8" : [b"file.txt" ], b"length" : 456 }],
401
+ b"name" : b"" , b"piece length" : 128 , b"pieces" : b"\x00 " * 100 }})
401
402
402
403
self .assertEqual ([(Path (name_unicode ), 123 ), (Path ('file.txt' ), 456 )], tdef .get_files_with_length ())
403
404
@@ -408,7 +409,8 @@ def test_get_files_with_length_valid_path_utf8(self) -> None:
408
409
name_bytes = b"\xe8 \xaf \xad \xe8 \xa8 \x80 \xe5 \xa4 \x84 \xe7 \x90 \x86 "
409
410
name_unicode = name_bytes .decode ()
410
411
tdef = TorrentDef (metainfo = {b"info" : {b"files" : [{b"path" : [name_bytes ], b"length" : 123 },
411
- {b"path" : [b"file.txt" ], b"length" : 456 }]}})
412
+ {b"path" : [b"file.txt" ], b"length" : 456 }],
413
+ b"name" : b"" , b"piece length" : 128 , b"pieces" : b"\x00 " * 100 }})
412
414
413
415
self .assertEqual ([(Path (name_unicode ), 123 ), (Path ('file.txt' ), 456 )], tdef .get_files_with_length ())
414
416
@@ -418,7 +420,8 @@ def test_get_files_with_length_illegal_path(self) -> None:
418
420
"""
419
421
name_bytes = b"\xe8 \xaf \xad \xe8 \xa8 \x80 \xe5 \xa4 \x84 \xe7 \x90 \x86 "
420
422
tdef = TorrentDef (metainfo = {b"info" : {b"files" : [{b"path" : [b"test\xff " + name_bytes ], b"length" : 123 },
421
- {b"path" : [b"file.txt" ], b"length" : 456 }]}})
423
+ {b"path" : [b"file.txt" ], b"length" : 456 }],
424
+ b"name" : b"" , b"piece length" : 128 , b"pieces" : b"\x00 " * 100 }})
422
425
423
426
self .assertEqual ([(Path ("test?????????????" ), 123 ), (Path ("file.txt" ), 456 )], tdef .get_files_with_length ())
424
427
@@ -428,10 +431,27 @@ def test_get_files_with_length_illegal_path_utf8(self) -> None:
428
431
"""
429
432
name_bytes = b"\xe8 \xaf \xad \xe8 \xa8 \x80 \xe5 \xa4 \x84 \xe7 \x90 \x86 "
430
433
tdef = TorrentDef (metainfo = {b"info" : {b"files" : [{b"path.utf-8" : [b"test\xff " + name_bytes ], b"length" : 123 },
431
- {b"path" : [b"file.txt" ], b"length" : 456 }]}})
434
+ {b"path" : [b"file.txt" ], b"length" : 456 }],
435
+ b"name" : b"" , b"piece length" : 128 , b"pieces" : b"\x00 " * 100 }})
432
436
433
437
self .assertEqual ([(Path ("file.txt" ), 456 )], tdef .get_files_with_length ())
434
438
439
+ def test_get_files_with_length_ignore_padding (self ) -> None :
440
+ """
441
+ Test if get_files_with_length ignores padding files.
442
+ """
443
+ tdef = TorrentDef (metainfo = {
444
+ b"info" : {
445
+ b"name" : b"torrent name" ,
446
+ b"files" : [{b"path" : [b".pad" ], b"length" : 123 , b"attr" : b"p" },
447
+ {b"path" : [b"file.txt" ], b"length" : 456 }],
448
+ b"piece length" : 128 ,
449
+ b"pieces" : b"\x00 " * 100
450
+ }
451
+ })
452
+
453
+ self .assertEqual ([(Path ('file.txt' ), 456 )], tdef .get_files_with_length ())
454
+
435
455
def test_load_torrent_info (self ) -> None :
436
456
"""
437
457
Test if load_torrent_info() loads the torrent info.
0 commit comments