コード例 #1
0
ファイル: EFLR.py プロジェクト: jimogaos/TotalDepth
 def __init__(self, ld: LogicalData):
     ld_index = ld.index
     component_descriptor = ComponentDescriptor(ld.read())
     if not component_descriptor.is_set_group:
         raise ExceptionEFLRSet(f'Component Descriptor does not represent a set but a {component_descriptor.type}.')
     self.type: bytes = RepCode.IDENT(ld)
     self.name: bytes = ComponentDescriptor.CHARACTERISTICS_AND_COMPONENT_FORMAT_SET_MAP['N'].global_default
     if component_descriptor.has_set_N:
         self.name = RepCode.IDENT(ld)
     self.logical_data_consumed = ld.index - ld_index
コード例 #2
0
ファイル: EFLR.py プロジェクト: jimogaos/TotalDepth
 def __init__(self,
              component_descriptor: ComponentDescriptor,
              ld: LogicalData,
              template_attribute: TemplateAttribute,
              ):
     super().__init__(component_descriptor)
     if self.component_descriptor.has_attribute_L:
         self.label = RepCode.IDENT(ld)
     else:
         self.label = template_attribute.label
     if self.component_descriptor.has_attribute_C:
         self.count = RepCode.UVARI(ld)
     else:
         self.count = template_attribute.count
     if self.component_descriptor.has_attribute_R:
         self.rep_code = RepCode.USHORT(ld)
     else:
         self.rep_code = template_attribute.rep_code
     if self.component_descriptor.has_attribute_U:
         self.units = RepCode.UNITS(ld)
     else:
         self.units = template_attribute.units
     if self.component_descriptor.has_attribute_V:
         self.value = [RepCode.code_read(self.rep_code, ld) for _i in range(self.count)]
     else:
         self.value = template_attribute.value
コード例 #3
0
def test_IDENT(ld, expected):
    result = RepCode.IDENT(ld)
    assert result == expected
    assert ld.remain == 0
コード例 #4
0
    # TODO: index != 0, index -ve. Also for other _len functions.
    result = RepCode.OBNAME_len(ld.bytes, 0)
    assert result == expected


def test_OBNAME_len_raises():
    ld = LogicalData(b'\x00' + b'\x01' + b'\x03')
    with pytest.raises(RepCode.ExceptionRepCode) as err:
        RepCode.OBNAME_len(ld.bytes, -1)
    assert err.value.args[0] == 'Index can not be negative.'


@pytest.mark.parametrize('ld, expected', ((
    LogicalData(b'\x0512345' + b'\x00' + b'\x01' + b'\x03ABC'),
    RepCode.ObjectReference(
        RepCode.IDENT(LogicalData(b'\x0512345')),
        RepCode.ObjectName(0, 1, b'ABC'),
    ),
), ))
def test_OBJREF(ld, expected):
    result = RepCode.OBJREF(ld)
    assert result == expected
    assert ld.remain == 0


@pytest.mark.parametrize('ld, expected', ((
    LogicalData(b'\x0512345' + b'\x00' + b'\x01' + b'\x03ABC'),
    "OBREF: O: b'12345' C: OBNAME: O: 0 C: 1 I: b'ABC'",
), ))
def test_OBJREF_str(ld, expected):
    result = RepCode.OBJREF(ld)