Exemplo n.º 1
0
def test_ExplicitlyFormattedLogicalRecord_key_values(sort_order, expected):
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD_SINGLE_OBJECT)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    result = eflr.key_values(
        stringify_function=stringify.stringify_object_by_type, sort=sort_order)
    # print(result)
    assert result == expected
Exemplo n.º 2
0
def test_ExplicitlyFormattedLogicalRecord_eq():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr_a = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    ld.rewind()
    eflr_b = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    assert eflr_a == eflr_b
    assert eflr_a != 1
Exemplo n.º 3
0
def test_ExplicitlyFormattedLogicalRecord_key_value_raises():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    assert not eflr.is_key_value()
    with pytest.raises(EFLR.ExceptionEFLR) as err:
        eflr.key_values(stringify_function=stringify.stringify_object_by_type,
                        sort=True)
    assert err.value.args[0] == 'Can not represent EFLR as key->value table.'
Exemplo n.º 4
0
def test_ExplicitlyFormattedLogicalRecord_table_as_string(
        sort_order, expected):
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    result = eflr.table_as_strings(
        stringify_function=stringify.stringify_object_by_type, sort=sort_order)
    # print(result)
    assert result == expected
Exemplo n.º 5
0
def test_ExplicitlyFormattedLogicalRecord_key_value():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD_SINGLE_OBJECT)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    assert eflr.is_key_value()
Exemplo n.º 6
0
def test_ExplicitlyFormattedLogicalRecord_reduced_object_map():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    result = EFLR.reduced_object_map(eflr)
    # print(result)
    assert result == {b'TIME': 0, b'PRESSURE': 1, b'PAD-ARRAY': 2}
Exemplo n.º 7
0
def test_ExplicitlyFormattedLogicalRecord_table_shape():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    assert eflr.shape == (3, 5)
Exemplo n.º 8
0
def test_ExplicitlyFormattedLogicalRecord_len():
    ld = LogicalData(LOGICAL_BYTES_FROM_STANDARD)
    eflr = EFLR.ExplicitlyFormattedLogicalRecord(3, ld)
    result = eflr.str_long()
    # print(result)
    assert len(eflr) == 3
Exemplo n.º 9
0
import contextlib
import typing

import pytest

import TotalDepth.RP66V1.core.LogicalRecord.Duplicates
from TotalDepth.RP66V1.core.File import LogicalData
from TotalDepth.RP66V1.core.LogicalRecord import EFLR
from TotalDepth.RP66V1.core.LogicalRecord.ComponentDescriptor import ComponentDescriptor
from TotalDepth.RP66V1.core import RepCode, stringify
from TotalDepth.RP66V1.core.RepCode import ObjectName


@pytest.mark.parametrize('ld, expected_type, expected_name', (
    (LogicalData(b'\xf0\x07CHANNEL'), b'CHANNEL', b''),
    (LogicalData(b'\xf8\x07CHANNEL\x01\x30'), b'CHANNEL', b'0'),
))
def test_Set(ld, expected_type, expected_name):
    result = EFLR.Set(ld)
    assert result.type == expected_type
    assert result.name == expected_name
    assert ld.remain == 0


@pytest.mark.parametrize('ld, expected_type, expected_name', (
    (LogicalData(b'\xf0\x07CHANNEL'), b'CHANNEL', b''),
    (LogicalData(b'\xf8\x07CHANNEL\x01\x30'), b'CHANNEL', b'0'),
))
def test_Set_eq(ld, expected_type, expected_name):
    result = EFLR.Set(ld)
    assert result == result
Exemplo n.º 10
0
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.'
Exemplo n.º 11
0
def test_DTIME_invalid_tz_description():
    ld = LogicalData(b'\x57\x34\x13\x15\x14\x0f\x02\x6c')
    #                        ^
    result = RepCode.DTIME(ld)
    assert result.tz_description == ''
Exemplo n.º 12
0
        24,  #   OBJREF	V	            Object reference
        25,  #   ATTREF	V	            Attribute reference
        27,  #   UNITS	V	            Units expression
    ))
def test_rep_code_fixed_length_raises(rc):
    with pytest.raises(RepCode.ExceptionRepCode) as err:
        RepCode.rep_code_fixed_length(rc)
    assert err.value.args[
        0] == f'Representation code {rc} is not fixed length.'


@pytest.mark.parametrize(
    'ld, expected',
    (
        # Examples from [RP66V1 Appendix B Section B.2]
        (LogicalData(b'\x43\x19\x00\x00'), 153.0),
        (LogicalData(b'\xc3\x19\x00\x00'), -153.0),
        # Example from RP66V2
        (LogicalData(b'\x00\x00\x00\x00'), 0.0),
    ))
def test_FSINGL(ld, expected):
    result = RepCode.FSINGL(ld)
    assert result == expected
    assert ld.remain == 0


@pytest.mark.parametrize(
    'ld, expected',
    (
        # Examples from [RP66V2 Section 11.3.23]
        (LogicalData(b'\x00\x00\x00\x00'), 0.0),