def test_missing_obstype(self): """ Check that Visual is assumed obstype when OBSTYPE header is missing. """ self._drop_header('OBSTYPE') reader = VisualFormatReader(self.fp) self.assertEqual(reader.obstype, 'Visual')
def test_row_count(self): """ Check that number of records in initial input file is exactly 1. """ reader = VisualFormatReader(self.fp) rows = [row for row in reader] self.assertEqual(len(rows), 1)
def test_missing_delimiter(self): """ Check that in case of missing delimiter, a comma is assumed. """ self._drop_header('DELIM') reader = VisualFormatReader(self.fp) self.assertEqual(reader.delimiter, ',')
def test_missing_software(self): """ Check that SOFTWARE header is not required. """ self._drop_header('SOFTWARE') reader = VisualFormatReader(self.fp) self.assertEqual(reader.software, '')
def test_missing_date_format(self): """ Check that a missing DATE header raises an exception. """ self._drop_header('DATE') with self.assertRaises(FormatException): reader = VisualFormatReader(self.fp)
def test_missing_observer_code(self): """ Check that a missing OBSCODE header raises an exception. """ self._drop_header('OBSCODE') with self.assertRaises(FormatException): reader = VisualFormatReader(self.fp)
def test_missing_type(self): """ Check that a missing TYPE header raises an exception. """ self._drop_header('TYPE') with self.assertRaises(FormatException): reader = VisualFormatReader(self.fp)
def test_row_dictionary(self): """ Check that an observation is returned as a dictionary of values. """ reader = VisualFormatReader(self.fp) rows = [row for row in reader] observation = rows[0] self.assertEqual(observation['name'], 'SS CYG') self.assertEqual(observation['comp1'], '110') self.assertEqual(observation['comp2'], '113')
def test_row_count_duplicated(self): """ Check that there are exactly 2 records after duplicating the last line. """ # duplicate the last line self.lines.append(self.lines[-1]) self.fp = StringIO("\n".join(self.lines)) reader = VisualFormatReader(self.fp) rows = [row for row in reader] self.assertEqual(len(rows), 2)
def test_obstype(self): """ Check that observation type matches data in header. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.obstype, 'Visual')
def test_delimiter(self): """ Check that the delimiter character is read correctly. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.delimiter, ',')
def test_software(self): """ Check that SOFTWARE header is read correctly. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.software, 'Notepad')
def test_date_format(self): """ Check that the date format is read correctly. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.date_format, 'JD')
def test_observer_code(self): """ Check that observer code matches header information. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.observer_code, 'XYZ')
def test_bytes_input(self): self.fp = BytesIO("\n".join(self.lines).encode('utf-8')) reader = VisualFormatReader(self.fp) self.assertEqual(reader.observer_code, 'XYZ')