def testRawDataOnly(self): ''' Test raw data only ''' raw_data = 'This is raw data' ed = ExtensionData(0, None, raw_data) self.assertEqual(raw_data, ed['raw_data']) self.assertEqual(len(ed.keys()), 1) self.assertEqual(0, ed.get_format())
def testString(self): ''' Test string data ''' raw_data = "0123456789ABCDEFGH" fmt = 0x5445535400000001 ed = ExtensionData(fmt,None, raw_data) self.assertEqual(raw_data, ed['raw_data']) self.assertEqual(raw_data, ed['info']) self.assertEqual(len(ed.keys()), 2) self.assertEqual(fmt, ed.get_format())
def testLocation(self): ''' Test location is handled correctly ''' s = struct.Struct("3p256p") fmt = 0x5445535400000003 loc = Location('C','MB-SL3-ET1-PT2') raw_data = s.pack(loc.get_id(),loc.get_location()) ed = ExtensionData(fmt,None, raw_data) self.assertEqual(raw_data,ed['raw_data']) self.assertEqual(loc,ed['neighbor']) self.assertEqual(len(ed.keys()),2) self.assertEqual(fmt,ed.get_format())
def testToFromDict(self): ''' Test to and from dict is handled correctly ''' s = struct.Struct("3p256p") fmt = 0x5445535400000003 loc = Location('C','MB-SL3-ET1-PT2') raw_data = s.pack(loc.get_id(),loc.get_location()) ed = ExtensionData(fmt,None, raw_data) self.assertEqual(raw_data,ed['raw_data']) self.assertEqual(loc,ed['neighbor']) self.assertEqual(len(ed.keys()),2) self.assertEqual(fmt,ed.get_format()) tmp_dict = ed.write_to_dictionary() new_ed = ExtensionData(fmt, None, None, tmp_dict) self.assertEqual(raw_data, new_ed['raw_data']) self.assertEqual(loc, new_ed['neighbor']) self.assertEqual(len(new_ed.keys()), 2) self.assertEqual(fmt, new_ed.get_format()) return