def test_write(self): random.seed(1) randnum = lambda: random.uniform(-1, 1) ** random.randint(-20, 20) data = opm.Data( state_vector=self.valid_state_vector, spacecraft_parameters=self.valid_spacecraft_parameters, keplerian_elements=self.valid_keplerian_elements, covariance_matrix=self.valid_covariance_matrix, maneuver_parameters=self.valid_maneuver_parameters) user_defined = OrderedDict() user_defined['TEST'] = randnum() user_defined['TEST2'] = 'String' opm_obj = opm.Opm( header=self.valid_header, metadata=self.valid_metadata, data=data, user_defined=user_defined) file_hash = hashlib.sha256() with TemporaryFile(mode='w+') as f: opm_obj.write(f) f.seek(0) for line in f.read().splitlines(): file_hash.update(line.encode('utf-8')) valid_hash = hashlib.sha256() with open(str(Path('.', 'odmpy', 'tests', 'valid.opm.txt')), 'r') as f: for line in f.read().splitlines(): valid_hash.update(line.encode('utf-8')) self.assertEqual(file_hash.hexdigest(), valid_hash.hexdigest())
def test_output(self): """Fail test if output doesn't match previously created file.""" random.seed(1) randnum = lambda: random.uniform(-1, 1) ** random.randint(-20, 20) data = opm.Data( state_vector=self.valid_state_vector, spacecraft_parameters=self.valid_spacecraft_parameters, keplerian_elements=self.valid_keplerian_elements, covariance_matrix=self.valid_covariance_matrix, maneuver_parameters=self.valid_maneuver_parameters) user_defined = OrderedDict() user_defined['TEST'] = randnum() user_defined['TEST2'] = 'String' opm_obj = opm.Opm( header=self.valid_header, metadata=self.valid_metadata, data=data, user_defined=user_defined) output_hash = hashlib.sha256() for line in opm_obj.output(): output_hash.update(line.encode('utf-8')) with open(str(Path('.', 'odmpy', 'tests', 'test.opm.txt')), 'w') as f: opm_obj.write(f) valid_hash = hashlib.sha256() with open(str(Path('.', 'odmpy', 'tests', 'valid.opm.txt')), 'r') as f: for line in f.read().splitlines(): valid_hash.update(line.encode('utf-8')) self.assertEqual(output_hash.hexdigest(), valid_hash.hexdigest())
def test_invalid_multiple_blocks(self): sv = self.valid_data.state_vector.block sp = self.valid_spacecraft_parameters ke = self.valid_keplerian_elements cm = self.valid_covariance_matrix data = opm.Data( state_vector=[sv, sv], spacecraft_parameters=sp, keplerian_elements=ke, covariance_matrix=cm, ) with self.assertRaises(ValueError): data.validate_blocks() data = opm.Data( state_vector=sv, spacecraft_parameters=[sp, sp], keplerian_elements=ke, covariance_matrix=cm, ) with self.assertRaises(ValueError): data.validate_blocks() data = opm.Data( state_vector=sv, spacecraft_parameters=sp, keplerian_elements=[ke, ke], covariance_matrix=cm, ) with self.assertRaises(ValueError): data.validate_blocks() data = opm.Data( state_vector=sv, spacecraft_parameters=sp, keplerian_elements=ke, covariance_matrix=[cm, cm], ) with self.assertRaises(ValueError): data.validate_blocks()
def test_missing_state_vector(self): data = self.valid_data with self.assertRaises(ValueError): data.state_vector = None data = opm.Data( state_vector=None ) with self.assertRaises(opm.MissingBlockError): data.validate_blocks()
def setUp(self): # Create dummy sections with valid data. random.seed(1) randnum = lambda: random.uniform(-1, 1) ** random.randint(-20, 20) self.valid_header = opm.Header( originator='ESA', opm_version='2.0', creation_date=datetime(2011,3,1,1,2,3), comment='Test comment\nline 2' ) self.valid_metadata = opm.Metadata( object_name='Dragon', object_id='2010-026A', center_name='EARTH', ref_frame=opm.RefFrame.GCRF, time_system=opm.TimeSystem.UTC ) self.valid_state_vector = opm.DataBlockStateVector( epoch=datetime(2011,2,24,1,2,3), x=randnum(), y=randnum(), z=randnum(), x_dot=randnum(), y_dot=randnum(), z_dot=randnum() ) self.valid_spacecraft_parameters = opm.DataBlockSpacecraftParameters( mass=randnum(), solar_rad_area=randnum(), solar_rad_coeff=randnum(), drag_area=randnum(), drag_coeff=randnum() ) self.valid_keplerian_elements = opm.DataBlockKeplerianElements( semi_major_axis=randnum(), eccentricity=randnum(), inclination=randnum(), ra_of_asc_node=randnum(), arg_of_pericenter=randnum(), true_anomaly=randnum(), gm=randnum() ) self.valid_covariance_matrix = opm.DataBlockCovarianceMatrix( cx_x=randnum(), cy_x=randnum(), cy_y=randnum(), cz_x=randnum(), cz_y=randnum(), cz_z=randnum(), cx_dot_x=randnum(), cx_dot_y=randnum(), cx_dot_z=randnum(), cx_dot_x_dot=randnum(), cy_dot_x=randnum(), cy_dot_y=randnum(), cy_dot_z=randnum(), cy_dot_x_dot=randnum(), cy_dot_y_dot=randnum(), cz_dot_x=randnum(), cz_dot_y=randnum(), cz_dot_z=randnum(), cz_dot_x_dot=randnum(), cz_dot_y_dot=randnum(), cz_dot_z_dot=randnum() ) self.valid_maneuver_parameters = opm.DataBlockManeuverParameters( man_epoch_ignition=datetime(2014, 11, 12, 13, 14, 15, 999999), man_duration=randnum(), man_delta_mass=-randnum(), man_ref_frame=opm.RefFrame.RSW, man_dv_1=randnum(), man_dv_2=randnum(), man_dv_3=randnum()) self.valid_data = opm.Data( state_vector=self.valid_state_vector )