Exemple #1
0
 def test_write_byte(self):
     """ Can we write a byte to the structure """
     element = ET.fromstring('<PackBootRev Type="Byte" Pos="5" RW="ALL" />')
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = 6
     self.assertEqual(5, self.spa.last_pos)
     self.assertEqual("\x06", self.spa.last_data)
Exemple #2
0
 def test_write_word(self):
     """ Can we write a word to the structure """
     element = ET.fromstring('<RealSetPointG Type="Word" Pos="17" RW="ALL"/>')
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = 726
     self.assertEqual(17, self.spa.last_pos)
     self.assertEqual("\x02\xd6", self.spa.last_data)
Exemple #3
0
 def test_write_bool(self):
     """ Can we write a bool to the structure """
     element = ET.fromstring(
         '<RelayStuck Type="Bool" Pos="2" BitPos="6" RW="ALL" />'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = True
     self.assertEqual(2, self.spa.last_pos)
     self.assertEqual(chr(0b01000010), self.spa.last_data)
Exemple #4
0
 def test_write_enum_not_member(self):
     """ Can we write an enum to the structure """
     element = ET.fromstring(
         '<PackType Type="Enum" Pos="6" '
         'Items="Unknown|inXE|MasIBC|MIA|DJS4|inClear|inXM|K600'
         '|inTerface|inTouch|inYT|K800|inYJ" RW="ALL"/>'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = "Not A Member"
Exemple #5
0
 def test_write_enum(self):
     """ Can we write an enum to the structure """
     element = ET.fromstring(
         '<PackType Type="Enum" Pos="6" '
         'Items="Unknown|inXE|MasIBC|MIA|DJS4|inClear|inXM|K600'
         '|inTerface|inTouch|inYT|K800|inYJ" RW="ALL"/>'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = "inYJ"
     self.assertEqual(6, self.spa.last_pos)
     self.assertEqual("\x0c", self.spa.last_data)
Exemple #6
0
 def test_write_bitpos_enum(self):
     """ Can we write an enum to the structure """
     element = ET.fromstring(
         '<UdP3 Type="Enum" Pos="3" BitPos="4" MaxItems="4" Items="OFF|LO|HI" RW="ALL" />'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = "HI"
     self.assertEqual(3, self.spa.last_pos)
     self.assertEqual(chr(0b00100011), self.spa.last_data)
     accessor.value = "LO"
     self.assertEqual(chr(0b00010011), self.spa.last_data)
     accessor.value = "OFF"
     self.assertEqual(chr(0b00000011), self.spa.last_data)
Exemple #7
0
 def test_write_sized_bitpos_enum(self):
     """ Can we write a sized bitpos enum to the structure """
     element = ET.fromstring(
         '<UdP2 Type="Enum" Pos="19" BitPos="12" Size="2" '
         'MaxItems="4" Items="OFF|LO|HI" RW="ALL" />'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = "HI"
     self.assertEqual(19, self.spa.last_pos)
     self.assertEqual(chr(0b00100001) + chr(0b01110000), self.spa.last_data)
     accessor.value = "LO"
     self.assertEqual(chr(0b00010001) + chr(0b01110000), self.spa.last_data)
     accessor.value = "OFF"
     self.assertEqual(chr(0b00000001) + chr(0b01110000), self.spa.last_data)
Exemple #8
0
 def test_read_bitpos_enum(self):
     """ Can we read a bitpos enum from the structure """
     element = ET.fromstring(
         '<UdP3 Type="Enum" Pos="3" BitPos="4" MaxItems="4" Items="OFF|LO|HI" RW="ALL" />'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     self.assertEqual("OFF", accessor.value)
Exemple #9
0
 def test_read_enum(self):
     """ Can we read an enum from the structure """
     element = ET.fromstring(
         '<PackType Type="Enum" Pos="6" '
         'Items="Unknown|inXE|MasIBC|MIA|DJS4|inClear|inXM|K600'
         '|inTerface|inTouch|inYT|K800|inYJ" />'
     )
     accessor = GeckoStructAccessor(self.spa, element)
     self.assertEqual("inXM", accessor.value)
Exemple #10
0
    def test_multiple_write_bitpos_enum(self):
        """ Can we write multiple bitpos enums to the structure """

        element_p1 = ET.fromstring(
            '<UdP1 Type="Enum" Pos="21" BitPos="14" Size="2" '
            'MaxItems="4" Items="OFF|LO|HI" RW="ALL" />'
        )
        element_p2 = ET.fromstring(
            '<UdP2 Type="Enum" Pos="21" BitPos="12" Size="2" '
            'MaxItems="4" Items="OFF|LO|HI" RW="ALL" />'
        )

        accessor_p1 = GeckoStructAccessor(self.spa, element_p1)
        accessor_p2 = GeckoStructAccessor(self.spa, element_p2)

        accessor_p2.value = "HI"
        self.assertEqual(21, self.spa.last_pos)
        self.assertEqual("\x20\x00", self.spa.last_data)
        self.assertEqual(7, self.spa.last_len)
        self.assertEqual(2, len(self.spa.last_data))

        accessor_p1.value = "HI"
        self.assertEqual(21, self.spa.last_pos)
        self.assertEqual("\xA0\x00", self.spa.last_data)
        self.assertEqual(7, self.spa.last_len)
        self.assertEqual(2, len(self.spa.last_data))
Exemple #11
0
 def test_read_word(self):
     """ Can we read a word from the structure """
     element = ET.fromstring('<RealSetPointG Type="Word" Pos="17" />')
     accessor = GeckoStructAccessor(self.spa, element)
     self.assertEqual(702, accessor.value)
Exemple #12
0
 def test_write_byte_fails(self):
     """ Can we write a byte to the structure without the RW tag? """
     element = ET.fromstring('<PackBootRev Type="Byte" Pos="5" />')
     accessor = GeckoStructAccessor(self.spa, element)
     accessor.value = 6
Exemple #13
0
 def test_read_byte(self):
     """ Can we read a byte from the structure """
     element = ET.fromstring('<PackBootRev Type="Byte" Pos="5" />')
     accessor = GeckoStructAccessor(self.spa, element)
     self.assertEqual(5, accessor.value)
Exemple #14
0
 def test_read_bool(self):
     """ Can we read a bool from the structure """
     element = ET.fromstring('<RelayStuck Type="Bool" Pos="2" BitPos="6" />')
     accessor = GeckoStructAccessor(self.spa, element)
     self.assertFalse(accessor.value)