def test_emptySpareField(self):
     """
     You can't insert a 0-sized spare. It makes no sense, too.
     Just comment the field if you don't need a field anymore.
     """
     spare_desc = ET.fromstring('<field type="spare" bits="0">woot</field>')
     self.assertRaises(ValueError, lambda : structureparser.parse_field(spare_desc))
 def test_emptySpareField(self):
     """
     You can't insert a 0-sized spare. It makes no sense, too.
     Just comment the field if you don't need a field anymore.
     """
     spare_desc = ET.fromstring('<field type="spare" bits="0">woot</field>')
     self.assertRaises(ValueError, lambda: structureparser.parse_field(spare_desc))
 def test_bool_doesnotexist(self):
     bool_desc = ET.fromstring('<field type="bool25">a_field</field>')
     self.assertRaises(ValueError, lambda : structureparser.parse_field(bool_desc))
 def test_spareField(self):
     spare_desc = ET.fromstring('<field type="spare" bits="8">woot</field>')
     parsed_field = structureparser.parse_field(spare_desc)
     self.assertEqual(parsed_field["name"], "woot")
     self.assertEqual(parsed_field["type"], "spare")
     self.assertEqual(parsed_field["bits"], 8)
 def test_paddingBits(self):
     padding_desc = ET.fromstring('<field type="padding">dis_not_pudding</field>')
     parsed_field = structureparser.parse_field(padding_desc)
     self.assertEqual(parsed_field["name"], "dis_not_pudding")
     self.assertEqual(parsed_field["type"], "padding")
     self.assertEqual(parsed_field["bits"], 0)
 def test_spare_nosize(self):
     spare_desc = ET.fromstring('<field type="spare"></field>')
     result = structureparser.parse_field(spare_desc)
 def test_schar(self):
     char_desc = ET.fromstring('<field type="schar">a_field</field>')
     parsed_field = structureparser.parse_field(char_desc)
     self.assertEqual(parsed_field["type"], "schar")
     self.assertEqual(parsed_field["bits"], 8)
 def test_bool32(self):
     bool_desc = ET.fromstring('<field type="bool32">a_field</field>')
     parsed_field = structureparser.parse_field(bool_desc)
     self.assertEqual(parsed_field["bits"], 32)
