def test_custom_path(self): default_path = MagneticFieldModel.default_magnetic_path() with tempfile.TemporaryDirectory() as dirname: magnetic_path = os.path.join(dirname, os.path.basename(default_path)) shutil.copytree(default_path, magnetic_path) model = MagneticFieldModel(self.MODEL_NAME, magnetic_path) self.assertEqual(model.magnetic_model_name(), self.MODEL_NAME) self.assertEqual(model.magnetic_model_directory(), magnetic_path)
def test_field_components_vector(self): H, F, D, I = MagneticFieldModel.field_components( self.BX.flatten(), self.BY.flatten(), self.BZ.flatten()) npt.assert_allclose(H, self.H.flatten()) npt.assert_allclose(F, self.F.flatten()) npt.assert_allclose(D, self.D.flatten()) npt.assert_allclose(I, self.I.flatten())
def test_field_components_matrix(self): H, F, D, I = MagneticFieldModel.field_components( self.BX, self.BY, self.BZ) npt.assert_allclose(H, self.H) npt.assert_allclose(F, self.F) npt.assert_allclose(D, self.D) npt.assert_allclose(I, self.I)
def test_custom_path_from_env02(self): default_path = MagneticFieldModel.default_magnetic_path() with tempfile.TemporaryDirectory() as dirname: magnetic_path = os.path.join(dirname, os.path.basename(default_path)) shutil.copytree(default_path, magnetic_path) old_env = os.environ.get('GEOGRAPHICLIB_MAGNETIC_PATH') os.environ['GEOGRAPHICLIB_MAGNETIC_PATH'] = magnetic_path try: model = MagneticFieldModel(self.MODEL_NAME) self.assertEqual(model.magnetic_model_name(), self.MODEL_NAME) self.assertEqual(model.magnetic_model_directory(), magnetic_path) finally: if old_env is None: del os.environ['GEOGRAPHICLIB_MAGNETIC_PATH'] else: os.environ['GEOGRAPHICLIB_MAGNETIC_PATH'] = old_env
def test_default_magnetic_name(self): names = ( 'wmm2010', 'wmm2015', 'wmm2015v2', 'wmm2020', 'igrf11', 'igrf12', 'emm2010', 'emm2015', 'emm2017', ) self.assertTrue(MagneticFieldModel.default_magnetic_name() in names)
def test_default_path(self): path = MagneticFieldModel.default_magnetic_path() model = MagneticFieldModel(self.MODEL_NAME, path) self.assertEqual(model.magnetic_model_name(), self.MODEL_NAME) self.assertEqual(model.magnetic_model_directory(), path)
def test_name(self): model = MagneticFieldModel(self.MODEL_NAME) self.assertIsInstance(model, MagneticFieldModel) self.assertEqual(model.magnetic_model_name(), self.MODEL_NAME)
def setUp(self) -> None: self.model = MagneticFieldModel(self.MODEL_NAME)
def test_no_args(self): model = MagneticFieldModel() self.assertIsInstance(model, MagneticFieldModel) self.assertEqual(model.magnetic_model_name(), MagneticFieldModel.default_magnetic_name())
def test_field_components(self): H, F, D, I = MagneticFieldModel.field_components( self.BX, self.BY, self.BZ) npt.assert_allclose([H, F, D, I], [self.H, self.F, self.D, self.I])
def test_default_magnetic_path(self): self.assertIsInstance(MagneticFieldModel.default_magnetic_path(), str) self.assertEqual(MagneticFieldModel.default_magnetic_path(), os.path.join(get_default_data_path(), 'magnetic'))
def setUp(self) -> None: self.name = MagneticFieldModel.default_magnetic_name() self.datapath = MagneticFieldModel.default_magnetic_path() self.model = MagneticFieldModel(self.name, self.datapath)
class InfoMethodsTestCase(unittest.TestCase): def setUp(self) -> None: self.name = MagneticFieldModel.default_magnetic_name() self.datapath = MagneticFieldModel.default_magnetic_path() self.model = MagneticFieldModel(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_magnetic_file(self): filename = self.model.magnetic_file() self.assertIn(self.name, filename) self.assertIn(self.datapath, filename) def test_magnetic_model_name(self): name = self.model.magnetic_model_name() self.assertEqual(name, self.name) def test_magnetic_model_directory(self): path = self.model.magnetic_model_directory() self.assertEqual(path, self.datapath) def test_min_height(self): self.assertIsInstance(self.model.min_height(), float) def test_max_height(self): self.assertIsInstance(self.model.max_height(), float) self.assertGreater(self.model.max_height(), 0) def test_min_max_height(self): self.assertLess(self.model.min_height(), self.model.max_height()) def test_min_time(self): self.assertIsInstance(self.model.min_time(), float) # self.assertLess(self.model.min_time(), datetime.date.today().year) def test_max_time(self): self.assertIsInstance(self.model.max_time(), float) self.assertGreater(self.model.max_time(), datetime.date.today().year) def test_min_max_time(self): self.assertLess(self.model.min_time(), self.model.max_time()) def test_major_radius(self): self.assertIsInstance(self.model.major_radius(), float) self.assertGreater(self.model.major_radius(), 5e6) def test_flattening(self): self.assertIsInstance(self.model.flattening(), float) self.assertGreater(self.model.flattening(), 0) self.assertLess(self.model.flattening(), 1)