Beispiel #1
0
    def test_compile_empty_header_raises_type_error(self):

        class EmptyHeader(Header):
            pass

        with raises(TypeError):
            compile_struct(EmptyHeader)
Beispiel #2
0
    def test_compile_header_coincident_fields_with_different_types_raises_type_error(
            self):
        class CoincidentFieldsWithDifferentTypesHeader(Header):
            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(NNInt32, 1, 0, "Field B.")

        with raises(TypeError):
            compile_struct(CoincidentFieldsWithDifferentTypesHeader)
Beispiel #3
0
    def test_compile_header_coincident_fields_with_different_types_raises_type_error(self):

        class CoincidentFieldsWithDifferentTypesHeader(Header):
            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(NNInt32, 1, 0, "Field B.")

        with raises(TypeError):
            compile_struct(CoincidentFieldsWithDifferentTypesHeader)
Beispiel #4
0
    def test_compile_header_with_partially_overlapping_fields_raises_value_error(
            self):
        class OverlappingFieldsHeader(Header):

            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(Int32, 3, 0, "Field B.")

        with raises(ValueError):
            compile_struct(OverlappingFieldsHeader)
Beispiel #5
0
    def test_compile_header_with_partially_overlapping_fields_raises_value_error(self):

        class OverlappingFieldsHeader(Header):

            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(Int32, 3, 0, "Field B.")

        with raises(ValueError):
            compile_struct(OverlappingFieldsHeader)
Beispiel #6
0
    def test_compile_header_with_too_short_length_raises_value_error(self):
        class ShortHeader(Header):

            START_OFFSET_IN_BYTES = 1
            LENGTH_IN_BYTES = 3

            field_a = field(Int32, 1, 0, "Field A.")

        with raises(ValueError):
            compile_struct(ShortHeader, ShortHeader.START_OFFSET_IN_BYTES,
                           ShortHeader.LENGTH_IN_BYTES)
Beispiel #7
0
    def test_compile_header_with_too_short_length_raises_value_error(self):

        class ShortHeader(Header):

            START_OFFSET_IN_BYTES = 1
            LENGTH_IN_BYTES = 3

            field_a = field(Int32, 1, 0, "Field A.")

        with raises(ValueError):
            compile_struct(ShortHeader, ShortHeader.START_OFFSET_IN_BYTES, ShortHeader.LENGTH_IN_BYTES)
Beispiel #8
0
    def test_compile_surjective_header_packer_successfully(self, endian):

        class SurjectiveHeader(Header):
            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(NNInt32, 5, 0, "Field B.")
            field_c = field(Int32, 1, 0, "Field C.")

        cformat, field_name_allocations = compile_struct(SurjectiveHeader, 1, endian=endian)
        assert cformat[0] == endian
        assert cformat[1] == 'i'
        assert field_name_allocations == [['field_a','field_c'], ['field_b']]
Beispiel #9
0
    def test_compile_surjective_header_packer_successfully(self, endian):
        class SurjectiveHeader(Header):
            field_a = field(Int32, 1, 0, "Field A.")
            field_b = field(NNInt32, 5, 0, "Field B.")
            field_c = field(Int32, 1, 0, "Field C.")

        cformat, field_name_allocations = compile_struct(SurjectiveHeader,
                                                         1,
                                                         endian=endian)
        assert cformat[0] == endian
        assert cformat[1] == 'i'
        assert field_name_allocations == [['field_a', 'field_c'], ['field_b']]
Beispiel #10
0
    def test_compile_empty_header_raises_type_error(self):
        class EmptyHeader(Header):
            pass

        with raises(TypeError):
            compile_struct(EmptyHeader)
Beispiel #11
0
 def test_compile_with_non_positive_length_raises_value_error(self):
     with raises(ValueError):
         compile_struct(None, 0, 0)
Beispiel #12
0
 def test_compile_with_negative_start_offset_raises_value_error(self):
     with raises(ValueError):
         compile_struct(None, -1, 1)
Beispiel #13
0
 def test_compile_with_non_positive_length_raises_value_error(self):
     with raises(ValueError):
         compile_struct(None, 0, 0)
Beispiel #14
0
 def test_compile_with_negative_start_offset_raises_value_error(self):
     with raises(ValueError):
         compile_struct(None, -1, 1)