def test_buffer_export(self): with TmpDir() as dir_: filename = os.path.join(dir_, "export.fcs") text_start = 256 fseg = TextSegment( self.data.shape[0], self.long_channels, self.channels, self.data.max(axis=0), text_start=text_start, ) header = HeaderSegment(text_start, fseg.text_end, fseg.data_start, fseg.data_end) fcs = Fcs(self.data, self.long_channels, self.channels) with open(filename, "wb") as fp: fcs.export(fp) with open(filename, "rb") as fp: assert fp.read(58).decode("UTF-8") == header.to_string() fp.seek(text_start) assert (fp.read(header.text_end - fseg.text_start + 1).decode("UTF-8").strip() == fseg.to_string()) fp.seek(fseg.data_start) dseg = DataSegment.from_string( fp.read(fseg.data_end - fseg.data_start + 1), fseg.datatype, len(fseg.pnn), fseg.tot, fseg.endian, ) assert np.array_equal(dseg.values, self.data)
def test_write_text_segment(self): with TmpDir() as dir_: filename = os.path.join(dir_, "export.fcs") fcs = Fcs(self.data, self.long_channels, self.channels) fcs.export(filename) fseg = TextSegment( self.data.shape[0], self.long_channels, ["w", "x", "y", "z"], self.data.max(axis=0), text_start=256, ) Fcs.write_text_segment(filename, fseg) tseg = Fcs.read_text_segment(filename) assert tseg.pns == ["w", "x", "y", "z"]