def write(self, format, path=None, return_string=None, *args): """ Serialize and write ``Run`` instances. Serialize ``Run`` instance using the stated ``format``. Args: format (str): The output format: Currently only "pickle". path (str): Path to output file .. todo:: Write checks for ``format`` and ``path``. """ if format == 'pickle': with open(path, 'wb') as fh: pickle.dump(self, fh) elif format == 'csv': output = run_io.serialize_run_for_r(self) else: raise Exception('Format is unknown: {}'.format(format)) if path: with open(path, 'w') as fh: fh.write(output) if return_string: return output
def test_write_run_csv_insulin(path_run): test_run = run.Run.create(origin="config", path=os.path.join(path_run, TEST_RUN_CONFIG_SIRNA)) test_serial = run_io.serialize_run_for_r(test_run) assert type(test_serial) == list assert len(test_serial[0]) == len(test_serial[1])