def test_save_cansas_v1_0(self): xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) self.assertTrue(xmlreader.validate_xml()) reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_0) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_0) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data(cansasreader[i]) reader_generic.save(self.write_1_0_filename, dataloader[i], None) reader2 = Reader() self.assertTrue(os.path.isfile(self.write_1_0_filename)) return_data = reader2.read(self.write_1_0_filename) written_data = return_data[0] xmlreader = XMLreader(self.write_1_0_filename, self.schema_1_0) self.assertTrue(xmlreader.validate_xml()) self._check_data(written_data) if os.path.isfile(self.write_1_0_filename): os.remove(self.write_1_0_filename)
def test_save_cansas_v1_0(self): filename = "isis_1_0_write_test.xml" xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) valid = xmlreader.validate_xml() self.assertTrue(valid) reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_0) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_0) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data(cansasreader[i]) reader_generic.save(filename, dataloader[i], None) reader2 = Reader() return_data = reader2.read(filename) written_data = return_data[0] xmlwrite = XMLreader(filename, self.schema_1_0) valid = xmlreader.validate_xml() self.assertTrue(valid) self._check_data(written_data)
def save_files(self, evt=None): """ Automatically save the sliced data to file. :param evt: Event that triggered the call to the method """ # Events triggered after this event pass other events to wx that are # necessary before this event is called. If this is the first time # reaching this event, send it to the end of the wx event queue if self.iter < 2: clone = evt.Clone() wx.PostEvent(self, clone) self.iter += 1 return if evt is None: return # Start definitions writer = Reader() data_dic = {} append = evt.append_to_name names = [] f_name_list = [] f_path_list = [] # Get list of 2D data names for saving for f_name in evt.file_list: names.append(f_name.data2D.label) # Find the correct plots to save for key, plot in self.main_window.plot_panels.items(): if not hasattr(plot, "data2D"): for item in plot.plots: base = item.replace(CONVERT_DICT[evt.type], "") if base in names: data_dic[item] = plot.plots[item] # Save files as Text for item, data1d in data_dic.items(): base = '.'.join(item.split('.')[:-1]) file_name = base + append + ".txt" save_to = evt.path + "\\" + file_name writer.write(save_to, data1d) f_path_list.append(save_to) f_name_list.append(file_name) # Load files into GUI for item in f_path_list: self.main_window.load_data(item) # Send to fitting self.send_to_fitting(evt.fit, f_name_list)
def setUp(self): self.loader = Loader() self.cansas_reader = Reader() self.xml_reader = XMLreader() self.xml_valid = find("cansas_test_modified.xml") self.xml_invalid = find("cansas_test.xml") self.cansas1d_badunits = find("cansas1d_badunits.xml") self.cansas1d = find("cansas1d.xml") self.cansas1d_slit = find("cansas1d_slit.xml") self.cansas1d_units = find("cansas1d_units.xml") self.cansas1d_notitle = find("cansas1d_notitle.xml") self.isis_1_0 = find("ISIS_1_0.xml") self.isis_1_1 = find("ISIS_1_1.xml") self.isis_1_1_notrans = find("ISIS_1_1_notrans.xml") self.isis_1_1_doubletrans = find("ISIS_1_1_doubletrans.xml") self.schema_1_0 = find("cansas1d_v1_0.xsd") self.schema_1_1 = find("cansas1d_v1_1.xsd") self.write_1_0_filename = find("isis_1_0_write_test.xml") self.write_1_1_filename = find("isis_1_1_write_test.xml") self.write_filename = find("write_test.xml")
def test_cansas_xml(self): xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) valid = xmlreader.validate_xml() xmlreader.set_processing_instructions() self.assertTrue(valid) reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_1) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_1) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data_1_1(dataloader[i]) self._check_data(cansasreader[i]) self._check_data_1_1(cansasreader[i]) reader_generic.save(self.write_1_1_filename, dataloader[i], None) reader2 = Loader() self.assertTrue(os.path.isfile(self.write_1_1_filename)) return_data = reader2.load(self.write_1_1_filename) written_data = return_data[0] self._check_data(written_data) if os.path.isfile(self.write_1_1_filename): os.remove(self.write_1_1_filename)
def test_cansas_xml(self): filename = "isis_1_1_write_test.xml" xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) valid = xmlreader.validate_xml() xmlreader.set_processing_instructions() self.assertTrue(valid) fo = open(self.isis_1_1) str = fo.read() reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_1) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_1) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data_1_1(dataloader[i]) self._check_data(cansasreader[i]) self._check_data_1_1(cansasreader[i]) reader_generic.save(filename, dataloader[i], None) fo = open(filename) str = fo.read() reader2 = Loader() return_data = reader2.load(filename) written_data = return_data[0] self._check_data(written_data)