def setUp(self): self.fst_three_rows = StringIO( '1009476,1,1_IDC_ML ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.90,0.30,1,IDC ,ML ,IDC' '\n' '1009476,1,1_IDC_mb ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.70,0.20,3,IDC ,mb ,IDC' '\n' '1009476,1,1_IDC_mb ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.70,0.20,3,IDC ,mb ,IDC') self.fst_exp_entry = {'azimuthGap': 156.0, 'solutionAgency': 'IDC', 'mag_agency': 'IDC', 'month': 9, 'minDistance': 7.05, 'depthError': None, 'second': 37.11, 'year': 2002, 'Latitude': 25.4812, 'time_rms': 0.95, 'originID': '4644028', 'phases': 6, 'solutionKey': '1', 'solutionDesc': '1_IDC_ML', 'timeError': 1.29, 'solutionID': '4644028', 'semiMajor90': 61.5, 'semiMinor90': 18.6, 'Longitude': 97.9598, 'errorAzimuth': 73.0, 'maxDistance': 59.32, 'day': 3, 'minute': 37, 'mag_type': 'ML', 'magStations': 1, 'hour': 21, 'stations': None, 'depth': 0.0, 'magnitude': 3.9, 'eventKey': '1009476', 'magnitudeError': 0.3} self.reader = CsvEqCatalogueReader(self.fst_three_rows) self.convert = Converter() self.reader_gen = self.reader.read(self.convert) self.maxDiff = None
class EqCatalogueReaderTestCase(unittest.TestCase): def setUp(self): self.fst_three_rows = StringIO( '1009476,1,1_IDC_ML ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.90,0.30,1,IDC ,ML ,IDC' '\n' '1009476,1,1_IDC_mb ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.70,0.20,3,IDC ,mb ,IDC' '\n' '1009476,1,1_IDC_mb ,4644028,2002,9,3,21,37,37.110,1.290,0.950,' '25.4812,97.9598,61.5,18.6,73,0.0,,6,,156,7.0500,59.3200,4644028,' '3.70,0.20,3,IDC ,mb ,IDC') self.fst_exp_entry = {'azimuthGap': 156.0, 'solutionAgency': 'IDC', 'mag_agency': 'IDC', 'month': 9, 'minDistance': 7.05, 'depthError': None, 'second': 37.11, 'year': 2002, 'Latitude': 25.4812, 'time_rms': 0.95, 'originID': '4644028', 'phases': 6, 'solutionKey': '1', 'solutionDesc': '1_IDC_ML', 'timeError': 1.29, 'solutionID': '4644028', 'semiMajor90': 61.5, 'semiMinor90': 18.6, 'Longitude': 97.9598, 'errorAzimuth': 73.0, 'maxDistance': 59.32, 'day': 3, 'minute': 37, 'mag_type': 'ML', 'magStations': 1, 'hour': 21, 'stations': None, 'depth': 0.0, 'magnitude': 3.9, 'eventKey': '1009476', 'magnitudeError': 0.3} self.reader = CsvEqCatalogueReader(self.fst_three_rows) self.convert = Converter() self.reader_gen = self.reader.read(self.convert) self.maxDiff = None def tearDown(self): self.fst_three_rows.close() def test_read_eq_entry(self): first_entry = self.reader_gen.next() self.assertEqual(self.fst_exp_entry, first_entry) def test_number_generated_entries(self): exp_num_gen_entries = 3 num_entries = 0 for num_entries, _ in enumerate(self.reader_gen, start=1): print _ self.assertEqual(exp_num_gen_entries, num_entries)