22
33import libipld
44import pytest
5+ from pytest_benchmark .fixture import BenchmarkFixture
56
67from conftest import load_car_fixture
78
8- _DID = os .environ .get ('CAR_REPO_DID' , 'did:plc:w4es6sfh43zlht3bgrzi5qzq' ) # default is public bot in bsky.app
9- _REPO_CAR_PATH = os .path .join (os .path .dirname (__file__ ), '..' , 'data' , 'repo.car' )
9+ _DID = os .environ .get (
10+ "CAR_REPO_DID" , "did:plc:w4es6sfh43zlht3bgrzi5qzq"
11+ ) # default is public bot in bsky.app
12+ _REPO_CAR_PATH = os .path .join (os .path .dirname (__file__ ), ".." , "data" , "repo.car" )
1013
1114
12- @pytest .fixture (scope = ' session' )
15+ @pytest .fixture (scope = " session" )
1316def car () -> bytes :
1417 return load_car_fixture (_DID , _REPO_CAR_PATH )
1518
1619
17- def test_decode_car (benchmark , car ) -> None :
20+ def test_decode_car (benchmark : BenchmarkFixture , car : bytes ) -> None :
1821 header , blocks = benchmark (libipld .decode_car , car )
1922
20- assert 1 == header [' version' ]
21- assert isinstance (header [' roots' ], list )
22- assert 1 == len (header [' roots' ])
23+ assert 1 == header [" version" ]
24+ assert isinstance (header [" roots" ], list )
25+ assert 1 == len (header [" roots" ])
2326
2427 assert isinstance (blocks , dict )
2528 assert all (isinstance (k , bytes ) for k in blocks .keys ())
@@ -30,71 +33,71 @@ def test_decode_car(benchmark, car) -> None:
3033
3134def test_decode_car_invalid_header_len () -> None :
3235 with pytest .raises (ValueError ) as exc_info :
33- libipld .decode_car (b'' )
36+ libipld .decode_car (b"" )
3437
35- assert ' Invalid uvarint' in str (exc_info .value )
38+ assert " Invalid uvarint" in str (exc_info .value )
3639
3740
3841def test_decode_car_invalid_header_type () -> None :
3942 with pytest .raises (TypeError ) as exc_info :
40- header_len = bytes .fromhex ('33' ) # 3
41- header_obj = libipld .encode_dag_cbor (' strInsteadOfObj' )
43+ header_len = bytes .fromhex ("33" ) # 3
44+ header_obj = libipld .encode_dag_cbor (" strInsteadOfObj" )
4245 libipld .decode_car (header_len + header_obj )
4346
4447 assert "cannot be converted to 'PyDict'" in str (exc_info .value )
4548
4649
4750def test_decode_car_invalid_header_version_key () -> None :
4851 with pytest .raises (ValueError ) as exc_info :
49- header_len = bytes .fromhex ('33' ) # 3
50- header_obj = libipld .encode_dag_cbor ({' blabla' : ' blabla' })
52+ header_len = bytes .fromhex ("33" ) # 3
53+ header_obj = libipld .encode_dag_cbor ({" blabla" : " blabla" })
5154 libipld .decode_car (header_len + header_obj )
5255
53- assert ' Version is None' in str (exc_info .value )
56+ assert " Version is None" in str (exc_info .value )
5457
5558
5659def test_decode_car_invalid_header_version_value () -> None :
5760 with pytest .raises (ValueError ) as exc_info :
58- header_len = bytes .fromhex ('33' ) # 3
59- header_obj = libipld .encode_dag_cbor ({' version' : 2 })
61+ header_len = bytes .fromhex ("33" ) # 3
62+ header_obj = libipld .encode_dag_cbor ({" version" : 2 })
6063 libipld .decode_car (header_len + header_obj )
6164
62- assert ' Version must be 1' in str (exc_info .value )
65+ assert " Version must be 1" in str (exc_info .value )
6366
6467
6568def test_decode_car_invalid_header_roots_key () -> None :
6669 with pytest .raises (ValueError ) as exc_info :
67- header_len = bytes .fromhex ('33' ) # 3
68- header_obj = libipld .encode_dag_cbor ({' version' : 1 })
70+ header_len = bytes .fromhex ("33" ) # 3
71+ header_obj = libipld .encode_dag_cbor ({" version" : 1 })
6972 libipld .decode_car (header_len + header_obj )
7073
71- assert ' Roots is None' in str (exc_info .value )
74+ assert " Roots is None" in str (exc_info .value )
7275
7376
7477def test_decode_car_invalid_header_roots_value_type () -> None :
7578 with pytest .raises (TypeError ) as exc_info :
76- header_len = bytes .fromhex ('33' ) # 3
77- header_obj = libipld .encode_dag_cbor ({' version' : 1 , ' roots' : 123 })
79+ header_len = bytes .fromhex ("33" ) # 3
80+ header_obj = libipld .encode_dag_cbor ({" version" : 1 , " roots" : 123 })
7881 libipld .decode_car (header_len + header_obj )
7982
8083 assert "cannot be converted to 'PyList'" in str (exc_info .value )
8184
8285
8386def test_decode_car_invalid_header_roots_value_empty_list () -> None :
8487 with pytest .raises (ValueError ) as exc_info :
85- header_len = bytes .fromhex ('33' ) # 3
86- header_obj = libipld .encode_dag_cbor ({' version' : 1 , ' roots' : []})
88+ header_len = bytes .fromhex ("33" ) # 3
89+ header_obj = libipld .encode_dag_cbor ({" version" : 1 , " roots" : []})
8790 libipld .decode_car (header_len + header_obj )
8891
89- assert ' Roots is empty' in str (exc_info .value )
92+ assert " Roots is empty" in str (exc_info .value )
9093
9194
9295def test_decode_car_invalid_block_cid () -> None :
9396 with pytest .raises (ValueError ) as exc_info :
94- header_len = bytes .fromhex ('33' ) # 3
95- header_obj = libipld .encode_dag_cbor ({' version' : 1 , ' roots' : [' blabla' ]})
96- block1 = bytes .fromhex ('33' ) + b' invalidSid'
97+ header_len = bytes .fromhex ("33" ) # 3
98+ header_obj = libipld .encode_dag_cbor ({" version" : 1 , " roots" : [" blabla" ]})
99+ block1 = bytes .fromhex ("33" ) + b" invalidSid"
97100
98101 libipld .decode_car (header_len + header_obj + block1 )
99102
100- assert ' Failed to read CID of block' in str (exc_info .value )
103+ assert " Failed to read CID of block" in str (exc_info .value )
0 commit comments