22
33import libipld
44import pytest
5- from pytest_benchmark .fixture import BenchmarkFixture
65
76from conftest import load_car_fixture
87
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" )
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' )
1310
1411
15- @pytest .fixture (scope = " session" )
12+ @pytest .fixture (scope = ' session' )
1613def car () -> bytes :
1714 return load_car_fixture (_DID , _REPO_CAR_PATH )
1815
1916
20- def test_decode_car (benchmark : BenchmarkFixture , car : bytes ) -> None :
17+ def test_decode_car (benchmark , car ) -> None :
2118 header , blocks = benchmark (libipld .decode_car , car )
2219
23- assert 1 == header [" version" ]
24- assert isinstance (header [" roots" ], list )
25- assert 1 == len (header [" roots" ])
20+ assert 1 == header [' version' ]
21+ assert isinstance (header [' roots' ], list )
22+ assert 1 == len (header [' roots' ])
2623
2724 assert isinstance (blocks , dict )
2825 assert all (isinstance (k , bytes ) for k in blocks .keys ())
@@ -33,71 +30,71 @@ def test_decode_car(benchmark: BenchmarkFixture, car: bytes) -> None:
3330
3431def test_decode_car_invalid_header_len () -> None :
3532 with pytest .raises (ValueError ) as exc_info :
36- libipld .decode_car (b"" )
33+ libipld .decode_car (b'' )
3734
38- assert " Invalid uvarint" in str (exc_info .value )
35+ assert ' Invalid uvarint' in str (exc_info .value )
3936
4037
4138def test_decode_car_invalid_header_type () -> None :
4239 with pytest .raises (TypeError ) as exc_info :
43- header_len = bytes .fromhex ("33" ) # 3
44- header_obj = libipld .encode_dag_cbor (" strInsteadOfObj" )
40+ header_len = bytes .fromhex ('33' ) # 3
41+ header_obj = libipld .encode_dag_cbor (' strInsteadOfObj' )
4542 libipld .decode_car (header_len + header_obj )
4643
4744 assert "cannot be converted to 'PyDict'" in str (exc_info .value )
4845
4946
5047def test_decode_car_invalid_header_version_key () -> None :
5148 with pytest .raises (ValueError ) as exc_info :
52- header_len = bytes .fromhex ("33" ) # 3
53- header_obj = libipld .encode_dag_cbor ({" blabla" : " blabla" })
49+ header_len = bytes .fromhex ('33' ) # 3
50+ header_obj = libipld .encode_dag_cbor ({' blabla' : ' blabla' })
5451 libipld .decode_car (header_len + header_obj )
5552
56- assert " Version is None" in str (exc_info .value )
53+ assert ' Version is None' in str (exc_info .value )
5754
5855
5956def test_decode_car_invalid_header_version_value () -> None :
6057 with pytest .raises (ValueError ) as exc_info :
61- header_len = bytes .fromhex ("33" ) # 3
62- header_obj = libipld .encode_dag_cbor ({" version" : 2 })
58+ header_len = bytes .fromhex ('33' ) # 3
59+ header_obj = libipld .encode_dag_cbor ({' version' : 2 })
6360 libipld .decode_car (header_len + header_obj )
6461
65- assert " Version must be 1" in str (exc_info .value )
62+ assert ' Version must be 1' in str (exc_info .value )
6663
6764
6865def test_decode_car_invalid_header_roots_key () -> None :
6966 with pytest .raises (ValueError ) as exc_info :
70- header_len = bytes .fromhex ("33" ) # 3
71- header_obj = libipld .encode_dag_cbor ({" version" : 1 })
67+ header_len = bytes .fromhex ('33' ) # 3
68+ header_obj = libipld .encode_dag_cbor ({' version' : 1 })
7269 libipld .decode_car (header_len + header_obj )
7370
74- assert " Roots is None" in str (exc_info .value )
71+ assert ' Roots is None' in str (exc_info .value )
7572
7673
7774def test_decode_car_invalid_header_roots_value_type () -> None :
7875 with pytest .raises (TypeError ) as exc_info :
79- header_len = bytes .fromhex ("33" ) # 3
80- header_obj = libipld .encode_dag_cbor ({" version" : 1 , " roots" : 123 })
76+ header_len = bytes .fromhex ('33' ) # 3
77+ header_obj = libipld .encode_dag_cbor ({' version' : 1 , ' roots' : 123 })
8178 libipld .decode_car (header_len + header_obj )
8279
8380 assert "cannot be converted to 'PyList'" in str (exc_info .value )
8481
8582
8683def test_decode_car_invalid_header_roots_value_empty_list () -> None :
8784 with pytest .raises (ValueError ) as exc_info :
88- header_len = bytes .fromhex ("33" ) # 3
89- header_obj = libipld .encode_dag_cbor ({" version" : 1 , " roots" : []})
85+ header_len = bytes .fromhex ('33' ) # 3
86+ header_obj = libipld .encode_dag_cbor ({' version' : 1 , ' roots' : []})
9087 libipld .decode_car (header_len + header_obj )
9188
92- assert " Roots is empty" in str (exc_info .value )
89+ assert ' Roots is empty' in str (exc_info .value )
9390
9491
9592def test_decode_car_invalid_block_cid () -> None :
9693 with pytest .raises (ValueError ) as exc_info :
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"
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'
10097
10198 libipld .decode_car (header_len + header_obj + block1 )
10299
103- assert " Failed to read CID of block" in str (exc_info .value )
100+ assert ' Failed to read CID of block' in str (exc_info .value )
0 commit comments