Skip to content

Commit 26929b0

Browse files
committed
Refactor progress
1 parent 644c56b commit 26929b0

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

common/block.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ def uuid(self):
4949
"""
5050
return self._block_uuid
5151

52+
@property
53+
def size(self):
54+
"""
55+
The size of the block in bytes.
56+
"""
57+
return self._size
58+
59+
@property
60+
def data(self):
61+
"""
62+
The data of the block.
63+
"""
64+
return self._data
65+
5266
@property
5367
def nr_used_bytes(self):
5468
"""

common/tests/test_block.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def test_properties():
4444
data = _bytes_test_pattern(size)
4545
block = Block(uuid, data)
4646
assert block.uuid == uuid
47+
assert block.size == size
48+
assert block.data == data
4749
assert block.nr_unused_bytes == size
4850

4951

common/tests/test_pool.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import List
77
from common.pool import Pool
88
from common.block import Block
9+
from common.utils import bytes_to_str
910

1011

1112
def _bytes_test_pattern(size):
@@ -52,3 +53,24 @@ def test_nr_unused_bytes():
5253
assert pool.nr_unused_bytes == 60
5354
_allocation = pool.allocate(10, purpose="test")
5455
assert pool.nr_unused_bytes == 50
56+
57+
58+
def test_to_mgmt():
59+
"""
60+
Get the management status.
61+
"""
62+
pool, blocks = _create_test_pool_and_block([10, 20])
63+
pool_mgmt = pool.to_mgmt()
64+
assert pool_mgmt == {
65+
"blocks": [
66+
{
67+
"uuid": str(block.uuid),
68+
"size": block.size,
69+
"data": bytes_to_str(block.data, truncate=True),
70+
"nr_used_bytes": block.nr_used_bytes,
71+
"nr_unused_bytes": block.nr_unused_bytes,
72+
}
73+
for block in blocks
74+
],
75+
"owner": str(pool.owner),
76+
}

0 commit comments

Comments
 (0)