def test3list_unseq(self): """catalogs.hermes read_hermesVR_velocities list unseq""" unseq = [2455351, 2455425, 2455620] # return all data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=False, unseq=unseq) msg = 'Should return 2 lines per unseq provided\nGot:\t\t{:}\nExpected:\t{:}'.format( \ data['unseq'], unseq+unseq) self.assertEqual(len(data['unseq']), 6, msg=msg) for sq in unseq: self.assertTrue(sq in data['unseq'], msg=msg) self.assertEqual(len(np.where(data['unseq']==sq)[0]), 2, msg=msg) # return unique data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, unseq=unseq) msg = 'Should return 1 lines per unseq provided\nGot:\t\t{:}\nExpected:\t{:}'.format( \ data['unseq'], unseq) self.assertEqual(len(data['unseq']), 3, msg=msg) for sq in unseq: self.assertTrue(sq in data['unseq'], msg=msg) self.assertEqual(len(np.where(data['unseq']==sq)[0]), 1, msg=msg) # check returned order unseq = [2455937, 2455620, 2455425] data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, unseq=unseq) msg = 'The returned order should be the same as the provided list' \ +'\nGot:\t\t{:}\nExpected:\t{:}'.format(data['unseq'], unseq) for i, sq in enumerate(unseq): self.assertEqual(data['unseq'][i], sq, msg=msg)
def test2unique(self): """catalogs.hermes read_hermesVR_velocities unique output""" # return the earliest added lines data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, return_latest=False) msg = 'Amount of data not correct, expected 9 lines, got {:}'.format( len(data)) self.assertEqual(len(data), 9, msg=msg) msg = 'All returned sequence numbers should be unique!, got: {:}'.format( data['unseq']) for sq in set(self.unseq): self.assertTrue(len(np.where(data['unseq'] == sq)) == 1, msg=msg) msg = 'When return_latest == False, Should return the first added lines, got the lastest!' self.assertEqual(data['vrad'][data['unseq'] == 2455351][0], -64.6618, msg=msg) # return the lastest added lines msg = 'When return_latest == True, Should return the latest added lines, got the first!' data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, return_latest=True) self.assertEqual(data['vrad'][data['unseq'] == 2455351][0], -66.5509, msg=msg)
def test4list_object(self): """catalogs.hermes read_hermesVR_velocities list object""" object = ['J1736+2806', 'EC11031-1348'] unseq = [2455617, 2455649, 2455659, 2455665, 2455937] # return all objects data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=False, object=object) msg = 'Should return 2 different object\nGot:\t\t{:}\nExpected:\t{:}'.format( \ set(data['object']), object) self.assertEqual(len(set(data['object'])), 2, msg=msg) for ob in object: self.assertTrue(ob in data['object'], msg=msg) self.assertFalse('BD+29.3070' in data['object'], msg=msg) # return all lines belonging to those objects msg = 'Should return 5 lines in total\nGot:\t\t{:}\nExpected:\t{:}'.format( \ set(data['unseq']), unseq) self.assertEqual(len(data['unseq']), 5, msg=msg) for sq in unseq: self.assertTrue(sq in data['unseq'], msg=msg) # return in the correct order object = [ 'J1736+2806', 'J1736+2806', 'J1736+2806', 'EC11031-1348', 'EC11031-1348' ] msg = 'Should return the objects in the correct order' \ +'\nGot:\t\t{:}\nExpected:\t{:}'.format(data['object'], object) for i, ob in enumerate(object): self.assertEqual(data['object'][i], ob, msg=msg)
def test4list_object(self): """catalogs.hermes read_hermesVR_velocities list object""" object = ['J1736+2806', 'EC11031-1348'] unseq = [2455617, 2455649, 2455659, 2455665, 2455937] # return all objects data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=False, object=object) msg = 'Should return 2 different object\nGot:\t\t{:}\nExpected:\t{:}'.format( \ set(data['object']), object) self.assertEqual(len(set(data['object'])), 2, msg=msg) for ob in object: self.assertTrue(ob in data['object'], msg=msg) self.assertFalse('BD+29.3070' in data['object'], msg=msg) # return all lines belonging to those objects msg = 'Should return 5 lines in total\nGot:\t\t{:}\nExpected:\t{:}'.format( \ set(data['unseq']), unseq) self.assertEqual(len(data['unseq']), 5, msg=msg) for sq in unseq: self.assertTrue(sq in data['unseq'], msg=msg) # return in the correct order object = ['J1736+2806','J1736+2806','J1736+2806','EC11031-1348','EC11031-1348'] msg = 'Should return the objects in the correct order' \ +'\nGot:\t\t{:}\nExpected:\t{:}'.format(data['object'], object) for i, ob in enumerate(object): self.assertEqual(data['object'][i], ob, msg=msg)
def test2unique(self): """catalogs.hermes read_hermesVR_velocities unique output""" # return the earliest added lines data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, return_latest=False) msg = 'Amount of data not correct, expected 9 lines, got {:}'.format(len(data)) self.assertEqual(len(data), 9, msg=msg) msg = 'All returned sequence numbers should be unique!, got: {:}'.format(data['unseq']) for sq in set(self.unseq): self.assertTrue(len(np.where(data['unseq'] == sq)) == 1, msg=msg) msg = 'When return_latest == False, Should return the first added lines, got the lastest!' self.assertEqual(data['vrad'][data['unseq'] == 2455351][0], -64.6618, msg=msg) # return the lastest added lines msg = 'When return_latest == True, Should return the latest added lines, got the first!' data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=True, return_latest=True) self.assertEqual(data['vrad'][data['unseq'] == 2455351][0], -66.5509, msg=msg)
def test1read_everything(self): """catalogs.hermes read_hermesVR_velocities basic read""" data = hermes.read_hermesVR_velocities(filename=self.testfile, unique=False) msg = 'Not all data read from file, expected 13 lines, got {:}'.format(len(data)) self.assertEqual(len(data), 13, msg=msg) msg = 'Not all expected unseq are present in data, expected:' \ +'\n{:}\ngot:\n{:}'.format(set(self.unseq), set(data['unseq'])) for sq in self.unseq: self.assertTrue(sq in data['unseq'], msg=msg) msg = 'Not all expected objects are present, expected:' \ +'\n{:}\ngot:\n{:}'.format(self.object, set(data['object'])) for obj in self.object: self.assertTrue(obj in data['object'], msg=msg)