-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from qurit/8-optinal-fields
feat: make certain ds fields optional and test
- Loading branch information
Showing
5 changed files
with
63 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rt_utils.rtstruct import RTStruct | ||
import pytest | ||
import os | ||
from rt_utils import RTStructBuilder | ||
|
||
@pytest.fixture() | ||
def series_path() -> str: | ||
return get_and_test_series_path() | ||
|
||
@pytest.fixture() | ||
def new_rtstruct() -> RTStruct: | ||
path = get_and_test_series_path() | ||
rtstruct = RTStructBuilder.create_new(path) | ||
return rtstruct | ||
|
||
def get_and_test_series_path() -> str: | ||
series_path = os.path.join(os.path.dirname(__file__), 'mock_data/') | ||
assert os.path.exists(series_path) | ||
return series_path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from rt_utils import ds_helper, image_helper | ||
|
||
def test_correctly_acquire_optional_ds_field(series_path): | ||
series_data = image_helper.load_sorted_image_series(series_path) | ||
|
||
patient_age = series_data[0]['PatientAge'].value | ||
ds = ds_helper.create_rtstruct_dataset(series_data) | ||
|
||
assert ds.PatientAge == patient_age | ||
|
||
def test_ds_creation_without_patient_age(series_path): | ||
# Ensure only 1 file in series data so ds_helper uses the file for header reference | ||
series_data = image_helper.load_sorted_image_series(series_path) | ||
series_data = [series_data[0]] | ||
|
||
# Remove optional field | ||
original_age = series_data[0]['PatientAge'].value | ||
del series_data[0]['PatientAge'] | ||
with pytest.raises(Exception): | ||
access = series_data[0]['PatientAge'] | ||
|
||
ds = ds_helper.create_rtstruct_dataset(series_data) | ||
|
||
assert ds.PatientAge != original_age | ||
assert ds.PatientAge == '' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters