2
2
3
3
import libipld
4
4
import pytest
5
- from pytest_benchmark .fixture import BenchmarkFixture
6
5
7
6
from conftest import load_car_fixture
8
7
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' )
13
10
14
11
15
- @pytest .fixture (scope = " session" )
12
+ @pytest .fixture (scope = ' session' )
16
13
def car () -> bytes :
17
14
return load_car_fixture (_DID , _REPO_CAR_PATH )
18
15
19
16
20
- def test_decode_car (benchmark : BenchmarkFixture , car : bytes ) -> None :
17
+ def test_decode_car (benchmark , car ) -> None :
21
18
header , blocks = benchmark (libipld .decode_car , car )
22
19
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' ])
26
23
27
24
assert isinstance (blocks , dict )
28
25
assert all (isinstance (k , bytes ) for k in blocks .keys ())
@@ -33,71 +30,71 @@ def test_decode_car(benchmark: BenchmarkFixture, car: bytes) -> None:
33
30
34
31
def test_decode_car_invalid_header_len () -> None :
35
32
with pytest .raises (ValueError ) as exc_info :
36
- libipld .decode_car (b"" )
33
+ libipld .decode_car (b'' )
37
34
38
- assert " Invalid uvarint" in str (exc_info .value )
35
+ assert ' Invalid uvarint' in str (exc_info .value )
39
36
40
37
41
38
def test_decode_car_invalid_header_type () -> None :
42
39
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' )
45
42
libipld .decode_car (header_len + header_obj )
46
43
47
44
assert "cannot be converted to 'PyDict'" in str (exc_info .value )
48
45
49
46
50
47
def test_decode_car_invalid_header_version_key () -> None :
51
48
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' })
54
51
libipld .decode_car (header_len + header_obj )
55
52
56
- assert " Version is None" in str (exc_info .value )
53
+ assert ' Version is None' in str (exc_info .value )
57
54
58
55
59
56
def test_decode_car_invalid_header_version_value () -> None :
60
57
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 })
63
60
libipld .decode_car (header_len + header_obj )
64
61
65
- assert " Version must be 1" in str (exc_info .value )
62
+ assert ' Version must be 1' in str (exc_info .value )
66
63
67
64
68
65
def test_decode_car_invalid_header_roots_key () -> None :
69
66
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 })
72
69
libipld .decode_car (header_len + header_obj )
73
70
74
- assert " Roots is None" in str (exc_info .value )
71
+ assert ' Roots is None' in str (exc_info .value )
75
72
76
73
77
74
def test_decode_car_invalid_header_roots_value_type () -> None :
78
75
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 })
81
78
libipld .decode_car (header_len + header_obj )
82
79
83
80
assert "cannot be converted to 'PyList'" in str (exc_info .value )
84
81
85
82
86
83
def test_decode_car_invalid_header_roots_value_empty_list () -> None :
87
84
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' : []})
90
87
libipld .decode_car (header_len + header_obj )
91
88
92
- assert " Roots is empty" in str (exc_info .value )
89
+ assert ' Roots is empty' in str (exc_info .value )
93
90
94
91
95
92
def test_decode_car_invalid_block_cid () -> None :
96
93
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'
100
97
101
98
libipld .decode_car (header_len + header_obj + block1 )
102
99
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