780b86f99c5617b98109cb7c8b3b22cad2c9c32f
1 # The MIT License (MIT)
3 # Copyright (c) 2023 Philippe Proulx <eeppeliteloop@gmail.com>
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 def test_init_labels():
28 labels
= {"yo": 0x88, "meow": 123} # type: normand.SymbolsT
29 res
= normand
.parse("11 22 {yo:8} 33", init_labels
=labels
.copy())
30 assert res
.data
== bytearray([0x11, 0x22, 0x88, 0x33])
31 assert res
.labels
== labels
.copy()
35 variables
= {"zoom": 0x88, "bateau": -123.45} # type: normand.SymbolsT
36 res
= normand
.parse("11 22 {zoom:8} 33", init_variables
=variables
.copy())
37 assert res
.data
== bytearray([0x11, 0x22, 0x88, 0x33])
38 assert res
.variables
== variables
.copy()
41 def test_init_offset():
42 res
= normand
.parse("11 22 {ICITTE:8} 33", init_offset
=0x23)
43 assert res
.data
== bytearray([0x11, 0x22, 0x25, 0x33])
44 assert res
.offset
== 0x27
47 def _test_init_bo(bo
: normand
.ByteOrder
):
51 if bo
== normand
.ByteOrder
.LE
:
52 h_byte
, l_byte
= l_byte
, h_byte
54 res
= normand
.parse("11 22 {-1993:16} 33", init_byte_order
=bo
)
55 assert res
.data
== bytearray([0x11, 0x22, h_byte
, l_byte
, 0x33])
56 assert res
.byte_order
== bo
59 def test_init_bo_be():
60 _test_init_bo(normand
.ByteOrder
.BE
)
63 def test_init_bo_le():
64 _test_init_bo(normand
.ByteOrder
.LE
)
67 def test_final_labels():
68 labels
= {"yo": 0x88, "meow": 123} # type: normand.SymbolsT
70 "11 <june> 22 (77 <aug> 88) * 2 <kilo> 33", init_labels
=labels
.copy()
74 assert res
.labels
== labels
.copy()
77 def test_final_vars():
78 variables
= {"yo": 0x88, "meow": -123.45}
80 "11 {yo = 18.2} 22 (77 {zoom = ICITTE} 88) * 2 33",
81 init_variables
=variables
.copy(),
83 variables
["yo"] = 18.2
85 assert res
.variables
== variables
.copy()
88 def test_final_offset():
89 res
= normand
.parse("11 22 33 <32> 44 55")
90 assert res
.offset
== 34
93 def test_final_byte_order_none():
94 res
= normand
.parse("11 22 33 {-19:8} 44 55")
95 assert res
.byte_order
is None
98 def test_final_byte_order_be():
99 res
= normand
.parse("11 22 {le} 33 {-19:8} 44 ( {be} 88 ) * 3 55")
100 assert res
.byte_order
== normand
.ByteOrder
.BE
103 def test_final_byte_order_le():
104 res
= normand
.parse("11 22 {be} 33 {-19:8} 44 ( {le} 88 ) * 3 55")
105 assert res
.byte_order
== normand
.ByteOrder
.LE
109 res
= normand
.parse("# nothing to see here!\n")
110 assert len(res
.data
) == 0
111 assert len(res
.labels
) == 0
112 assert len(res
.variables
) == 0
113 assert res
.offset
== 0
This page took 0.033249 seconds and 3 git commands to generate.