diff --git a/processing_engine/metadata_processor/metadata_processor.py b/processing_engine/metadata_processor/metadata_processor.py index 1624f85..aaecef4 100644 --- a/processing_engine/metadata_processor/metadata_processor.py +++ b/processing_engine/metadata_processor/metadata_processor.py @@ -70,8 +70,13 @@ def get_modality_table(modality,table_name): def _datasetProcess(ds,root_directory,filename,logger): records = [] - modality = ds.Modality - modality_config = get_modality_config_for_file(modality) + modality = None + modality_config = None + try: + modality = ds.Modality + modality_config = get_modality_config_for_file(modality) + except Exception: + pass if modality_config is None: logger.error({ "message":f'modality {modality} not found', diff --git a/tests/test_destination_writer.py b/tests/test_destination_writer.py index 8c4be8b..40cf5b7 100644 --- a/tests/test_destination_writer.py +++ b/tests/test_destination_writer.py @@ -94,6 +94,7 @@ def test_write_file_copies_files_to_destination(monkeypatch): mock_get_dest = Mock(return_value="/dest/file.dcm") monkeypatch.setattr("destination_writer.destination_writer.shutil.copyfile", mock_copyfile) monkeypatch.setattr("destination_writer.destination_writer.get_destination_location", mock_get_dest) + monkeypatch.setattr("destination_writer.destination_writer.os.makedirs", Mock()) config = {"destination": {"files": {"directory": "/dest"}}} logger = Mock() @@ -114,6 +115,7 @@ def test_write_file_skips_copy_when_destination_is_none(monkeypatch): "destination_writer.destination_writer.get_destination_location", Mock(return_value=None), ) + monkeypatch.setattr("destination_writer.destination_writer.os.makedirs", Mock()) config = {"destination": {"files": {"directory": "/dest"}}} logger = Mock() diff --git a/tests/test_source_extractor.py b/tests/test_source_extractor.py index 39ab0a5..2f52613 100644 --- a/tests/test_source_extractor.py +++ b/tests/test_source_extractor.py @@ -2,6 +2,7 @@ import pytest import pydicom from pydicom.dataset import Dataset, FileMetaDataset +import py7zr from source_extractor.source_extractor import _build_identifier, _cmove, source_extractor @@ -202,22 +203,25 @@ def test_cmove_handle_store_saves_file_to_output_dir(mock_ae, tmp_path): def test_cmove_received_count_reflects_stored_files(mock_ae, tmp_path): - _, ae_inst, _, _ = mock_ae + _, ae_inst, assoc, _ = mock_ae logger = Mock() - _cmove_defaults(tmp_path, logger) - _, handler = ae_inst.start_server.call_args.kwargs["evt_handlers"][0] + def fake_send_c_move(*args, **kwargs): + _, handler = ae_inst.start_server.call_args.kwargs["evt_handlers"][0] + for uid in ("1.1.1", "1.1.2", "1.1.3"): + ds = Dataset() + ds.SOPInstanceUID = uid + ev = Mock() + ev.dataset = ds + ev.file_meta = FileMetaDataset() + with patch.object(ds, "save_as"): + handler(ev) + return iter([(_status(0x0000), None)]) - for uid in ("1.1.1", "1.1.2", "1.1.3"): - ds = Dataset() - ds.SOPInstanceUID = uid - ev = Mock() - ev.dataset = ds - ev.file_meta = FileMetaDataset() - with patch.object(ds, "save_as"): - handler(ev) + assoc.send_c_move.side_effect = fake_send_c_move + + _cmove_defaults(tmp_path, logger) - print(logger.info.call_args.args[0]) assert logger.info.call_args.args[0]["recieved"] == 3 @@ -312,8 +316,10 @@ def test_filesystem_source_with_include_archives_counts_archive_files(tmp_path): """With include_archives, .zip and .7z files are included in the reported count.""" (tmp_path / "scan.dcm").touch() (tmp_path / "backup.zip").touch() - (tmp_path / "compressed.7z").touch() + # (tmp_path / "compressed.7z").touch() (tmp_path / "readme.txt").touch() + with py7zr.SevenZipFile( (tmp_path / "compressed.7z"), 'w') as z: + z.write(tmp_path / "scan.dcm") logger = Mock() config = {"sources": {"images": { "type": "filesystem",