コード例 #1
0
    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())
コード例 #2
0
    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())
コード例 #3
0
    def test_multiple_maneuver_parameters(self):
        """There can be one or more maneuver parameters blocks"""
        mp1 = opm.DataBlockManeuverParameters(
            man_epoch_ignition=datetime.utcnow(),
            man_duration=1,
            man_delta_mass=1,
            man_ref_frame=opm.RefFrame.TNW,
            man_dv_1=1,
            man_dv_2=0,
            man_dv_3=0
        )

        mp2 = opm.DataBlockManeuverParameters(
            man_epoch_ignition=datetime.utcnow(),
            man_duration=2,
            man_delta_mass=1,
            man_ref_frame=opm.RefFrame.TNW,
            man_dv_1=1,
            man_dv_2=1,
            man_dv_3=1
        )

        sp = self.valid_spacecraft_parameters

        data = self.valid_data
        data.maneuver_parameters = mp1
        data.spacecraft_parameters = sp

        data.validate_blocks()

        opm.Opm(header=self.valid_header,
                metadata=self.valid_metadata,
                data=data)

        data.maneuver_parameters = [mp1, mp2]
        data.validate_blocks()

        opm.Opm(header=self.valid_header,
                metadata=self.valid_metadata,
                data=data)
コード例 #4
0
    def test_empty_opm_version(self):
        header = opm.Header(originator='ESA', opm_version='')

        # Check that validation fails

        self.assertRaises(ValueError, header.validate_keywords)

        # Check that OPM cannot be constructed from invalid header

        with self.assertRaises(ValueError):
            opm.Opm(header=header,
                    metadata=self.valid_metadata,
                    data=self.valid_data)
コード例 #5
0
    def test_data_block_missing_spacecraft_parameters(self):
        """If maneuver parameters are used, spacecraft parameters block
        is mandatory.
        """
        mp = self.valid_maneuver_parameters

        data = self.valid_data
        data.maneuver_parameters = mp
        with self.assertRaises(ValueError):
            data.validate_blocks()

        with self.assertRaises(ValueError):
            opm.Opm(header=self.valid_header,
                    metadata=self.valid_metadata,
                    data=data)
コード例 #6
0
    def test_empty_object_id(self):
        # Take valid metadata object, and set invalid object_id
        metadata = self.valid_metadata
        metadata.object_id = ''

        # Check that validation fails

        self.assertRaises(ValueError, metadata.validate_keywords)

        # Check that OPM cannot be constructed from invalid header

        with self.assertRaises(ValueError):
            opm.Opm(header=self.valid_header,
                    metadata=metadata,
                    data=self.valid_data)
コード例 #7
0
    def test_invalid_object_id(self):
        # Take valid metadata object, and set invalid object_id
        # Note that the validator itself is tested in the TestValidators class
        metadata = self.valid_metadata
        metadata.object_id = '2010-062'

        # Check that validation fails

        self.assertRaises(ValueError, metadata.validate_keywords)

        # Check that OPM cannot be constructed from invalid header

        with self.assertRaises(ValueError):
            opm.Opm(header=self.valid_header,
                    metadata=metadata,
                    data=self.valid_data)