def _test_modify(self, contents, vr, accessor): # Typed test element = odil.Element([contents[0]], vr) if isinstance(contents[0], bytearray): accessor(element).append(odil.Value.BinaryItem(contents[1])) else: accessor(element).append(contents[1]) self._test_sequences(accessor(element), contents[:2]) if isinstance(contents[0], bytearray): accessor(element)[0] = odil.Value.BinaryItem(contents[1]) else: accessor(element)[0] = contents[1] self._test_sequences(accessor(element), [contents[1], contents[1]]) # Polymorphic test element = odil.Element([contents[0]], vr) if isinstance(contents[0], bytearray): element.append(odil.Value.BinaryItem(contents[1])) else: element.append(contents[1]) self._test_sequences(element, contents[:2]) if isinstance(contents[0], bytearray): element[0] = odil.Value.BinaryItem(contents[1]) else: element[0] = contents[1] self._test_sequences(element, [contents[1], contents[1]])
def _test_equality(self, contents_1, contents_2, vr_1, vr_2): element_1 = odil.Element(contents_1, vr_1) element_2 = odil.Element(contents_1, vr_1) element_3 = odil.Element(contents_1, vr_2) element_4 = odil.Element(contents_2, vr_1) self.assertTrue(element_1 == element_2) self.assertFalse(element_1 == element_3) self.assertFalse(element_1 == element_4) self.assertFalse(element_1 != element_2) self.assertTrue(element_1 != element_3) self.assertTrue(element_1 != element_4)
def _test_item(self, tag, contents, type_check, accessor): data_set = odil.DataSet() data_set.add(tag, contents) self._test_sequences(accessor(data_set[tag]), contents) data_set[tag] = odil.Element(contents[:1], data_set.get_vr(tag)) self._test_sequences(accessor(data_set[tag]), contents[:1])
def _test_modify(self, contents, vr, accessor): value = odil.Element([contents[0]], vr) if isinstance(contents[0], bytearray): accessor(value).append( odil.Value.BinaryItem("".join(chr(x) for x in contents[1]))) else: accessor(value).append(contents[1]) self._test_sequences(accessor(value), contents)
def test_write_element(self): string_io = BytesIO() stream = odil.iostream(string_io) writer = odil.Writer(stream, odil.registry.ExplicitVRLittleEndian) writer.write_element(odil.Element(["Foo^Bar"], odil.VR.PN)) self.assertEqual(string_io.getvalue(), b"PN\x08\x00Foo^Bar ")
def test_read_element(self): string_io = BytesIO(b"PN\x08\x00Foo^Bar ") stream = odil.iostream(string_io) reader = odil.Reader(stream, odil.registry.ExplicitVRLittleEndian) self.assertEqual(reader.read_element(odil.registry.PatientName), odil.Element(["Foo^Bar"], odil.VR.PN))
def _test_clear(self, contents, vr, type_check): element = odil.Element(contents, vr) element.clear() self.assertTrue(type_check(element)) self.assertTrue(element.empty())
def _test_container(self, contents, vr, type_check, accessor): element = odil.Element(contents, vr) self._test_value(element, vr, contents, type_check, accessor)
def _test_implicit_container(self, empty_content, vr, type_check, accessor): element = odil.Element(vr) self._test_value(element, vr, empty_content, type_check, accessor)
def test_pickle_empty(self): self.assertEqual(pickle.loads(pickle.dumps(odil.Element(odil.VR.CS))), odil.Element(odil.VR.CS))
def _test_pickle(self, contents, vr, accessor): element = odil.Element(contents, vr) self.assertSequenceEqual(accessor(pickle.loads(pickle.dumps(element))), accessor(element)) self.assertEqual(pickle.loads(pickle.dumps(element)).vr, vr)