Skip to content

Commit

Permalink
fix: add disk image data to string repr
Browse files Browse the repository at this point in the history
  • Loading branch information
swysocki committed Jul 25, 2022
1 parent 05a09fc commit 2d5b3ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions gpt_image/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def __repr__(self):
# so that we can create a single JSON document
partition_list = [json.loads(str(p)) for p in self.table.partitions.entries]
disk_dict = {
"path": str(self.image_path),
"image_size": self.size,
"sector_size": self.sector_size,
"primary_header": json.loads(str(self.table.primary_header)),
"backup_header": json.loads(str(self.table.secondary_header)),
"partitions": partition_list,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from gpt_image.partition import Partition

BYTE_DATA = b"\x01\x02\x03\x04"
DISK_SIZE = 2 * 1024 * 1024
OFFSET = 32
DISK_SIZE = 4 * 1024 * 1024 # 4 MB


@pytest.fixture
def new_image(tmp_path):
image_name = tmp_path / "test.img"
disk = Disk(image_name)
disk.create(DISK_SIZE * 2)
disk.create(DISK_SIZE)
part1 = Partition("partition1", 2 * 1024, Partition.LINUX_FILE_SYSTEM)
part2 = Partition("partition2", 3 * 1024, Partition.LINUX_FILE_SYSTEM)
disk.table.partitions.add(part1)
Expand All @@ -35,7 +34,7 @@ def test_disk_create(tmp_path):
def test_disk_open(new_image):
disk = Disk(new_image)
disk.open()
assert disk.size == DISK_SIZE * 2
assert disk.size == DISK_SIZE
assert disk.table.primary_header.backup is False
assert disk.table.secondary_header.backup is True
assert disk.table.primary_header.partition_entry_lba == 2
Expand All @@ -49,6 +48,8 @@ def test_disk_info(new_image):
disk.open()
disk_s = str(disk)
disk_d = json.loads(disk_s)
assert disk_d["path"] == str(new_image)
assert disk_d["image_size"] == DISK_SIZE
assert not disk_d["primary_header"]["backup"]
assert disk_d["backup_header"]["backup"]
assert disk_d["backup_header"]["header_size"] == 92
Expand Down

0 comments on commit 2d5b3ef

Please sign in to comment.