forked from yaqwsx/PcbDraw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_kicad9_compatibility.py
More file actions
89 lines (71 loc) · 2.98 KB
/
test_kicad9_compatibility.py
File metadata and controls
89 lines (71 loc) · 2.98 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
Test script for KiCad 9 SVG path parsing compatibility.
This script tests the updated SvgPathItem class with various KiCad 9 path formats
to ensure they are parsed correctly without throwing exceptions.
"""
import sys
import os
# Add the current directory to Python path to import pcbdraw modules
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
try:
from pcbdraw.plot import SvgPathItem
print("✓ Successfully imported SvgPathItem from pcbdraw.plot")
except ImportError as e:
print(f"✗ Failed to import SvgPathItem: {e}")
print("Please ensure you're running this script from the PcbDraw directory")
sys.exit(1)
def test_svg_path_parsing():
"""Test various SVG path formats that KiCad 9 might generate."""
test_cases = [
# KiCad 9 problematic formats
("136.00000", "Single coordinate"),
("136.00000 50.00000", "Two coordinates (point)"),
("136.00000 50.00000 140.00000 54.00000", "Four coordinates (line)"),
("100.5 200.75", "Decimal coordinates"),
("0 0", "Origin point"),
# Standard SVG formats (should still work)
("M 136 50 L 140 54", "Standard move-line"),
("M 100 100", "Simple move"),
("M 100 100 L 200 200", "Move and line"),
("M 50 50 A 25 25 0 1 0 100 50", "Arc command"),
# Edge cases
("M 0 0 L 0 0", "Zero-length line"),
("M -100 -50", "Negative coordinates"),
]
passed = 0
failed = 0
print("\n" + "="*70)
print("Testing SVG Path Parsing with KiCad 9 Compatibility")
print("="*70)
for path, description in test_cases:
print(f"\nTest: {description}")
print(f"Path: '{path}'")
try:
item = SvgPathItem(path)
print(f"✓ SUCCESS: start={item.start}, end={item.end}, type='{item.type}'")
if hasattr(item, 'args') and item.args:
print(f" args={item.args}")
passed += 1
except Exception as e:
print(f"✗ FAILED: {type(e).__name__}: {e}")
failed += 1
print("\n" + "="*70)
print(f"Results: {passed} passed, {failed} failed")
print("="*70)
if failed == 0:
print("🎉 All tests passed! KiCad 9 SVG path parsing should work correctly.")
return True
else:
print("⚠️ Some tests failed. There may still be issues with certain path formats.")
return False
if __name__ == "__main__":
print("KiCad 9 SVG Path Parsing Test Suite")
print("This script tests the compatibility fixes for SVG path parsing.")
success = test_svg_path_parsing()
if success:
print("\n✓ The updated SvgPathItem class should resolve the KiCad 9 compatibility issues.")
print(" You can now update your PcbDraw installation and retry your command.")
else:
print("\n✗ There are still issues that need to be addressed.")
sys.exit(0 if success else 1)