-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_package.py
More file actions
39 lines (34 loc) · 1.8 KB
/
Copy pathtest_package.py
File metadata and controls
39 lines (34 loc) · 1.8 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
import pytest
from unittest.mock import patch, MagicMock
from pyaslreport.main import get_bids_metadata
# filepath: /home/ibrahim/MyPc/Projects/GSoC/ASL-Parameter-Generator/package/src/pyaslreport/test_main.py
def test_get_bids_metadata_success():
data = {"modality": "asl", "dicom_dir": "/fake/dir"}
fake_header = MagicMock()
fake_sequence = MagicMock()
fake_sequence.extract_bids_metadata.return_value = ("meta", "context")
with patch("pyaslreport.main.get_dicom_header", return_value=fake_header), \
patch("pyaslreport.main.get_sequence", return_value=fake_sequence):
result = get_bids_metadata(data)
assert result == ("meta", "context")
fake_sequence.extract_bids_metadata.assert_called_once()
def test_get_bids_metadata_no_dicom_dir():
data = {"modality": "asl"}
with pytest.raises(TypeError):
get_bids_metadata(data)
def test_get_bids_metadata_no_sequence():
data = {"modality": "asl", "dicom_dir": "/fake/dir"}
fake_header = MagicMock()
with patch("pyaslreport.main.get_dicom_header", return_value=fake_header), \
patch("pyaslreport.main.get_sequence", side_effect=ValueError("No ASL sequence class found that matches the DICOM header")):
with pytest.raises(ValueError) as exc:
get_bids_metadata(data)
assert "No ASL sequence class found" in str(exc.value)
def test_get_bids_metadata_invalid_modality():
data = {"modality": None, "dicom_dir": "/fake/dir"}
fake_header = MagicMock()
with patch("pyaslreport.main.get_dicom_header", return_value=fake_header), \
patch("pyaslreport.main.get_sequence", side_effect=ValueError("Unsupported modality: None")):
with pytest.raises(ValueError) as exc:
get_bids_metadata(data)
assert "Unsupported modality" in str(exc.value)