예제 #1
0
    def test_compile_empty_header_raises_type_error(self):

        class EmptyHeader(Header):
            pass

        with raises(TypeError):
            compile_struct(EmptyHeader)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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']]
예제 #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']]
예제 #10
0
    def test_compile_empty_header_raises_type_error(self):
        class EmptyHeader(Header):
            pass

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