Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_to_string_msh_field_v27(self):
for v in ('2.7', '2.8', '2.8.1', '2.8.2'):
m = Message('OML_O33', version=v)
msh = m.msh
self.assertEqual(msh.msh_1.to_er7(), '|')
self.assertEqual(msh.msh_2.to_er7(), '^~\\&#')
msh_1 = Field('MSH_1')
msh_2 = Field('MSH_2')
self.assertRaises(IndexError, msh_1.to_er7)
self.assertRaises(IndexError, msh_2.to_er7)
# name with base datatype
m = Message('RSP_K21')
m.pid.pid_39.cwe_1 = ST(cmp_str)
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# value with base datatype
m = Message('RSP_K21')
m.pid.pid_39.cwe_1.value = ST(cmp_str)
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# complex datatype
complex_cmp_str = 'xxx&yyy&zzz'
# name
f = Field('PID_4')
f.cx_10 = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
# value
f = Field('PID_4')
f.cx_10.value = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
def test_create_varies_datatype_field(self):
f = Field('PID_1', datatype='varies')
self.assertEqual(f.datatype, 'varies')
def test_to_string_msh_field_v27(self):
for v in ('2.7', '2.8', '2.8.1', '2.8.2'):
m = Message('OML_O33', version=v)
msh = m.msh
self.assertEqual(msh.msh_1.to_er7(), '|')
self.assertEqual(msh.msh_2.to_er7(), '^~\\&#')
msh_1 = Field('MSH_1')
msh_2 = Field('MSH_2')
self.assertRaises(IndexError, msh_1.to_er7)
self.assertRaises(IndexError, msh_2.to_er7)
def test_to_string_msh_field(self):
m = Message('OML_O33')
msh = m.msh
self.assertEqual(msh.msh_1.to_er7(), '|')
self.assertEqual(msh.msh_2.to_er7(), '^~\\&')
msh_1 = Field('MSH_1')
msh_2 = Field('MSH_2')
self.assertRaises(IndexError, msh_1.to_er7)
self.assertRaises(IndexError, msh_2.to_er7)
def test_override_field_datatype_strict(self):
f = Field('pid_3', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
f.datatype = 'HD'
self.assertRaises(OperationNotAllowed, Field, 'pid_3', datatype='HD',
validation_level=VALIDATION_LEVEL.STRICT)
# in this case we are assigning the official datatype to the Field, thus no exception should be raised
b = Field('pid_3', 'CX', validation_level=VALIDATION_LEVEL.STRICT)
self.assertEqual(b.datatype, 'CX')
f = Field('pid_3')
f.datatype = 'HD'
self.assertEqual(f.datatype, 'HD')
f = Field('pid_3', datatype='HD')
self.assertEqual(f.datatype, 'HD')
# it raises an exception because the field already has some children
def test_assign_wrong_component_to_known_position(self):
f1 = Field('pid_10', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(ChildNotValid):
f1.ce_1 = Component('CX_1')
f2 = Field('pid_3')
with self.assertRaises(ChildNotValid):
f2.cx_1 = Component('HD_1')
f2.cx_1 = Component('CX_1')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.qip_1 = Component('CX_1')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.qip_1 = Component('CX_1')
def test_field_wgith_three_part_name_bug_39(self):
"""
Tests that fields with three part name are handled correctly. See issue #39 on github
"""
f = Field('MSH_9', version='2.3')
f.value = 'SIU^S12'
self.assertEqual(f.cm_msg_1.value, 'SIU')
self.assertEqual(f.cm_msg_2.value, 'S12')
def test_create_empty_field(self):
f = Field()
self.assertEqual(f.classname, 'Field')
self.assertRaises(OperationNotAllowed, Field, validation_level=VALIDATION_LEVEL.STRICT)
>>> print(unknown.to_er7())
NUCLEAR^NELDA^W
"""
version = _get_version(version)
encoding_chars = _get_encoding_chars(encoding_chars, version)
validation_level = _get_validation_level(validation_level)
try:
field = Field(name, version=version, validation_level=validation_level, reference=reference)
except InvalidName:
if force_varies:
reference = ('leaf', None, 'varies', None, None, -1)
field = Field(name, version=version, validation_level=validation_level, reference=reference)
else:
field = Field(version=version, validation_level=validation_level, reference=reference)
if name in ('MSH_1', 'MSH_2'):
s = SubComponent(datatype='ST', value=text, validation_level=validation_level, version=version)
c = Component(datatype='ST', validation_level=validation_level, version=version)
c.add(s)
field.add(c)
else:
children = parse_components(text, field.datatype, version, encoding_chars, validation_level,
field.structure_by_name)
if Validator.is_tolerant(validation_level) and is_base_datatype(field.datatype, version) and \
len(children) > 1:
field.datatype = None
field.children = children
return field