File tests-improved.patch of Package python-dtfabric
From 40b51143a0b956b0f28fc49b6c3f3e48b379e4bf Mon Sep 17 00:00:00 2001
From: Joachim Metz <joachim.metz@gmail.com>
Date: Fri, 30 Jul 2021 11:05:03 +0200
Subject: [PATCH] Worked on tests
---
test_data/structure.yaml | 2
test_data/structure_with_condition.yaml | 2
test_data/structure_with_padding.yaml | 5 ++
test_data/structure_with_sequence.yaml | 2
test_data/structure_with_stream.yaml | 2
test_data/structure_with_string.yaml | 2
test_data/structure_with_values.yaml | 2
tests/runtime/byte_operations.py | 4 -
tests/runtime/data_maps.py | 69 +++++++++++++-------------------
9 files changed, 48 insertions(+), 42 deletions(-)
--- a/test_data/structure.yaml
+++ b/test_data/structure.yaml
@@ -43,6 +43,8 @@ members:
---
name: sphere3d
type: structure
+attributes:
+ byte_order: little-endian
description: Sphere in 3 dimensional space.
members:
- name: number_of_triangles
--- a/test_data/structure_with_condition.yaml
+++ b/test_data/structure_with_condition.yaml
@@ -14,6 +14,8 @@ attributes:
---
name: structure_with_condition
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: flags
data_type: uint16
--- a/test_data/structure_with_padding.yaml
+++ b/test_data/structure_with_padding.yaml
@@ -14,6 +14,8 @@ attributes:
---
name: structure_with_padding
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: data_size
data_type: uint16
@@ -23,6 +25,9 @@ members:
---
name: structure_with_padding_and_stream
type: structure
+attributes:
+ byte_order: little-endian
+members:
members:
- name: data_size
data_type: uint16
--- a/test_data/structure_with_sequence.yaml
+++ b/test_data/structure_with_sequence.yaml
@@ -14,6 +14,8 @@ attributes:
---
name: extension_block
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: size
data_type: uint32
--- a/test_data/structure_with_stream.yaml
+++ b/test_data/structure_with_stream.yaml
@@ -14,6 +14,8 @@ attributes:
---
name: extension_block
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: size
data_type: uint32
--- a/test_data/structure_with_string.yaml
+++ b/test_data/structure_with_string.yaml
@@ -14,6 +14,8 @@ attributes:
---
name: utf16_string
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: size
data_type: uint16
--- a/test_data/structure_with_values.yaml
+++ b/test_data/structure_with_values.yaml
@@ -29,6 +29,8 @@ members:
---
name: structure_with_values
type: structure
+attributes:
+ byte_order: little-endian
members:
- name: format_version
data_type: uint32
--- a/tests/runtime/byte_operations.py
+++ b/tests/runtime/byte_operations.py
@@ -27,7 +27,7 @@ class StructOperationTest(test_lib.BaseT
def testReadFrom(self):
"""Tests the ReadFrom function."""
- byte_stream_operation = byte_operations.StructOperation('i')
+ byte_stream_operation = byte_operations.StructOperation('<i')
value = byte_stream_operation.ReadFrom(b'\x12\x34\x56\x78')
self.assertEqual(value, tuple([0x78563412]))
@@ -40,7 +40,7 @@ class StructOperationTest(test_lib.BaseT
def testWriteTo(self):
"""Tests the WriteTo function."""
- byte_stream_operation = byte_operations.StructOperation('i')
+ byte_stream_operation = byte_operations.StructOperation('<i')
byte_stream = byte_stream_operation.WriteTo(tuple([0x78563412]))
self.assertEqual(byte_stream, b'\x12\x34\x56\x78')
--- a/tests/runtime/data_maps.py
+++ b/tests/runtime/data_maps.py
@@ -761,12 +761,10 @@ class SequenceMapTest(test_lib.BaseTestC
data_type_map = data_maps.SequenceMap(data_type_definition)
- byte_values = []
- for value in range(1, 13):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [
+ value.to_bytes(4, byteorder='little') for value in range(1, 13)]
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
sequence_value = data_type_map._CompositeMapByteStream(byte_stream)
self.assertEqual(
@@ -1157,14 +1155,13 @@ class StructureMapTest(test_lib.BaseTest
data_type_definition = definitions_registry.GetDefinitionByName('point3d')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = []
- for value in range(1, 4):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ expected_byte_values = [
+ value.to_bytes(4, byteorder='little') for value in range(1, 4)]
+
+ expected_byte_stream = b''.join(expected_byte_values)
point3d = data_type_map.CreateStructureValues(x=1, y=2, z=3)
- expected_byte_stream = bytes(bytearray(byte_values))
byte_stream = data_type_map._LinearFoldByteStream(point3d)
self.assertEqual(byte_stream, expected_byte_stream)
@@ -1178,12 +1175,10 @@ class StructureMapTest(test_lib.BaseTest
data_type_definition = definitions_registry.GetDefinitionByName('point3d')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = []
- for value in range(1, 4):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [
+ value.to_bytes(4, byteorder='little') for value in range(1, 4)]
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
point3d = data_type_map._LinearMapByteStream(byte_stream)
self.assertEqual(point3d.x, 1)
@@ -1240,12 +1235,10 @@ class StructureMapTest(test_lib.BaseTest
data_type_definition = definitions_registry.GetDefinitionByName('point3d')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = []
- for value in range(1, 4):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [
+ value.to_bytes(4, byteorder='little') for value in range(1, 4)]
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
point3d = data_type_map.MapByteStream(byte_stream)
self.assertEqual(point3d.x, 1)
@@ -1271,12 +1264,10 @@ class StructureMapTest(test_lib.BaseTest
data_type_definition = definitions_registry.GetDefinitionByName('box3d')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = []
- for value in range(1, 433):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [
+ value.to_bytes(4, byteorder='little') for value in range(1, 433)]
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
box = data_type_map.MapByteStream(byte_stream)
self.assertEqual(box.triangles[0].a.x, 1)
@@ -1294,12 +1285,11 @@ class StructureMapTest(test_lib.BaseTest
'structure_with_condition')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = [0x01, 0x80]
- for value in range(1, 6):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [0x8001.to_bytes(2, byteorder='little')]
+ byte_values.extend([
+ value.to_bytes(4, byteorder='little') for value in range(1, 6)])
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
structure_with_condition = data_type_map.MapByteStream(byte_stream)
self.assertEqual(structure_with_condition.flags, 0x8001)
@@ -1310,12 +1300,11 @@ class StructureMapTest(test_lib.BaseTest
self.assertEqual(structure_with_condition.conditional_data2, 4)
self.assertEqual(structure_with_condition.data3, 5)
- byte_values = [0x01, 0x00]
- for value in range(1, 6):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ byte_values = [0x0001.to_bytes(2, byteorder='little')]
+ byte_values.extend([
+ value.to_bytes(4, byteorder='little') for value in range(1, 6)])
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
structure_with_condition = data_type_map.MapByteStream(byte_stream)
self.assertEqual(structure_with_condition.flags, 0x0001)
@@ -1378,12 +1367,12 @@ class StructureMapTest(test_lib.BaseTest
data_type_definition = definitions_registry.GetDefinitionByName('sphere3d')
data_type_map = data_maps.StructureMap(data_type_definition)
- byte_values = [3, 0, 0, 0]
- for value in range(1, 113):
- byte_value_upper, byte_value_lower = divmod(value, 256)
- byte_values.extend([byte_value_lower, byte_value_upper, 0, 0])
+ # Note that 3.to_bytes() is not supported as syntax.
+ byte_values = [0x3.to_bytes(4, byteorder='little')]
+ byte_values.extend([
+ value.to_bytes(4, byteorder='little') for value in range(1, 113)])
- byte_stream = bytes(bytearray(byte_values))
+ byte_stream = b''.join(byte_values)
sphere = data_type_map.MapByteStream(byte_stream)
self.assertEqual(sphere.number_of_triangles, 3)