Exemple #9
0
 def test_spare_size_ignored_lenght(self):
     parsed_doc = parser.parse_field(ET.fromstring('<field type="spare" lenght="10">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("spare test;", res)
Exemple #10
0
 def test_int8_repeated_variable(self):
     parsed_doc = parser.parse_field(ET.fromstring('<field type="uint8" repeated="num_of_nums">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8[num_of_nums] test;", res)
Exemple #11
0
 def test_int8_repeated(self):
     parsed_doc = parser.parse_field(ET.fromstring('<field type="uint8" repeated="5">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8[5] test;", res)
Exemple #12
0
 def test_int8(self):
     parsed_doc = parser.parse_field(ET.fromstring('<field type="uint8" bits="0">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8 test;", res)
 def test_spare_nosize(self):
     parsed_doc = parser.parse_field(
         ET.fromstring('<field type="spare">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("spare test;", res)
 def test_spare_size_ignored_lenght(self):
     parsed_doc = parser.parse_field(
         ET.fromstring('<field type="spare" lenght="10">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("spare test;", res)
 def test_int8_repeated_variable(self):
     parsed_doc = parser.parse_field(
         ET.fromstring(
             '<field type="uint8" repeated="num_of_nums">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8[num_of_nums] test;", res)
 def test_int8_repeated(self):
     parsed_doc = parser.parse_field(
         ET.fromstring('<field type="uint8" repeated="5">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8[5] test;", res)
Exemple #17
0
 def test_spareField(self):
     spare_desc = ET.fromstring('<field type="spare" bits="8">woot</field>')
     parsed_field = structureparser.parse_field(spare_desc)
     self.assertEqual(parsed_field["name"], "woot")
     self.assertEqual(parsed_field["type"], "spare")
     self.assertEqual(parsed_field["bits"], 8)
Exemple #18
0
 def test_spare_nosize(self):
     parsed_doc = parser.parse_field(ET.fromstring('<field type="spare">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("spare test;", res)
Exemple #19
0
 def test_bool_doesnotexist(self):
     bool_desc = ET.fromstring('<field type="bool25">a_field</field>')
     self.assertRaises(ValueError, lambda: structureparser.parse_field(bool_desc))
Exemple #20
0
 def test_raw_withsize(self):
     char_desc = ET.fromstring('<field type="raw" lenght="5">a_field</field>')
     parsed_field = structureparser.parse_field(char_desc)
     self.assertEqual(parsed_field["type"], "raw")
     self.assertEqual(parsed_field["bits"], 40)
 def test_raw_withsize(self):
     char_desc = ET.fromstring('<field type="raw" lenght="5">a_field</field>')
     parsed_field = structureparser.parse_field(char_desc)
     self.assertEqual(parsed_field["type"], "raw")
     self.assertEqual(parsed_field["bits"], 40)
Exemple #22
0
 def test_spare_wrongsize(self):
     spare_desc = ET.fromstring('<field type="spare" bits="a">woot</field>')
     self.assertRaises(ValueError, lambda: structureparser.parse_field(spare_desc))
 def test_spare_wrongsize(self):
     spare_desc = ET.fromstring('<field type="spare" bits="a">woot</field>')
     self.assertRaises(ValueError, lambda : structureparser.parse_field(spare_desc))
Exemple #24
0
 def test_spare_nosize(self):
     spare_desc = ET.fromstring('<field type="spare"></field>')
     result = structureparser.parse_field(spare_desc)
 def test_float64(self):
     float_desc = ET.fromstring('<field type="float64">woot</field>')
     parsed_field = structureparser.parse_field(float_desc)
     self.assertEqual(parsed_field["name"], "woot")
     self.assertEqual(parsed_field["type"], "float64")
     self.assertEqual(parsed_field["bits"], 64)
Exemple #26
0
 def test_float64(self):
     float_desc = ET.fromstring('<field type="float64">woot</field>')
     parsed_field = structureparser.parse_field(float_desc)
     self.assertEqual(parsed_field["name"], "woot")
     self.assertEqual(parsed_field["type"], "float64")
     self.assertEqual(parsed_field["bits"], 64)
 def test_paddingBits_sizeIsIgnored(self):
     padding_desc = ET.fromstring('<field type="padding" bits="15">dis_not_pudding</field>')
     parsed_field = structureparser.parse_field(padding_desc)
     #`bits` is overridden
     self.assertEqual(parsed_field["bits"], 0) 
Exemple #28
0
 def test_paddingBits(self):
     padding_desc = ET.fromstring('<field type="padding">dis_not_pudding</field>')
     parsed_field = structureparser.parse_field(padding_desc)
     self.assertEqual(parsed_field["name"], "dis_not_pudding")
     self.assertEqual(parsed_field["type"], "padding")
     self.assertEqual(parsed_field["bits"], 0)
 def test_bool32(self):
     bool_desc = ET.fromstring('<field type="bool32">a_field</field>')
     parsed_field = structureparser.parse_field(bool_desc)
     self.assertEqual(parsed_field["bits"], 32)
Exemple #30
0
 def test_paddingBits_sizeIsIgnored(self):
     padding_desc = ET.fromstring('<field type="padding" bits="15">dis_not_pudding</field>')
     parsed_field = structureparser.parse_field(padding_desc)
     # `bits` is overridden
     self.assertEqual(parsed_field["bits"], 0)
 def test_schar(self):
     char_desc = ET.fromstring('<field type="schar">a_field</field>')
     parsed_field = structureparser.parse_field(char_desc)
     self.assertEqual(parsed_field["type"], "schar")
     self.assertEqual(parsed_field["bits"], 8)
 def test_int8(self):
     parsed_doc = parser.parse_field(
         ET.fromstring('<field type="uint8" bits="0">test</field>'))
     res = ws.build_field(parsed_doc)
     self.assertEqual("uint8 test;", res)