-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathtest_utils.py
More file actions
66 lines (52 loc) · 1.97 KB
/
test_utils.py
File metadata and controls
66 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##
# Copyright (C) 2026 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
##
import os
import sys
import unittest
from ctypes import c_int32
# Add the source directory to Python path so we can import pyzes
script_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.path.join(script_dir, "..", "..", "source")
source_dir = os.path.abspath(source_dir)
if source_dir not in sys.path:
sys.path.insert(0, source_dir)
class TestUtilsInfrastructure(unittest.TestCase):
"""Test utility and infrastructure classes"""
def setUp(self):
import pyzes
self.pyzes = pyzes
def test_GivenPrintableStructureWhenConvertedToStringThenProvidesFormattedOutput(
self,
):
# Test _PrintableStructure string formatting functionality
temp_state = self.pyzes.zes_temp_config_t()
temp_state.enableCritical = True
temp_state.threshold1.threshold = 75.0
temp_state.threshold2.threshold = 80.0
# Test string representation functionality
str_repr = str(temp_state)
self.assertIsInstance(str_repr, str)
self.assertIn("zes_temp_config_t", str_repr)
self.assertIn("enableCritical", str_repr)
self.assertIn("threshold1", str_repr)
def test_GivenPrintableStructureWithDefaultFormattingWhenConvertedToStringThenUsesDefaultFormat(
self,
):
# Test _PrintableStructure with <default> format case
# Create a custom structure class with <default> formatting
class TestStructure(self.pyzes._PrintableStructure):
_fields_ = [("testField", c_int32)]
_fmt_ = {
"<default>": "default_%d"
} # This will trigger default format usage
test_struct = TestStructure()
test_struct.testField = 42
str_repr = str(test_struct)
self.assertIn("default_42", str_repr) # Tests <default> format usage
self.assertIn("TestStructure", str_repr)
if __name__ == "__main__":
unittest.main()