149 lines
4.0 KiB
Python
149 lines
4.0 KiB
Python
"""Test configuration and fixtures"""
|
|
|
|
import pytest
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
|
|
from src.cad_automation.config import Config
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
"""Create a temporary directory for tests"""
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
yield Path(temp_dir)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_config():
|
|
"""Create a mock configuration for tests"""
|
|
config = Config()
|
|
# Override with test-specific settings
|
|
config._config = {
|
|
"oda_converter": {
|
|
"path": "C:\\Test\\OdaFileConverter.exe",
|
|
"version": "ACAD2018",
|
|
"output_format": "DXF",
|
|
"recurse": False,
|
|
"audit": True
|
|
},
|
|
"paths": {
|
|
"input_dir": "test_input",
|
|
"output_dir": "test_output",
|
|
"template_dir": "test_templates",
|
|
"test_data_dir": "test_data"
|
|
},
|
|
"templates": {
|
|
"bom_template": "test_bom_template.json"
|
|
},
|
|
"table_settings": {
|
|
"row_height": 8.0,
|
|
"header_height": 16.0,
|
|
"default_color": 7,
|
|
"default_layer": "TEST_TABLE"
|
|
}
|
|
}
|
|
return config
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_dxf_doc():
|
|
"""Create a mock DXF document"""
|
|
mock_doc = Mock()
|
|
mock_msp = Mock()
|
|
mock_doc.modelspace.return_value = mock_msp
|
|
|
|
# Mock some entities
|
|
mock_line = Mock()
|
|
mock_line.dxftype.return_value = "LINE"
|
|
mock_line.dxf.start = Mock()
|
|
mock_line.dxf.start.x = 0
|
|
mock_line.dxf.start.y = 0
|
|
mock_line.dxf.end = Mock()
|
|
mock_line.dxf.end.x = 10
|
|
mock_line.dxf.end.y = 10
|
|
mock_line.dxf.color = 1
|
|
|
|
mock_msp.query.return_value = [mock_line]
|
|
mock_msp.add_line.return_value = mock_line
|
|
mock_msp.add_text.return_value = Mock()
|
|
|
|
return mock_doc
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_bom_data():
|
|
"""Sample BOM data for testing"""
|
|
return [
|
|
{
|
|
"件 号": {"main": "1"},
|
|
"图号或标准号": {"main": "JB/T XXXX"},
|
|
"名 称": {
|
|
"chinese_name": "测试零件-A",
|
|
"english_name": "TEST PART-A",
|
|
"specification": "M20x150"
|
|
},
|
|
"数量": {"main": "4"},
|
|
"材 料": {"main": "Q345R"},
|
|
"备 注": {"main": "测试备注"}
|
|
},
|
|
{
|
|
"件 号": {"main": "2"},
|
|
"图号或标准号": {"main": "GB/T YYYY"},
|
|
"名 称": {
|
|
"chinese_name": "测试零件-B",
|
|
"english_name": "TEST PART-B",
|
|
"specification": "DN200"
|
|
},
|
|
"数量": {"main": "2"},
|
|
"材 料": {"main": "S30408"},
|
|
"备 注": {"main": ""}
|
|
}
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_template():
|
|
"""Sample template data for testing"""
|
|
return {
|
|
"template_name": "测试物料清单",
|
|
"row_height": 8.0,
|
|
"header_height": 16.0,
|
|
"column_boundaries": [0, 40, 120, 160, 200, 240],
|
|
"header_definition": {
|
|
"lines": [
|
|
{"start": [0, 0], "end": [240, 0]},
|
|
{"start": [0, 16], "end": [240, 16]}
|
|
],
|
|
"texts": [
|
|
{
|
|
"content": "件号",
|
|
"relative_pos": [5, 5],
|
|
"alignment": "MIDDLE_CENTER",
|
|
"height": 3.5,
|
|
"style": "Standard",
|
|
"layer": "TABLE",
|
|
"color": 7
|
|
}
|
|
]
|
|
},
|
|
"column_definitions": [
|
|
{
|
|
"name": "件 号",
|
|
"relative_x_start": 0,
|
|
"text_definitions": [
|
|
{
|
|
"data_key": "main",
|
|
"relative_pos": [5, 2],
|
|
"alignment": "MIDDLE_CENTER",
|
|
"height": 3.5,
|
|
"style": "Standard",
|
|
"layer": "TABLE",
|
|
"color": 7
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|