Пример #1
0
    def test_custom_path(self):
        default_path = pathlib.Path(GravityModel.default_gravity_path())
        with tempfile.TemporaryDirectory() as dirname:
            gravity_model_path = pathlib.Path(dirname) / default_path.name
            gravity_model_path.mkdir()
            for filename in default_path.glob(f'{self.MODEL_NAME}*'):
                shutil.copy(filename, gravity_model_path)

            model = GravityModel(self.MODEL_NAME, gravity_model_path)
            self.assertEqual(model.gravity_model_name(), self.MODEL_NAME)
            self.assertEqual(model.gravity_model_directory(),
                             str(gravity_model_path))
Пример #2
0
class InfoMethodsTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.name = GravityModel.default_gravity_name()
        self.datapath = GravityModel.default_gravity_path()
        self.model = GravityModel(self.name, self.datapath)

    def test_description(self):
        description = self.model.description()
        self.assertIsInstance(description, str)
        self.assertNotEqual(description, 'NONE')

    def test_datetime(self):
        datestr = self.model.datetime()
        self.assertIsInstance(datestr, str)
        self.assertNotEqual(datestr, 'UNKNOWN')
        date = datetime.datetime.strptime(datestr, '%Y-%m-%d')
        # date = datetime.datetime.strptime(datestr, '%Y-%m-%d %H:%M:%S')
        self.assertLess(date, datetime.datetime.now())

    def test_gravity_file(self):
        filename = self.model.gravity_file()
        self.assertIn(self.name, filename)
        self.assertIn(self.datapath, filename)

    def test_gravity_model_name(self):
        name = self.model.gravity_model_name()
        self.assertEqual(name, self.name)

    def test_gravity_model_directory(self):
        path = self.model.gravity_model_directory()
        self.assertEqual(path, self.datapath)

    def equator_radius(self):
        self.assertIsInstance(self.model.equator_radius(), float)
        self.assertGreater(self.model.equator_radius(), 5e6)

    def test_flattening(self):
        self.assertIsInstance(self.model.flattening(), float)
        self.assertGreater(self.model.flattening(), 0)
        self.assertLess(self.model.flattening(), 1)

    def test_mass_constant(self):
        self.assertIsInstance(self.model.mass_constant(), float)
        self.assertGreater(self.model.mass_constant(), 0)

    def test_reference_mass_constant(self):
        self.assertIsInstance(self.model.reference_mass_constant(), float)
        self.assertGreater(self.model.reference_mass_constant(), 0)

    def test_angular_velocity(self):
        self.assertIsInstance(self.model.angular_velocity(), float)
        self.assertGreater(self.model.angular_velocity(), 0)
Пример #3
0
    def test_custom_path_from_env02(self):
        default_path = pathlib.Path(GravityModel.default_gravity_path())
        with tempfile.TemporaryDirectory() as dirname:
            gravity_model_path = pathlib.Path(dirname) / default_path.name
            gravity_model_path.mkdir()
            for filename in default_path.glob(f'{self.MODEL_NAME}*'):
                shutil.copy(filename, gravity_model_path)

            old_env = os.environ.get('GEOGRAPHICLIB_GRAVITY_PATH')
            os.environ['GEOGRAPHICLIB_GRAVITY_PATH'] = str(gravity_model_path)
            try:
                model = GravityModel(self.MODEL_NAME)
                self.assertEqual(model.gravity_model_name(), self.MODEL_NAME)
                self.assertEqual(model.gravity_model_directory(),
                                 str(gravity_model_path))
            finally:
                if old_env is None:
                    del os.environ['GEOGRAPHICLIB_GRAVITY_PATH']
                else:
                    os.environ['GEOGRAPHICLIB_GRAVITY_PATH'] = old_env
Пример #4
0
 def test_default_path(self):
     path = GravityModel.default_gravity_path()
     model = GravityModel(self.MODEL_NAME, path)
     self.assertEqual(model.gravity_model_name(), self.MODEL_NAME)
     self.assertEqual(model.gravity_model_directory(), path)