@@ -29,3 +29,48 @@ def test_fragment_init():
2929 size = 10 ,
3030 data = bytes .fromhex ("00010203040506070809" ),
3131 )
32+
33+
34+ def test_fragment_properties ():
35+ """
36+ Test Fragment properties.
37+ """
38+ pass
39+
40+
41+ def test_fragment_allocate_full ():
42+ """
43+ Test Fragment allocation: requested bytes are fully available.
44+ (This also covers all the @property methods.)
45+ """
46+ block = _create_test_block (100 )
47+ fragment = Fragment .allocate (block , 10 )
48+ assert fragment .block == block
49+ assert fragment .start == 0
50+ assert fragment .size == 10
51+ assert fragment .data == bytes .fromhex ("00010203040506070809" )
52+
53+
54+ def test_fragment_allocate_partial ():
55+ """
56+ Test Fragment allocation: requested bytes are partially available.
57+ """
58+ block = _create_test_block (5 )
59+ fragment = Fragment .allocate (block , 10 )
60+ assert fragment .block == block
61+ assert fragment .start == 0
62+ assert fragment .size == 5
63+ assert fragment .data == bytes .fromhex ("0001020304" )
64+
65+
66+ def test_fragment_allocate_none ():
67+ """
68+ Test Fragment allocation: requested bytes are not available.
69+ """
70+ block = _create_test_block (5 )
71+ fragment = Fragment .allocate (block , 5 )
72+ assert fragment .block == block
73+ assert fragment .start == 0
74+ assert fragment .size == 5
75+ assert fragment .data == bytes .fromhex ("0001020304" )
76+ assert Fragment .allocate (block , 5 ) is None
0 commit comments