Skip to content

Commit e24ce34

Browse files
committed
Refactor progress
1 parent fb89bcf commit e24ce34

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

common/tests/test_allocation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,29 @@ def test_to_enc_str():
137137
allocation = pool.allocate(8, purpose="test")
138138
enc_str = allocation.to_enc_str()
139139
assert enc_str == f"{blocks[0].uuid}:0:5,{blocks[1].uuid}:0:3"
140+
141+
142+
def test_from_enc_str_success_one_fragment():
143+
"""
144+
Create an allocation from a valid encoded string with one fragment.
145+
"""
146+
# pylint: disable=protected-access
147+
pool, blocks = create_test_pool_and_blocks([10, 10])
148+
fragment_1_enc_str = f"{blocks[0].uuid}:0:10"
149+
fragment_2_enc_str = f"{blocks[1].uuid}:0:3"
150+
allocation_enc_str = f"{fragment_1_enc_str},{fragment_2_enc_str}"
151+
allocation = Allocation.from_enc_str(allocation_enc_str, pool)
152+
assert len(allocation.fragments) == 2
153+
fragment_1 = allocation.fragments[0]
154+
fragment_2 = allocation.fragments[1]
155+
assert fragment_1.block == blocks[0]
156+
assert fragment_1.start == 0
157+
assert fragment_1.size == 10
158+
assert fragment_1.data == bytes.fromhex("00010203040506070809")
159+
assert fragment_2.block == blocks[1]
160+
assert fragment_2.start == 0
161+
assert fragment_2.size == 3
162+
assert fragment_2.data == bytes.fromhex("000102")
163+
assert pool.nr_used_bytes == 13
164+
assert blocks[0]._data == bytes.fromhex("00000000000000000000")
165+
assert blocks[1]._data == bytes.fromhex("00000003040506070809")

0 commit comments

Comments
 (0)