def test_file(self): hfile = Hfile(hostname, port, path, mode='w') self.assertTrue(hfile.write(data)) hfile.close() hfile = Hfile(hostname, port, path) self.assertTrue(hfile.seek(10)) self.assertEqual(hfile.tell(), 10) hfile.seek(0) read_data = hfile.read() self.assertEqual(read_data, data) hfile.close()
def test_file(self): hfile = Hfile(hostname, port, path, mode='w') self.assertTrue(hfile.write(data)) hfile.close() hfile = Hfile(hostname, port, path) self.assertTrue(hfile.seek(10)) self.assertEqual(hfile.tell(), 10) hfile.seek(0) read_data = hfile.read() self.assertEqual(read_data, data) hfile.close()
hfile.write(line) # And close them. fh.close() hfile.close() # Let's read local_path into memory for comparison. motd = open(local_path).read() # Now let's read the data back hfile = Hfile(hostname, port, hdfs_path) # With an iterator data_read_from_hdfs = '' for line in hfile: data_read_from_hdfs += line print motd == data_read_from_hdfs # All at once data_read_from_hdfs = hfile.read() print motd == data_read_from_hdfs hfile.close() # Hopefully you have enough info to get started! from hdfs.hfilesystem import Hfilesystem hfs = Hfilesystem(hostname, port) print hfs.getHosts(hdfs_path, 0, 1)