Skip to content

Commit e4f6e18

Browse files
committed
Refactor progress
1 parent d7fd9b4 commit e4f6e18

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

common/allocation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class Allocation:
2222
_fragments: list[Fragment]
2323

2424
def __init__(self, fragments: list[Fragment]):
25+
# Don't call this directly. Instead use one of the following:
26+
# Pool.allocate
27+
# Allocation.from_api
28+
# Allocation.from_enc_str
2529
self._fragments = fragments
2630

2731
@property

common/fragment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Fragment:
3030

3131
def __init__(self, block, start, size, data):
3232
# Don't call this directly. Instead use one of the following:
33-
# Block.allocate
33+
# Block.allocate_fragment
3434
# Fragment.from_api
3535
# Fragment.from_enc_str
3636
self._block = block

common/tests/test_allocation.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Unit tests for the Allocation class.
3+
"""
4+
5+
from uuid import uuid4
6+
from common.allocation import Allocation
7+
from common.block import Block
8+
from common.fragment import Fragment
9+
10+
11+
def _bytes_test_pattern(size):
12+
return bytes([i % 255 for i in range(size)])
13+
14+
15+
def _create_test_block(size):
16+
uuid = uuid4()
17+
data = _bytes_test_pattern(size)
18+
block = Block(uuid, data)
19+
return block
20+
21+
22+
def test_init():
23+
"""
24+
Initialize an allocation.
25+
"""
26+
block = _create_test_block(100)
27+
fragment = Fragment(
28+
block=block,
29+
start=0,
30+
size=10,
31+
data=bytes.fromhex("00010203040506070809"),
32+
)
33+
_allocation = Allocation(fragments=[fragment])

0 commit comments

Comments
 (0)