def test_write_with_creation_date(generated_singlefile_torrent, tmp_path): f = tmp_path / 'a.torrent' now = int(time.time()) generated_singlefile_torrent.creation_date = now generated_singlefile_torrent.write(f) metainfo = bencode.decode(open(f, 'rb').read()) assert metainfo[b'creation date'] == now
def test_decode_recursion(depth): data = b'l' * depth + b'i0e' + b'e' * depth expected = list_nesting(0, depth) # Test that we don't have any nesting limit (many implementation uses # recursivity which blows up the stack.) with maximum_recursion(MIN_RECURSION): result = decode(data) with maximum_recursion(max(depth ** 2, MIN_RECURSION)): assert result == expected
#!/usr/bin/env python3 import flatbencode import furl import sys import time if len(sys.argv) != 2: print('usage: autotor.py torrent', file=sys.stderr) print(' prints tracker hostname', file=sys.stderr) sys.exit(1) time.sleep(.2) bencoded_torrent = open(sys.argv[1], 'rb').read() torrent = flatbencode.decode(bencoded_torrent) host = furl.furl(torrent[b'announce']).host print(host)
def test_invalid_values(data): with pytest.raises(DecodingError): decode(data)
def test_order_is_preserved(): assert list(decode(b'd3:cow3:moo4:spam4:eggse').keys()) == [b'cow', b'spam']
def test_decode_simple(data, expected): assert decode(data) == expected
def test_prop_trailing_data_is_invalid(obj, extra): with pytest.raises(DecodingError): assert decode(encode(obj) + extra)
def test_prop_decode_encode_is_a_noop(obj): assert decode(encode(obj)) == obj