feature: add mypy type checking for better type consistency

This commit is contained in:
James Hilliard
2025-09-26 11:24:38 -06:00
committed by GitHub
parent cd52d3aeaf
commit 1f4054bf38
100 changed files with 2813 additions and 2203 deletions

View File

@@ -7,7 +7,7 @@ class TestFanConfig(unittest.TestCase):
def test_serialize_and_deserialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of fan config",
msg="Test serialization and deserialization of fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -17,7 +17,7 @@ class TestFanConfig(unittest.TestCase):
def test_bosminer_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of bosminer fan config",
msg="Test serialization and deserialization of bosminer fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -27,7 +27,7 @@ class TestFanConfig(unittest.TestCase):
def test_am_modern_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of antminer modern fan config",
msg="Test serialization and deserialization of antminer modern fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -37,7 +37,7 @@ class TestFanConfig(unittest.TestCase):
def test_epic_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of epic fan config",
msg="Test serialization and deserialization of epic fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -47,7 +47,7 @@ class TestFanConfig(unittest.TestCase):
def test_vnish_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of vnish fan config",
msg="Test serialization and deserialization of vnish fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -57,7 +57,7 @@ class TestFanConfig(unittest.TestCase):
def test_auradine_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of auradine fan config",
msg="Test serialization and deserialization of auradine fan config",
fan_mode=fan_mode,
):
conf = fan_mode()
@@ -67,7 +67,7 @@ class TestFanConfig(unittest.TestCase):
def test_boser_deserialize_and_serialize(self):
for fan_mode in FanModeConfig:
with self.subTest(
msg=f"Test serialization and deserialization of boser fan config",
msg="Test serialization and deserialization of boser fan config",
fan_mode=fan_mode,
):
conf = fan_mode()

View File

@@ -29,7 +29,7 @@ class MinersTest(unittest.TestCase):
for miner_type in MINER_CLASSES.keys():
for miner_model in MINER_CLASSES[miner_type].keys():
with self.subTest(
msg=f"Test creation of miner",
msg="Test creation of miner",
miner_type=miner_type,
miner_model=miner_model,
):
@@ -42,7 +42,7 @@ class MinersTest(unittest.TestCase):
if miner_model is None:
continue
with self.subTest(
msg=f"Test miner has defined hashboards",
msg="Test miner has defined hashboards",
miner_type=miner_type,
miner_model=miner_model,
):
@@ -56,7 +56,7 @@ class MinersTest(unittest.TestCase):
if miner_model is None:
continue
with self.subTest(
msg=f"Test miner has defined fans",
msg="Test miner has defined fans",
miner_type=miner_type,
miner_model=miner_model,
):
@@ -70,7 +70,7 @@ class MinersTest(unittest.TestCase):
if miner_model is None:
continue
with self.subTest(
msg=f"Test miner has defined algo",
msg="Test miner has defined algo",
miner_type=miner_type,
miner_model=miner_model,
):
@@ -105,7 +105,7 @@ class MinersTest(unittest.TestCase):
for miner_type in MINER_CLASSES.keys():
for miner_model in MINER_CLASSES[miner_type].keys():
with self.subTest(
msg=f"Data map key check",
msg="Data map key check",
miner_type=miner_type,
miner_model=miner_model,
):

View File

@@ -50,23 +50,39 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
).encode("utf-8")
def get_success_value(self, command: str):
if self.api_str == "BTMiner" and command == "status":
return json.dumps(
{
"STATUS": "S",
"When": 1706287567,
"Code": 131,
"Msg": {
"mineroff": "false",
"mineroff_reason": "",
"mineroff_time": "",
"FirmwareVersion": "20230911.12.Rel",
"power_mode": "",
"hash_percent": "",
},
"Description": "",
}
).encode("utf-8")
if self.api_str == "BTMiner":
if command == "status":
return json.dumps(
{
"STATUS": "S",
"When": 1706287567,
"Code": 131,
"Msg": {
"mineroff": "false",
"mineroff_reason": "",
"mineroff_time": "",
"FirmwareVersion": "20230911.12.Rel",
"power_mode": "",
"hash_percent": "",
},
"Description": "",
}
).encode("utf-8")
elif command == "get_token":
# Return proper token response for BTMiner matching real miner format
return json.dumps(
{
"STATUS": "S",
"When": int(time.time()),
"Code": 134,
"Msg": {
"time": str(int(time.time())),
"salt": "D6w5gVOb", # Valid salt format (alphanumeric only)
"newsalt": "zU4gvW30", # Valid salt format (alphanumeric only)
},
"Description": "",
}
).encode("utf-8")
return json.dumps(
{
"STATUS": [
@@ -119,7 +135,33 @@ class TestAPIBase(unittest.IsolatedAsyncioTestCase):
command=command,
):
api_func = getattr(self.api, command)
mock_send_bytes.return_value = self.get_success_value(command)
# For BTMiner, we need to handle multiple calls for privileged commands
# Use a list to track calls and return different values
if self.api_str == "BTMiner":
def btminer_side_effect(data):
# Parse the command from the sent data
try:
# data is already bytes
if isinstance(data, bytes):
cmd_str = data.decode("utf-8")
cmd_data = json.loads(cmd_str)
if "cmd" in cmd_data:
sent_cmd = cmd_data["cmd"]
if sent_cmd == "get_token":
# Return proper token response
return self.get_success_value("get_token")
except Exception:
# If we can't parse it, it might be encrypted privileged command
pass
# Default return for the actual command
return self.get_success_value(command)
mock_send_bytes.side_effect = btminer_side_effect
else:
mock_send_bytes.return_value = self.get_success_value(command)
try:
await api_func()
except APIError: