From dd1fcea7e284176b56fcc650ce6bc4d537deeba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Mon, 2 Nov 2026 21:19:57 +0800 Subject: [PATCH] fix: accept layout-based PCB projects without optional icdb path --- src/cbb_refresh_verify/management.py | 5 +++ tests/test_management_source.py | 58 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/test_management_source.py diff --git a/src/cbb_refresh_verify/management.py b/src/cbb_refresh_verify/management.py index 1664344..8501d7b 100644 --- a/src/cbb_refresh_verify/management.py +++ b/src/cbb_refresh_verify/management.py @@ -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 数据库。') diff --git a/tests/test_management_source.py b/tests/test_management_source.py new file mode 100644 index 0000000..a024368 --- /dev/null +++ b/tests/test_management_source.py @@ -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