object size measurement function, related to #7
This commit is contained in:
57
tests/test_system.py
Normal file
57
tests/test_system.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import dataclasses as dc
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from dopt_basics import system
|
||||
|
||||
|
||||
@dc.dataclass()
|
||||
class _TData:
|
||||
dic: dict[str, str]
|
||||
dic2: dict[str, dict[str, int]]
|
||||
lst: list[int]
|
||||
tup: tuple[str, ...]
|
||||
string: str
|
||||
id_: int
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def TData() -> _TData:
|
||||
return _TData(
|
||||
{"test": "test", "test2": "test"},
|
||||
{"test": {"prop1": 3, "prop2": 500}},
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
("test", "test", "test", "test", "test", "test", "test"),
|
||||
"This is one test string",
|
||||
1234,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def TData_real_size(TData) -> int:
|
||||
return 1435
|
||||
|
||||
|
||||
def test_obj_size(TData, TData_real_size):
|
||||
ret = system.obj_size(TData)
|
||||
|
||||
assert ret == TData_real_size
|
||||
|
||||
|
||||
def test_obj_size_kb(TData, TData_real_size):
|
||||
ret = system.obj_size(TData, unit="kb")
|
||||
|
||||
assert ret == pytest.approx(TData_real_size / 1024)
|
||||
|
||||
|
||||
def test_obj_size_mb(TData, TData_real_size):
|
||||
ret = system.obj_size(TData, unit="mb")
|
||||
|
||||
assert ret == pytest.approx(TData_real_size / 1024**2)
|
||||
|
||||
|
||||
def test_obj_size_gb(TData, TData_real_size):
|
||||
ret = system.obj_size(TData, unit="gb")
|
||||
|
||||
assert ret == pytest.approx(TData_real_size / 1024**3)
|
||||
Reference in New Issue
Block a user