Commit 8b8c1c6e authored by Gabriel Couture's avatar Gabriel Couture

Adding DVH integration tests

parent 2bd38f63
Pipeline #188 passed with stage
in 9 seconds
{"structure_name": "", "doses": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], "dose_units": "GY", "volumes": [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], "volume_units": "CM3", "prescription_dose": -1}
\ No newline at end of file
# coding: utf-8
# author: gabriel couture
import json
import os
import unittest
from dvh.dvh import DVH
A_VALID_DOSE_UNIT = 'GY'
AN_INVALID_DOSE_UNIT = 'cGY'
A_VALID_VOLUME_UNIT = 'CM3'
AN_INVALID_VOLUME_UNIT = 'cc'
A_DOSE_ARRAY = list(range(16))
A_VOLUME_ARRAY = A_DOSE_ARRAY[::-1]
A_STRUCTURE_NAME = 'A_STRUCTURE_NAME'
A_PRESCRIPTION_DOSE = 15
A_DVH_DATA = {
'structure_name': A_STRUCTURE_NAME,
'doses': A_DOSE_ARRAY,
'dose_units': A_VALID_DOSE_UNIT,
'volumes': A_VOLUME_ARRAY,
'volume_units': A_VALID_VOLUME_UNIT,
'prescription_dose': A_PRESCRIPTION_DOSE
}
A_DVH_DATA_FILE_PATH = './tests/integration/data/A_DVH_DATA.json'
class TestDVH(unittest.TestCase):
def test_givenADVHAndAFilePath_whenWritingToJson_thenExpectedJsonFileWithDVHDataIsWrote(self):
a_file_path = './tests/integration/data/a_file_path.json'
a_dvh = DVH(
doses=A_DOSE_ARRAY,
volumes=A_VOLUME_ARRAY,
dose_unit=A_VALID_DOSE_UNIT,
volume_unit=A_VALID_VOLUME_UNIT,
)
a_dvh.write_to_json(a_file_path)
with open(A_DVH_DATA_FILE_PATH, 'r') as expected_json_file_handler:
with open(a_file_path, 'r') as result_json_file_handler:
self.assertEqual(
json.load(result_json_file_handler),
json.load(expected_json_file_handler)
)
os.remove(a_file_path)
def test_givenAFilePath_whenReadingDVHFromJsonFile_thenResultIsADVH(self):
result = DVH.read_from_json(A_DVH_DATA_FILE_PATH)
self.assertIsInstance(result, DVH)
......@@ -62,7 +62,7 @@ class TestDVH(unittest.TestCase):
@mock.patch('builtins.open')
@mock.patch('json.dump')
def test_givenADVH_whenWritingToJson_thenJsonDumpFunctionIsCalled(self, mock_open: mock.Mock, mock_json_dump: mock.Mock):
def test_givenADVHAndAFilePath_whenWritingToJson_thenJsonDumpFunctionIsCalled(self, mock_open: mock.Mock, mock_json_dump: mock.Mock):
a_file_path = 'a_file_path.json'
a_dvh = DVH(
doses=A_DOSE_ARRAY,
......@@ -78,7 +78,7 @@ class TestDVH(unittest.TestCase):
@mock.patch('builtins.open')
@mock.patch('json.load', lambda f: A_DVH_DATA)
def test_whenReadingDVHFromJsonFile_thenResultIsADVH(self, mock_open: mock.Mock):
def test_givenAFilePath_whenReadingDVHFromJsonFile_thenResultIsADVH(self, mock_open: mock.Mock):
a_file_path = 'a_file_path.json'
result = DVH.read_from_json(a_file_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment