Esempio n. 1
0
 def test_collate_packet(self):
     pkt = CorrPacket()
     # Make sure a correctly formatted packet is accepted
     self.cb.collate_packet(pkt)
     # Make sure bad packets are rejected
     pkt.instrument_id = 5
     self.assertRaises(ValueError, self.cb.collate_packet, pkt)
Esempio n. 2
0
 def test_collate_packet(self):
     pkt = CorrPacket()
     # Make sure a correctly formatted packet is accepted
     self.cb.collate_packet(pkt)
     # Make sure bad packets are rejected
     pkt.instrument_id = 5 
     self.assertRaises(ValueError, self.cb.collate_packet, pkt)
Esempio n. 3
0
 def test_unpack_data(self):
     cp = CorrPacket()
     cp.unpack_header(PACKET)
     cp.unpack_data(PACKET[cp.header_size():])
     print "Packet data is ", len(cp.get_data()), "bytes long"
     data = struct.unpack('II', cp.get_data())  # use native endianess
     self.assertEqual(data, OPTS['data'])
Esempio n. 4
0
    def test_unpack_data(self):
        cp = CorrPacket()
        cp.unpack_header(PACKET)
        cp.unpack_data(PACKET[cp.header_size():])
	print "Packet data is ",len(cp.get_data()),"bytes long"
        data = struct.unpack('II', cp.get_data()) # use native endianess
        self.assertEqual(data, OPTS['data'])
Esempio n. 5
0
 def test_setattributes(self):
     cp = CorrPacket()
     cp.n_options = 7
     self.assertEqual(cp.n_options, 7)
     cp.instrument_id = 7
     self.assertEqual(cp.instrument_id, 7)
     cp.instance_id = 7
     self.assertEqual(cp.instance_id, 7)
     cp.engine_id = 7
     self.assertEqual(cp.engine_id, 7)
     cp.timestamp = 7
     self.assertEqual(cp.timestamp, 7)
     cp.heap_off = 7
     self.assertEqual(cp.heap_off, 7)
     cp.currerr = 7
     self.assertEqual(cp.currerr, 7)
     cp.set_data('abcdefgh')
     self.assertEqual(cp.get_data(), 'abcdefgh')
Esempio n. 6
0
 def test_setattributes(self):
     cp = CorrPacket()
     cp.n_options     = 7; self.assertEqual(cp.n_options,     7)
     cp.instrument_id = 7; self.assertEqual(cp.instrument_id, 7)
     cp.instance_id   = 7; self.assertEqual(cp.instance_id,   7)
     cp.engine_id     = 7; self.assertEqual(cp.engine_id,     7)
     cp.timestamp     = 7; self.assertEqual(cp.timestamp,     7)
     cp.heap_off       = 7; self.assertEqual(cp.heap_off,       7)
     cp.currerr       = 7; self.assertEqual(cp.currerr,       7)
     cp.set_data('abcdefgh'); self.assertEqual(cp.get_data(), 'abcdefgh')
Esempio n. 7
0
 def test_unpack_header(self):
     cp = CorrPacket()
     cp.unpack_header(PACKET)
     for k in OPTS:
         if not k in ['data']: self.assertEqual(getattr(cp,k), OPTS[k])
Esempio n. 8
0
 def setUp(self):
     self.cp = CorrPacket()
     self.cp.unpack_header(PACKET)
Esempio n. 9
0
 def test_size(self):
     cp = CorrPacket()
     self.assertEqual(cp.size(), HEADER_SIZE)
