Skip to content

Commit

Permalink
Add serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zacikpa committed Jul 22, 2024
1 parent 18e876c commit 422ea78
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion python/tests/sanity_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Sanity tests for the libcpuid package."""

import os
import tempfile
import libcpuid
from libcpuid.info import CPUInfo
from libcpuid.info import CPUInfo, SystemInfo
from libcpuid.raw import CPURawData, CPURawDataArray


def test_cpu_name_in_vendor_list():
Expand All @@ -12,3 +15,32 @@ def test_cpu_name_in_vendor_list():
info = CPUInfo.from_current_cpu()
cpulist = libcpuid.get_cpu_list(info.vendor)
assert info.cpu_codename in cpulist


def test_serialization():
"""
Check that CPU data serialization and
deserialization does not raise any errors.
"""
with tempfile.TemporaryDirectory() as tmpdirname:
info_file = os.path.join(tmpdirname, "info.txt")
raw = CPURawData.from_current_cpu()
raw.serialize(info_file)
info = CPUInfo.from_raw(raw)
info_from_file = CPUInfo.from_raw(CPURawData.from_file(info_file))
assert info.features == info_from_file.features


def test_array_serialization():
"""
Check that CPU array data serialization and
deserialization does not raise any errors.
"""
with tempfile.TemporaryDirectory() as tmpdirname:
info_file = os.path.join(tmpdirname, "info.txt")
raw_array = CPURawDataArray.from_all_cpus()
raw_array.serialize(info_file)
info = SystemInfo.from_raw_array(raw_array)
info_from_file = SystemInfo.from_raw_array(CPURawDataArray.from_file(info_file))
assert len(info) == len(info_from_file)
assert info[0].features == info_from_file[0].features

0 comments on commit 422ea78

Please sign in to comment.