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_normalized_na_fields(self): """ Check that 'na' values are normalized to empty strings. """ row = [ 'SS CYG', '2450702.1234', '<11.1', 'na', 'na', 'na', 'na', 'na', ] data = VisualFormatReader.row_to_dict(row) expected_data = { 'name': 'SS CYG', 'date': '2450702.1234', 'magnitude': '<11.1', 'comment_code': '', 'comp1': '', 'comp2': '', 'chart': '', 'notes': '', } self.assertEqual(data, expected_data)
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_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_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_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_roundtrip_row(self): """ Check that a data row onverted to dict and back to row is the same. """ row = [ 'SS CYG', '2450702.1234', '<11.1', 'na', '110', '113', '070613', 'This is a test', ] data = VisualFormatReader.row_to_dict(row) output_row = VisualFormatWriter.dict_to_row(data) self.assertEqual(output_row, row)
def test_roundtrip_dict(self): """ Check that observation converted to row and back to dict is the same. """ data = { 'name': 'SS CYG', 'date': '2450702.1234', 'magnitude': '<11.1', 'comment_code': '', 'comp1': '110', 'comp2': '113', 'chart': '070613', 'notes': 'This is a test', } row = VisualFormatWriter.dict_to_row(data) output_data = VisualFormatReader.row_to_dict(row) self.assertEqual(output_data, data)
def test_roundtrip_row(self): """ Check that a data row onverted to dict and back to row is the same. """ row = [ 'SS CYG', '2450702.1234', '<11.1', 'na', '110', '113', '070613', 'This is a test', ] data = VisualFormatReader.row_to_dict(row) output_row = VisualFormatWriter.dict_to_row(data) self.assertEqual(output_row, row)
def test_roundtrip_dict(self): """ Check that observation converted to row and back to dict is the same. """ data = { 'name': 'SS CYG', 'date': '2450702.1234', 'magnitude': '<11.1', 'comment_code': '', 'comp1': '110', 'comp2': '113', 'chart': '070613', 'notes': 'This is a test', } row = VisualFormatWriter.dict_to_row(data) output_data = VisualFormatReader.row_to_dict(row) self.assertEqual(output_data, data)
def test_normalized_na_fields(self): """ Check that 'na' values are normalized to empty strings. """ row = [ 'SS CYG', '2450702.1234', '<11.1', 'na', 'na', 'na', 'na', 'na', ] data = VisualFormatReader.row_to_dict(row) expected_data = { 'name': 'SS CYG', 'date': '2450702.1234', 'magnitude': '<11.1', 'comment_code': '', 'comp1': '', 'comp2': '', 'chart': '', 'notes': '', } self.assertEqual(data, expected_data)
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')
def test_observer_code(self): """ Check that observer code matches header information. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.observer_code, 'XYZ')
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_software(self): """ Check that SOFTWARE header is read correctly. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.software, 'Notepad')
def test_delimiter(self): """ Check that the delimiter character is read correctly. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.delimiter, ',')
def test_obstype(self): """ Check that observation type matches data in header. """ reader = VisualFormatReader(self.fp) self.assertEqual(reader.obstype, 'Visual')