@@ -20,6 +20,7 @@ class TestSimData:
2020 {"address" : 6 , "count" : 10 , "datatype" : DataType .INT16 , "values" : [17 , 18 ]},
2121 {"address" : 7 , "datatype" : DataType .STRING , "values" : "test" },
2222 {"address" : 8 , "count" : 10 , "datatype" : DataType .STRING , "values" : "test" },
23+ {"address" : 8 , "count" : 10 , "datatype" : DataType .STRING , "values" : "test" , "string_encoding" : "utf-8" },
2324 {"address" : 0 , "datatype" : DataType .REGISTERS , "values" : 17 , "count" : 5 },
2425 {"address" : 3 , "datatype" : DataType .INT16 , "values" : 17 , "readonly" : True },
2526 {"address" : 0 , "count" : 2 ^ 16 - 1 },
@@ -45,6 +46,7 @@ def test_simdata_instanciate(self, kwargs):
4546 {"address" : 1 , "datatype" : "not ok" },
4647 {"address" : 1 , "datatype" : 11 },
4748 {"address" : 2 , "values" : 17 },
49+ {"address" : 8 , "count" : 10 , "datatype" : DataType .STRING , "values" : "test" , "string_encoding" : "not ok" },
4850 ])
4951 def test_simdata_not_ok (self , kwargs ):
5052 """Test that simdata can be objects."""
@@ -94,40 +96,34 @@ def test_simdata_value_invalid(self, values):
9496 with pytest .raises (TypeError ):
9597 SimData (0 , values = values , datatype = DataType .INVALID )
9698
97- @pytest .mark .parametrize (("value" , "value_type" , "order" , "regs" ), [
98- # test word order
99- (- 27123 , DataType .INT16 , (True , True ), [0x960D ]),
100- ([- 27123 , 27123 ], DataType .INT16 , (True , True ), [0x960D , 0x69F3 ]),
101- ([- 27123 , 27123 ], DataType .INT16 , (False , True ), [0x960D , 0x69F3 ]),
102- ([32145678 , - 32145678 ], DataType .INT32 , (True , True ), [0x01EA , 0x810E , 0xFE15 , 0x7EF2 ]),
103- ([32145678 , - 32145678 ], DataType .INT32 , (False , True ), [0x810E , 0x01EA , 0x7EF2 , 0xFE15 ]),
104- # test byte order
105- ([- 27123 , 27123 ], DataType .REGISTERS , (True , False ), [0x0D96 , 0xF369 ]),
106- ([32145678 , - 32145678 ], DataType .INT32 , (True , False ), [0xEA01 , 0x0E81 , 0x15FE , 0xF27E ]),
99+ @pytest .mark .parametrize (("value" , "value_type" , "regs" ), [
100+ (- 27123 , DataType .INT16 , [0x960D ]),
101+ ([- 27123 , 27123 ], DataType .INT16 , [0x960D , 0x69F3 ]),
102+ ([32145678 , - 32145678 ], DataType .INT32 , [0x01EA , 0x810E , 0xFE15 , 0x7EF2 ]),
107103 # test data types
108- (27123 , DataType .REGISTERS , ( True , True ), [0x69F3 ]),
109- (- 27124 , DataType .INT16 , ( True , True ), [0x960C ]),
110- (27123 , DataType .UINT16 , ( True , True ), [0x69F3 ]),
111- (- 32145678 , DataType .INT32 , ( True , True ), [0xFE15 , 0x7EF2 ]),
112- (32145678 , DataType .UINT32 , ( True , True ), [0x01EA , 0x810E ]),
113- (- 1234567890123456789 , DataType .INT64 , ( True , True ), [0xEEDD , 0xEF0B , 0x8216 , 0x7EEB ]),
114- (1234567890123456789 , DataType .UINT64 , ( True , True ), [0x1122 , 0x10F4 , 0x7DE9 , 0x8115 ]),
115- (27123.5 , DataType .FLOAT32 , ( True , True ), [0x46D3 , 0xE700 ]),
116- (3.141592 , DataType .FLOAT32 , ( True , True ), [0x4049 , 0x0FD8 ]),
117- (- 3.141592 , DataType .FLOAT32 , ( True , True ), [0xC049 , 0x0FD8 ]),
118- (27123.5 , DataType .FLOAT64 , ( True , True ), [0x40DA , 0x7CE0 , 0x0000 , 0x0000 ]),
119- (3.14159265358979 , DataType .FLOAT64 , ( True , True ), [0x4009 , 0x21FB , 0x5444 , 0x2D11 ]),
120- (- 3.14159265358979 , DataType .FLOAT64 , ( True , True ), [0xC009 , 0x21FB , 0x5444 , 0x2D11 ]),
121- (0x0100 , DataType .BITS , ( True , True ), [256 ]),
122- ([0x0100 , 0x0001 ], DataType .BITS , ( True , True ), [256 , 1 ]),
123- ([True ] + [False ] * 15 , DataType .BITS , ( True , True ), [1 ]),
124- ([True ] + [False ] * 8 + [True ] + [False ] * 6 , DataType .BITS , ( True , True ), [513 ]),
125- ([True ] + [False ] * 15 + [False ] * 8 + [True ] + [False ] * 7 , DataType .BITS , ( True , True ), [1 , 256 ]),
104+ (27123 , DataType .REGISTERS , [0x69F3 ]),
105+ (- 27124 , DataType .INT16 , [0x960C ]),
106+ (27123 , DataType .UINT16 , [0x69F3 ]),
107+ (- 32145678 , DataType .INT32 , [0xFE15 , 0x7EF2 ]),
108+ (32145678 , DataType .UINT32 , [0x01EA , 0x810E ]),
109+ (- 1234567890123456789 , DataType .INT64 , [0xEEDD , 0xEF0B , 0x8216 , 0x7EEB ]),
110+ (1234567890123456789 , DataType .UINT64 , [0x1122 , 0x10F4 , 0x7DE9 , 0x8115 ]),
111+ (27123.5 , DataType .FLOAT32 , [0x46D3 , 0xE700 ]),
112+ (3.141592 , DataType .FLOAT32 , [0x4049 , 0x0FD8 ]),
113+ (- 3.141592 , DataType .FLOAT32 , [0xC049 , 0x0FD8 ]),
114+ (27123.5 , DataType .FLOAT64 , [0x40DA , 0x7CE0 , 0x0000 , 0x0000 ]),
115+ (3.14159265358979 , DataType .FLOAT64 , [0x4009 , 0x21FB , 0x5444 , 0x2D11 ]),
116+ (- 3.14159265358979 , DataType .FLOAT64 , [0xC009 , 0x21FB , 0x5444 , 0x2D11 ]),
117+ (0x0100 , DataType .BITS , [256 ]),
118+ ([0x0100 , 0x0001 ], DataType .BITS , [256 , 1 ]),
119+ ([True ] + [False ] * 15 , DataType .BITS , [1 ]),
120+ ([True ] + [False ] * 8 + [True ] + [False ] * 6 , DataType .BITS , [513 ]),
121+ ([True ] + [False ] * 15 + [False ] * 8 + [True ] + [False ] * 7 , DataType .BITS , [1 , 256 ]),
126122 ])
127- def test_simdata_build_registers (self , value , value_type , order , regs ):
123+ def test_simdata_build_registers (self , value , value_type , regs ):
128124 """Test simdata value."""
129125 sd = SimData (0 , values = value , datatype = value_type )
130- build_regs = sd .build_registers (( order [ 0 ], order [ 1 ]), "utf-8" , False )
126+ build_regs = sd .build_registers (False )
131127 assert build_regs == regs
132128
133129 @pytest .mark .parametrize (("value" , "code" , "expect" ), [
@@ -138,8 +134,8 @@ def test_simdata_build_registers(self, value, value_type, order, regs):
138134 ])
139135 def test_simdata_build_string (self , value , code , expect ):
140136 """Test simdata value."""
141- sd = SimData (0 , values = value , datatype = DataType .STRING )
142- build_regs = sd .build_registers (( True , True ), code , False )
137+ sd = SimData (0 , values = value , datatype = DataType .STRING , string_encoding = code )
138+ build_regs = sd .build_registers (False )
143139 assert build_regs == expect
144140
145141 @pytest .mark .parametrize (("value" , "regs" ), [
@@ -152,22 +148,22 @@ def test_simdata_build_string(self, value, code, expect):
152148 def test_simdata_build_bit_block (self , value , regs ):
153149 """Test simdata value."""
154150 sd = SimData (0 , values = value , datatype = DataType .BITS )
155- build_regs = sd .build_registers (( True , True ), "utf-8" , True )
151+ build_regs = sd .build_registers (True )
156152 assert build_regs == regs
157153
158154 def test_simdata_build_updated_simdata (self ):
159155 """Test simdata value."""
160156 sd = SimData (0 , values = "ABC" , datatype = DataType .STRING )
161- build_regs = sd .build_registers (( True , True ), "utf-8" , False )
157+ build_regs = sd .build_registers (False )
162158 assert build_regs == [0x4142 , 0x4300 ]
163159 sd .values = "ABCDEF"
164- build_regs = sd .build_registers (( True , True ), "utf-8" , False )
160+ build_regs = sd .build_registers (False )
165161 assert build_regs == [0x4142 , 0x4344 , 0x4546 ]
166162
167163 sd .values = 123
168164 with pytest .raises (TypeError ):
169- sd .build_registers (( True , True ), "utf-8" , False )
165+ sd .build_registers (False )
170166 sd = SimData (0 , values = [True , True ], datatype = DataType .BITS )
171167 with pytest .raises (TypeError ):
172- sd .build_registers (( True , True ), "utf-8" , False )
168+ sd .build_registers (False )
173169
0 commit comments