55from uuid import uuid4
66from common .block import Block
77from common .fragment import Fragment
8+ from common .utils import bytes_to_str
9+
10+
11+ # pylint: disable=missing-function-docstring
812
913
1014def _bytes_test_pattern (size ):
@@ -19,9 +23,6 @@ def _create_test_block(size):
1923
2024
2125def test_fragment_init ():
22- """
23- Test initialization of a Fragment.
24- """
2526 block = _create_test_block (100 )
2627 _fragment = Fragment (
2728 block = block ,
@@ -31,18 +32,7 @@ def test_fragment_init():
3132 )
3233
3334
34- def test_fragment_properties ():
35- """
36- Test Fragment properties.
37- """
38- pass
39-
40-
4135def test_fragment_allocate_full ():
42- """
43- Test Fragment allocation: requested bytes are fully available.
44- (This also covers all the @property methods.)
45- """
4636 block = _create_test_block (100 )
4737 fragment = Fragment .allocate (block , 10 )
4838 assert fragment .block == block
@@ -52,9 +42,6 @@ def test_fragment_allocate_full():
5242
5343
5444def test_fragment_allocate_partial ():
55- """
56- Test Fragment allocation: requested bytes are partially available.
57- """
5845 block = _create_test_block (5 )
5946 fragment = Fragment .allocate (block , 10 )
6047 assert fragment .block == block
@@ -64,13 +51,22 @@ def test_fragment_allocate_partial():
6451
6552
6653def test_fragment_allocate_none ():
67- """
68- Test Fragment allocation: requested bytes are not available.
69- """
7054 block = _create_test_block (5 )
7155 fragment = Fragment .allocate (block , 5 )
7256 assert fragment .block == block
7357 assert fragment .start == 0
7458 assert fragment .size == 5
7559 assert fragment .data == bytes .fromhex ("0001020304" )
7660 assert Fragment .allocate (block , 5 ) is None
61+
62+
63+ def test_fragment_to_mgmt ():
64+ block = _create_test_block (5 )
65+ fragment = Fragment .allocate (block , 5 )
66+ fragment_mgmt = fragment .to_mgmt ()
67+ assert fragment_mgmt == {
68+ "block_uuid" : str (block .uuid ),
69+ "start" : 0 ,
70+ "size" : 5 ,
71+ "data" : bytes_to_str (bytes .fromhex ("0001020304" )),
72+ }
0 commit comments