Ejemplo n.º 1
0
 def test_add_values_two_records(self):
     """ Test outputting csv file of two records and one topic. """
     topic = u'BE'
     data_folder = os.path.join(os.getcwd(), 'tests/data')
     source = os.path.join(data_folder, 'split/two_objects.dat')
     out = os.path.join(data_folder, 'out')
     split_file = os.path.join(out, topic + '.csv')
     file = open(split_file, 'w')
     writer = csv.writer(file)
     split.add_dat_values(topic, source, writer)
     file.close()
     number_lines = sum(1 for line in open(split_file))
     self.assertEquals(number_lines, 2)
Ejemplo n.º 2
0
 def test_add_line_break(self):
     """ Test outputting csv file of records with value containing line break. """
     topic = u'TF'
     data_folder = os.path.join(os.getcwd(), 'tests/data')
     source = os.path.join(data_folder, 'split/line_break.dat')
     out = os.path.join(data_folder, 'out')
     split_file = os.path.join(out, topic + '.csv')
     file = open(split_file, 'w')
     writer = csv.writer(file)
     split.add_dat_values(topic, source, writer)
     file.close()
     number_lines = sum(1 for line in open(split_file))
     self.assertEquals(number_lines, 2)
Ejemplo n.º 3
0
 def test_unicode_in_csv(self):
     """ Test unicode character in output csv. """
     topic = 'BE'
     data_folder = os.path.join(os.getcwd(), 'tests/data')
     dat_file = os.path.join(data_folder, 'split/unicode.dat')
     out = os.path.join(data_folder, 'out')
     csv_file = os.path.join(out, topic + '.csv')
     file = open(csv_file, 'w')
     writer = csv.writer(file)
     split.add_dat_values(topic, dat_file, writer)
     file.close()
     character_byte_array = []
     with open(dat_file, "rb") as f:
         byte = f.read(1)
         while byte != b'':
             character_byte_array.append(byte)
             byte = f.read(1)
     check_byte_array = [
         b'B', b'\xc3', b'\x89', b' ', b'\xc3', b'\xbe', b'\r', b'\n', b'I',
         b'\xc3', b'\x91', b' ', b'\xc2', b'\xae', b'\r', b'\n', b'*', b'*',
         b'\r', b'\n'
     ]
     self.assertEquals(character_byte_array, check_byte_array)