fix: accept layout-based PCB projects without optional icdb path

This commit is contained in:
阿白叔 committed 2026-11-02 21:19:57 +08:00
1 parent 797a79c30e
commit dd1fcea7e2
2 files changed
+63

No files matched your search

+5
View File
@@ -100,6 +100,11 @@ def source_project(source, top_level_block=''):
for path in (source, pcb.parent/'pcb.prj'):
if not path.is_file():
raise ValueError('工程缺少 PCB 工程配置。')
# Healthy Expedition PCB projects can use Layout/LayoutDB.lyt without
# declaring an independent iCDBDir. The schematic DB stays mandatory;
# an explicitly declared PCB DB must still pass every reference check.
if path != source and not re.search(r'^KEY iCDBDir\b', _project_text(path), re.M):
continue
db = reference(path, 'iCDBDir')
if not (db/'icdb.dat').is_file():
raise ValueError('工程缺少原理图/PCB 数据库。')
+58
View File
@@ -0,0 +1,58 @@
"""Real EE7.9.5 PRJ shape: PCB pcb.prj may use LayoutDB without iCDBDir."""
import pytest
from cbb_refresh_verify.management import source_project, engineering_identity
@pytest.fixture
def healthy_source(tmp_path):
(tmp_path/'database').mkdir()
(tmp_path/'database/icdb.dat').write_bytes(b'schematic database')
(tmp_path/'PCB/Layout').mkdir(parents=True)
(tmp_path/'PCB/Layout/LayoutDB.lyt').write_bytes(b'layout database')
source = tmp_path/'IP101GR.prj'
source.write_text('KEY RootBlock "IP101GR"\nKEY FlowType "DX"\n'
'KEY iCDBDir ".\\database"\nKEY PCBDesignPath "PCB\\IP101GR.pcb"\n', encoding='utf-8')
(tmp_path/'PCB/IP101GR.pcb').write_text('KEY ProjectFile "..\\IP101GR.prj"\n', encoding='utf-8')
(tmp_path/'PCB/pcb.prj').write_text('SECTION Project\nKEY CentralLibrary "old.lmc"\nENDSECTION\n', encoding='utf-8')
return source
def test_layout_based_pcb_without_independent_icdb_directory_is_complete(healthy_source):
source, pcb, top = source_project(healthy_source)
assert source == healthy_source
assert pcb == healthy_source.parent/'PCB/IP101GR.pcb'
assert top == 'IP101GR'
assert engineering_identity(source)['top_level_block'] == 'IP101GR'
@pytest.mark.parametrize('missing', ['database/icdb.dat', 'PCB/Layout/LayoutDB.lyt', 'PCB/pcb.prj'])
def test_optional_pcb_icdb_does_not_relax_required_engineering_files(healthy_source, missing):
(healthy_source.parent/missing).unlink()
with pytest.raises(ValueError):
source_project(healthy_source)
def test_main_schematic_icdb_declaration_remains_required(healthy_source):
text = healthy_source.read_text(encoding='utf-8').replace('KEY iCDBDir ".\\database"\n', '')
healthy_source.write_text(text, encoding='utf-8')
with pytest.raises(ValueError, match='iCDBDir'):
source_project(healthy_source)
@pytest.mark.parametrize('declared', [
'KEY iCDBDir "missing"\n',
'KEY iCDBDir "..\\..\\outside"\n',
'KEY iCDBDir "C:\\external"\n',
'KEY iCDBDir ""\n',
'KEY iCDBDir "..\\database"\nKEY iCDBDir "..\\database"\n',
])
def test_explicit_pcb_icdb_reference_must_be_unique_contained_and_exist(healthy_source, declared):
(healthy_source.parent/'PCB/pcb.prj').write_text(declared, encoding='utf-8')
with pytest.raises(ValueError):
source_project(healthy_source)
def test_valid_explicit_pcb_icdb_directory_remains_supported(healthy_source):
(healthy_source.parent/'PCB/pcb.prj').write_text('KEY iCDBDir "..\\database"\n', encoding='utf-8')
assert source_project(healthy_source)[0] == healthy_source