mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Update get_pretty_snapshot_diff(...) to handle None-snapshots.
This commit is contained in:
parent
bac2a757e8
commit
8ff49109a8
@ -64,7 +64,7 @@ class MemorySnapshot:
|
|||||||
return cls(process_ram, vram, malloc_info)
|
return cls(process_ram, vram, malloc_info)
|
||||||
|
|
||||||
|
|
||||||
def get_pretty_snapshot_diff(snapshot_1: MemorySnapshot, snapshot_2: MemorySnapshot) -> str:
|
def get_pretty_snapshot_diff(snapshot_1: Optional[MemorySnapshot], snapshot_2: Optional[MemorySnapshot]) -> str:
|
||||||
"""Get a pretty string describing the difference between two `MemorySnapshot`s."""
|
"""Get a pretty string describing the difference between two `MemorySnapshot`s."""
|
||||||
|
|
||||||
def get_msg_line(prefix: str, val1: int, val2: int):
|
def get_msg_line(prefix: str, val1: int, val2: int):
|
||||||
@ -73,6 +73,9 @@ def get_pretty_snapshot_diff(snapshot_1: MemorySnapshot, snapshot_2: MemorySnaps
|
|||||||
|
|
||||||
msg = ""
|
msg = ""
|
||||||
|
|
||||||
|
if snapshot_1 is None or snapshot_2 is None:
|
||||||
|
return msg
|
||||||
|
|
||||||
msg += get_msg_line("Process RAM", snapshot_1.process_ram, snapshot_2.process_ram)
|
msg += get_msg_line("Process RAM", snapshot_1.process_ram, snapshot_2.process_ram)
|
||||||
|
|
||||||
if snapshot_1.malloc_info is not None and snapshot_2.malloc_info is not None:
|
if snapshot_1.malloc_info is not None and snapshot_2.malloc_info is not None:
|
||||||
|
@ -17,6 +17,7 @@ snapshots = [
|
|||||||
MemorySnapshot(process_ram=1.0, vram=2.0, malloc_info=None),
|
MemorySnapshot(process_ram=1.0, vram=2.0, malloc_info=None),
|
||||||
MemorySnapshot(process_ram=1.0, vram=None, malloc_info=Struct_mallinfo2()),
|
MemorySnapshot(process_ram=1.0, vram=None, malloc_info=Struct_mallinfo2()),
|
||||||
MemorySnapshot(process_ram=1.0, vram=None, malloc_info=None),
|
MemorySnapshot(process_ram=1.0, vram=None, malloc_info=None),
|
||||||
|
None,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -26,10 +27,12 @@ def test_get_pretty_snapshot_diff(snapshot_1, snapshot_2):
|
|||||||
"""Test that get_pretty_snapshot_diff() works with various combinations of missing MemorySnapshot fields."""
|
"""Test that get_pretty_snapshot_diff() works with various combinations of missing MemorySnapshot fields."""
|
||||||
msg = get_pretty_snapshot_diff(snapshot_1, snapshot_2)
|
msg = get_pretty_snapshot_diff(snapshot_1, snapshot_2)
|
||||||
|
|
||||||
expected_lines = 1
|
expected_lines = 0
|
||||||
if snapshot_1.vram is not None and snapshot_2.vram is not None:
|
if snapshot_1 is not None and snapshot_2 is not None:
|
||||||
expected_lines += 1
|
expected_lines += 1
|
||||||
if snapshot_1.malloc_info is not None and snapshot_2.malloc_info is not None:
|
if snapshot_1.vram is not None and snapshot_2.vram is not None:
|
||||||
expected_lines += 5
|
expected_lines += 1
|
||||||
|
if snapshot_1.malloc_info is not None and snapshot_2.malloc_info is not None:
|
||||||
|
expected_lines += 5
|
||||||
|
|
||||||
assert len(msg.splitlines()) == expected_lines
|
assert len(msg.splitlines()) == expected_lines
|
||||||
|
Loading…
Reference in New Issue
Block a user