def test_file_packet(self): """ * Write a file * Convert to packet * Extract packet * Compare """ test_string = 'This is a test file for packetcommslib' filename = os.path.join(TEMP_DIR,'file_packet_test.txt') with open(filename,'w') as fid: fid.write(test_string) label = 'File packet test' file_packet = pcl.makeFilePacket(label,filename) #print('file_packet = ',file_packet) (label_out,(filename_out,file_contents)) = pcl.extractPacket(file_packet) self.assertTrue( label_out==label and file_contents.decode()==test_string and filename_out==filename)
def test_text_string_packet(self): """ Create and extract text packets using string format """ # Input data data_label = "/Data/New_place" text = "Some text to send" # Packet text_packet = pcl.makeTextPacket(data_label,text) # Extracted packet (label,text_out) = pcl.extractPacket(text_packet) self.assertTrue(label==data_label and text_out==text)
def test_text_list_packet(self): """ Create and extract text packets using list format """ # Input data data_label = "/Data/New_place" text_list = ["Sending","some","text","in","a","list"] # Packet text_list_packet = pcl.makeTextPacket(data_label,text_list) # Extracted data (list_label,text_list_out) = pcl.extractPacket(text_list_packet) self.assertTrue(list_label==data_label and text_list_out==text_list)
def test_array_packet(self): """ Create and extract array packet """ # Make an array packet # ----------------------- data_label ='array packet' array = np.array([[1,2,3],[4,5,6]]).transpose() columns = ['col1','col2'] packet = pcl.makeArrayPacket(data_label,array,columns) (label,array_out) = pcl.extractPacket(packet) print("Packet: %s" % label) print("Array :") print(array_out) self.assertTrue(label==data_label and all(array_out==array))
#================================================================= #%% Array Packet making/extracting test #================================================================= import sys, imp sys.path.append( '/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk') import packetcommslib as pcl # Make an array packet # ----------------------- array = np.array([[1, 2, 3], [4, 5, 6]]).transpose() columns = ['col1', 'col2'] packet = pcl.makeArrayPacket('label', array, columns) (label, array_out) = pcl.extractPacket(packet) print("Packet: %s" % label) print("Array :") print(array_out) #================================================================= #%% Text Packet making/extracting test #================================================================= import sys, imp sys.path.append( '/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk') import packetcommslib as pcl data_label = "/Data/New_place"