def setUp(self): TestBase.setUp(self) # Create a temporary directory self.test_dir = tempfile.mkdtemp() self.n = 100 self.titles = ['Array 1', 'Array 2', 'Array 3'] self.header = 'A header line' ##### Now generate output for testing #### filename = os.path.join(self.test_dir, 'test.dat') self.data = np.random.random((self.n, len(self.titles))) header = [self.header, '%d' % len(self.titles)] for ln in self.titles: header.append(ln + '\n') header = '\n'.join(header) np.savetxt(filename, self.data, delimiter=' ', header=header, comments='') # Set up the reader reader = GSLibReader() reader.AddFileName(filename) # Perform the read reader.Update() self.HEADER = reader.get_file_header() self.TABLE = reader.GetOutput()
def test_bad_file(self): """`GSLibReader`: check handling of bad input file""" filename = os.path.join(self.test_dir, 'test_bad.dat') header = ['A header line', 'Bad number of titles'] for ln in self.titles: header.append(ln + '\n') header = '\n'.join(header) np.savetxt(filename, self.data, delimiter=' ', header=header, comments='') # Set up the reader reader = GSLibReader() reader.AddFileName(filename) # Perform the read reader.Update() self.assertTrue(reader.error_occurred())
def AddFileName(self, filename): GSLibReader.AddFileName(self, filename)