Esempio n. 10
0
 def test_pack(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     data = cp.pack()
     print "Packlen:",len(data),"Origlen:",len(PACKET)
     self.assertEqual(data, PACKET)
Esempio n. 11
0
class TestCorrPacket(unittest.TestCase):
    def setUp(self):
        self.cp = CorrPacket()
        self.cp.unpack_header(PACKET)
	    #self.heap_len = len(PACKET[self.cp.header_size():])

    def test_header_size(self):
        self.assertEqual(self.cp.header_size(), HEADER_SIZE)
    def test_size(self):
        cp = CorrPacket()
        self.assertEqual(cp.size(), HEADER_SIZE)
    def test_getattributes(self):
        self.assertEqual(self.cp.n_options, OPTS['n_options'])
        self.assertEqual(self.cp.instrument_id, OPTS['instrument_id'])
        self.assertEqual(self.cp.instance_id, OPTS['instance_id'])
        self.assertEqual(self.cp.engine_id, OPTS['engine_id'])
        self.assertEqual(self.cp.timestamp, OPTS['timestamp'])
        self.assertEqual(self.cp.currerr, OPTS['currerr'])
    def test_setattributes(self):
        cp = CorrPacket()
        cp.n_options     = 7; self.assertEqual(cp.n_options,     7)
        cp.instrument_id = 7; self.assertEqual(cp.instrument_id, 7)
        cp.instance_id   = 7; self.assertEqual(cp.instance_id,   7)
        cp.engine_id     = 7; self.assertEqual(cp.engine_id,     7)
        cp.timestamp     = 7; self.assertEqual(cp.timestamp,     7)
        cp.heap_off       = 7; self.assertEqual(cp.heap_off,       7)
        cp.currerr       = 7; self.assertEqual(cp.currerr,       7)
        cp.set_data('abcdefgh'); self.assertEqual(cp.get_data(), 'abcdefgh')
    def test_unpack_header(self):
        cp = CorrPacket()
        cp.unpack_header(PACKET)
        for k in OPTS:
            if not k in ['data']: self.assertEqual(getattr(cp,k), OPTS[k])
    def test_unpack_data(self):
        cp = CorrPacket()
        cp.unpack_header(PACKET)
        cp.unpack_data(PACKET[cp.header_size():])
	print "Packet data is ",len(cp.get_data()),"bytes long"
        data = struct.unpack('II', cp.get_data()) # use native endianess
        self.assertEqual(data, OPTS['data'])
    def test_unpack(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        for k in OPTS:
            if not k in ['data']: self.assertEqual(getattr(cp,k), OPTS[k])
        self.assertRaises(ValueError, cp.unpack, BAD_PACKET1)
        #self.assertRaises(ValueError, cp.unpack, BAD_PACKET2, self.heap_len)
    def test_pack_header(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack_header()
        self.assertEqual(data, PACKET[:cp.header_size()])
    def test_pack_data(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack_data()
        self.assertEqual(data, PACKET[cp.header_size():])
    def test_pack(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack()
        print "Packlen:",len(data),"Origlen:",len(PACKET)
        self.assertEqual(data, PACKET)
Esempio n. 12
0
    'engine_id': 59,
    'timestamp': 64,
    'heapoff': 128,
    'packetlen': 8,
    'packetcount': 1,
    'currerr': 0,
    'heaplen': 8,
    'data': (55, 22),
}

PACKET = struct.pack('>HHHH', PKT_ID, 3, 0, OPTS['n_options']) + \
    struct.pack('>HHHH', 50, OPTS['instrument_id'], OPTS['instance_id'], OPTS['engine_id']) + \
    struct.pack('>HHI', 3, 0, OPTS['timestamp']) + \
    struct.pack('>HHI', 52, 0, OPTS['currerr']) + \
    struct.pack('>H', 51) + bitstring.BitString(uintbe=OPTS['packetlen'], length=24).bytes + \
    bitstring.BitString(uintbe=OPTS['packetlen'], length=24).bytes + \
    struct.pack('>HHI', 5, 0, OPTS['heapoff']) + \
    struct.pack('>HHI', 53, 0, 0) + \
    struct.pack('>II',  *OPTS['data'])

cp = CorrPacket()
cp.unpack_header(PACKET)
cp.unpack_data(PACKET[cp.header_size():], len(PACKET[cp.header_size():]))
print "header:", cp.header_size()
print "data:", len(cp.get_data())
print "data size:", cp.size()
print "instance_id", cp.instance_id
print "instrument_id", cp.instrument_id
print "engine_id", cp.engine_id
print struct.unpack('>II', cp.get_data())
Esempio n. 13
0
 def test_pack_data(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     data = cp.pack_data()
     self.assertEqual(data, PACKET[cp.header_size():])
Esempio n. 14
0
 def test_size(self):
     cp = CorrPacket()
     self.assertEqual(cp.size(), HEADER_SIZE)
Esempio n. 15
0
 def test_unpack_header(self):
     cp = CorrPacket()
     cp.unpack_header(PACKET)
     for k in OPTS:
         if not k in ['data']: self.assertEqual(getattr(cp, k), OPTS[k])
Esempio n. 16
0
 def setUp(self):
     self.cp = CorrPacket()
     self.cp.unpack_header(PACKET)
Esempio n. 17
0
class TestCorrPacket(unittest.TestCase):
    def setUp(self):
        self.cp = CorrPacket()
        self.cp.unpack_header(PACKET)

#self.heap_len = len(PACKET[self.cp.header_size():])

    def test_header_size(self):
        self.assertEqual(self.cp.header_size(), HEADER_SIZE)

    def test_size(self):
        cp = CorrPacket()
        self.assertEqual(cp.size(), HEADER_SIZE)

    def test_getattributes(self):
        self.assertEqual(self.cp.n_options, OPTS['n_options'])
        self.assertEqual(self.cp.instrument_id, OPTS['instrument_id'])
        self.assertEqual(self.cp.instance_id, OPTS['instance_id'])
        self.assertEqual(self.cp.engine_id, OPTS['engine_id'])
        self.assertEqual(self.cp.timestamp, OPTS['timestamp'])
        self.assertEqual(self.cp.currerr, OPTS['currerr'])

    def test_setattributes(self):
        cp = CorrPacket()
        cp.n_options = 7
        self.assertEqual(cp.n_options, 7)
        cp.instrument_id = 7
        self.assertEqual(cp.instrument_id, 7)
        cp.instance_id = 7
        self.assertEqual(cp.instance_id, 7)
        cp.engine_id = 7
        self.assertEqual(cp.engine_id, 7)
        cp.timestamp = 7
        self.assertEqual(cp.timestamp, 7)
        cp.heap_off = 7
        self.assertEqual(cp.heap_off, 7)
        cp.currerr = 7
        self.assertEqual(cp.currerr, 7)
        cp.set_data('abcdefgh')
        self.assertEqual(cp.get_data(), 'abcdefgh')

    def test_unpack_header(self):
        cp = CorrPacket()
        cp.unpack_header(PACKET)
        for k in OPTS:
            if not k in ['data']: self.assertEqual(getattr(cp, k), OPTS[k])

    def test_unpack_data(self):
        cp = CorrPacket()
        cp.unpack_header(PACKET)
        cp.unpack_data(PACKET[cp.header_size():])
        print "Packet data is ", len(cp.get_data()), "bytes long"
        data = struct.unpack('II', cp.get_data())  # use native endianess
        self.assertEqual(data, OPTS['data'])

    def test_unpack(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        for k in OPTS:
            if not k in ['data']: self.assertEqual(getattr(cp, k), OPTS[k])
        self.assertRaises(ValueError, cp.unpack, BAD_PACKET1)
        #self.assertRaises(ValueError, cp.unpack, BAD_PACKET2, self.heap_len)
    def test_pack_header(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack_header()
        self.assertEqual(data, PACKET[:cp.header_size()])

    def test_pack_data(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack_data()
        self.assertEqual(data, PACKET[cp.header_size():])

    def test_pack(self):
        cp = CorrPacket()
        cp.unpack(PACKET)
        data = cp.pack()
        print "Packlen:", len(data), "Origlen:", len(PACKET)
        self.assertEqual(data, PACKET)
Esempio n. 18
0
 def test_pack(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     data = cp.pack()
     print "Packlen:", len(data), "Origlen:", len(PACKET)
     self.assertEqual(data, PACKET)
Esempio n. 19
0
 def test_pack_data(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     data = cp.pack_data()
     self.assertEqual(data, PACKET[cp.header_size():])
Esempio n. 20
0
 def test_unpack(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     for k in OPTS:
         if not k in ['data']: self.assertEqual(getattr(cp, k), OPTS[k])
     self.assertRaises(ValueError, cp.unpack, BAD_PACKET1)
Esempio n. 21
0
 def test_unpack(self):
     cp = CorrPacket()
     cp.unpack(PACKET)
     for k in OPTS:
         if not k in ['data']: self.assertEqual(getattr(cp,k), OPTS[k])
     self.assertRaises(ValueError, cp.unpack, BAD_PACKET1)
Esempio n. 22
0
    'engine_id':59,
    'timestamp':64, 
    'heapoff':128,
    'packetlen':8,
    'packetcount':1,
    'currerr':0, 
    'heaplen':8, 
    'data':(55,22),
}

PACKET = struct.pack('>HHHH', PKT_ID, 3, 0, OPTS['n_options']) + \
    struct.pack('>HHHH', 50, OPTS['instrument_id'], OPTS['instance_id'], OPTS['engine_id']) + \
    struct.pack('>HHI', 3, 0, OPTS['timestamp']) + \
    struct.pack('>HHI', 52, 0, OPTS['currerr']) + \
    struct.pack('>H', 51) + bitstring.BitString(uintbe=OPTS['packetlen'], length=24).bytes + \
    bitstring.BitString(uintbe=OPTS['packetlen'], length=24).bytes + \
    struct.pack('>HHI', 5, 0, OPTS['heapoff']) + \
    struct.pack('>HHI', 53, 0, 0) + \
    struct.pack('>II',  *OPTS['data'])

cp = CorrPacket()
cp.unpack_header(PACKET)
cp.unpack_data(PACKET[cp.header_size():], len(PACKET[cp.header_size():]))
print "header:",cp.header_size()
print "data:",len(cp.get_data())
print "data size:",cp.size()
print "instance_id",cp.instance_id
print "instrument_id",cp.instrument_id
print "engine_id",cp.engine_id
print struct.unpack('>II', cp.get_data())