- Move test scripts to tests/ directory for better organization - Add improved YOLOv5 postprocessing with reference implementation - Update gitignore to exclude *.mflow files and include main.spec - Add debug capabilities and coordinate scaling improvements - Enhance multi-series support with proper validation - Add AGENTS.md documentation and example utilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
173 lines
6.7 KiB
Python
173 lines
6.7 KiB
Python
"""
|
|
Test Multi-Series Integration for Multidongle
|
|
|
|
Testing the integration of multi-series functionality into the existing Multidongle class
|
|
following TDD principles.
|
|
"""
|
|
|
|
import unittest
|
|
import sys
|
|
import os
|
|
from unittest.mock import Mock, patch, MagicMock
|
|
|
|
# Add project root (core/functions) to path
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
parent_dir = os.path.dirname(current_dir)
|
|
sys.path.insert(0, os.path.join(parent_dir, 'core', 'functions'))
|
|
|
|
from Multidongle import MultiDongle
|
|
|
|
class TestMultiSeriesMultidongle(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
"""Set up test fixtures"""
|
|
self.multi_series_config = {
|
|
"KL520": {
|
|
"port_ids": [28, 32],
|
|
"model_path": "/path/to/kl520_model.nef",
|
|
"firmware_paths": {
|
|
"scpu": "/path/to/kl520_scpu.bin",
|
|
"ncpu": "/path/to/kl520_ncpu.bin"
|
|
}
|
|
},
|
|
"KL720": {
|
|
"port_ids": [40, 44],
|
|
"model_path": "/path/to/kl720_model.nef",
|
|
"firmware_paths": {
|
|
"scpu": "/path/to/kl720_scpu.bin",
|
|
"ncpu": "/path/to/kl720_ncpu.bin"
|
|
}
|
|
}
|
|
}
|
|
|
|
def test_multi_series_initialization_should_fail(self):
|
|
"""
|
|
Test that multi-series initialization accepts config and sets up series groups
|
|
This should FAIL initially since the functionality doesn't exist yet
|
|
"""
|
|
# This should work but will fail initially
|
|
try:
|
|
multidongle = MultiDongle(multi_series_config=self.multi_series_config)
|
|
|
|
# Should have series groups configured
|
|
self.assertIsNotNone(multidongle.series_groups)
|
|
self.assertIn("KL520", multidongle.series_groups)
|
|
self.assertIn("KL720", multidongle.series_groups)
|
|
|
|
# Should have GOPS weights calculated
|
|
self.assertIsNotNone(multidongle.gops_weights)
|
|
self.assertIn("KL520", multidongle.gops_weights)
|
|
self.assertIn("KL720", multidongle.gops_weights)
|
|
|
|
# KL720 should have higher weight due to higher GOPS
|
|
self.assertGreater(multidongle.gops_weights["KL720"],
|
|
multidongle.gops_weights["KL520"])
|
|
|
|
self.fail("Multi-series initialization should not work yet - test should fail")
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
# Expected to fail at this stage
|
|
print(f"Expected failure: {e}")
|
|
self.assertTrue(True, "Multi-series initialization correctly fails (not implemented yet)")
|
|
|
|
def test_single_series_to_multi_series_conversion_should_fail(self):
|
|
"""
|
|
Test that single-series config gets converted to multi-series internally
|
|
This should FAIL initially
|
|
"""
|
|
try:
|
|
# Legacy single-series initialization
|
|
multidongle = MultiDongle(
|
|
port_id=[28, 32],
|
|
scpu_fw_path="/path/to/scpu.bin",
|
|
ncpu_fw_path="/path/to/ncpu.bin",
|
|
model_path="/path/to/model.nef",
|
|
upload_fw=True
|
|
)
|
|
|
|
# Should internally convert to multi-series format
|
|
self.assertIsNotNone(multidongle.series_groups)
|
|
self.assertEqual(len(multidongle.series_groups), 1)
|
|
|
|
# Should auto-detect series from device scan or use default
|
|
series_keys = list(multidongle.series_groups.keys())
|
|
self.assertEqual(len(series_keys), 1)
|
|
|
|
self.fail("Single to multi-series conversion should not work yet")
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
# Expected to fail at this stage
|
|
print(f"Expected failure: {e}")
|
|
self.assertTrue(True, "Single-series conversion correctly fails (not implemented yet)")
|
|
|
|
def test_load_balancing_should_fail(self):
|
|
"""
|
|
Test that load balancing works based on GOPS weights
|
|
This should FAIL initially
|
|
"""
|
|
try:
|
|
multidongle = MultiDongle(multi_series_config=self.multi_series_config)
|
|
|
|
# Should have load balancing method
|
|
optimal_series = multidongle._select_optimal_series()
|
|
self.assertIsNotNone(optimal_series)
|
|
self.assertIn(optimal_series, ["KL520", "KL720"])
|
|
|
|
self.fail("Load balancing should not work yet")
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
# Expected to fail at this stage
|
|
print(f"Expected failure: {e}")
|
|
self.assertTrue(True, "Load balancing correctly fails (not implemented yet)")
|
|
|
|
def test_backward_compatibility_should_work(self):
|
|
"""
|
|
Test that existing single-series API still works
|
|
This should PASS (existing functionality)
|
|
"""
|
|
# This should still work with existing code
|
|
try:
|
|
multidongle = MultiDongle(
|
|
port_id=[28, 32],
|
|
scpu_fw_path="/path/to/scpu.bin",
|
|
ncpu_fw_path="/path/to/ncpu.bin",
|
|
model_path="/path/to/model.nef"
|
|
)
|
|
|
|
# Basic properties should still exist
|
|
self.assertIsNotNone(multidongle.port_id)
|
|
self.assertEqual(multidongle.port_id, [28, 32])
|
|
self.assertEqual(multidongle.model_path, "/path/to/model.nef")
|
|
|
|
print("Backward compatibility test passed")
|
|
|
|
except Exception as e:
|
|
self.fail(f"Backward compatibility should work: {e}")
|
|
|
|
def test_multi_series_device_grouping_should_fail(self):
|
|
"""
|
|
Test that devices are properly grouped by series
|
|
This should FAIL initially
|
|
"""
|
|
try:
|
|
multidongle = MultiDongle(multi_series_config=self.multi_series_config)
|
|
multidongle.initialize()
|
|
|
|
# Should have device groups for each series
|
|
self.assertIsNotNone(multidongle.device_groups)
|
|
self.assertEqual(len(multidongle.device_groups), 2)
|
|
|
|
# Each series should have its device group
|
|
for series_name, config in self.multi_series_config.items():
|
|
self.assertIn(series_name, multidongle.device_groups)
|
|
|
|
self.fail("Multi-series device grouping should not work yet")
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
# Expected to fail
|
|
print(f"Expected failure: {e}")
|
|
self.assertTrue(True, "Device grouping correctly fails (not implemented yet)")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|