class TestSoundSpeedDb(unittest.TestCase): def setUp(self): def add_cast(lat, lon): self.lib.ssp.cur.meta.latitude = lat self.lib.ssp.cur.meta.longitude = lon self.lib.ssp.cur.meta.utc_time = datetime.now() self.lib.ssp.cur.init_data(self.levels) self.lib.ssp.cur.data.depth[:self.levels] = self.depth self.lib.ssp.cur.data.speed[:self.levels] = 1415 self.lib.restart_proc() self.lib.store_data() self.max_pk = 5 self.levels = self.max_pk * self.max_pk self.depth = np.array(range(self.levels)) projects_folder = os.path.abspath(os.curdir) project_name = 'unittest' db_name = '%s.db' % project_name self.db_path = os.path.join(projects_folder, db_name) self.tearDown() self.lib = SoundSpeedLibrary() self.lib.projects_folder = projects_folder self.lib.current_project = project_name self.lib.ssp = ProfileList() self.lib.ssp.append() if len(self.lib.db_list_profiles()) < self.max_pk: for i in range(self.max_pk): add_cast(20 + i, -75) def tearDown(self): if os.path.exists(self.db_path): os.remove(self.db_path) @unittest.skipUnless(sys.platform.startswith("win"), "only works with GDAL < 2.0 on Windows") def test_save_load_cast(self): def test_pk(pk): self.lib.ssp = self.lib.db_retrieve_profile(pk) self.lib.store_data() self.lib.ssp = self.lib.db_retrieve_profile(pk) sum_ = len(self.lib.ssp.cur.proc.speed) + len( self.lib.ssp.cur.proc.depth) sum_ += len(self.lib.ssp.cur.data.speed) + len( self.lib.ssp.cur.data.depth) self.assertEqual(sum_, self.levels * 4) self.assertTrue((self.lib.ssp.cur.data.depth == self.depth).all()) self.assertTrue((self.lib.ssp.cur.proc.depth == self.depth).all()) for i in range(self.levels): # pk = random.randint(1, self.max_pk) pk = i % self.max_pk + 1 test_pk(pk)
def main(): # create a project with test-callbacks lib = SoundSpeedLibrary(callbacks=TestCallbacks()) # set the current project name lib.setup.current_project = 'test' # retrieve data input/output folders data_input = testing.input_data_folder() logger.info('input folder: %s' % data_input) data_output = testing.output_data_folder() logger.info('output folder: %s' % data_output) # test readers/writers logger.info('test: *** START ***') filters = [ "aml", ] tests = testing.input_dict_test_files(inclusive_filters=filters) # print(tests) # import each identified file for idx, testfile in enumerate(tests.keys()): logger.debug("filename: %s" % testfile) if idx > 4: # FILE FILTER break logger.info("test: * New profile: #%03d *" % idx) # import lib.import_data(data_path=testfile, data_format=tests[testfile].name) # print(lib.cur) lib.plot_ssp(more=True, show=False) # store the current profile success = lib.store_data() logger.info("stored: %s" % success) from matplotlib import pyplot as plt plt.show() # retrieve all the id profiles from db lst = lib.db_list_profiles() logger.info("Profiles: %s" % len(lst)) for p in lst: logger.info(p) # retrieve a specific profile and delete it ssp_pk = lst[0][0] ssp = lib.db_retrieve_profile(pk=ssp_pk) logger.info("Retrieved profile:\n%s" % ssp) ret = lib.delete_db_profile(pk=ssp_pk) logger.info("Deleted profile: %s" % ret) logger.info('test: *** END ***')
def _run(self, filters): # create a project with test-callbacks lib = SoundSpeedLibrary(callbacks=TestCallbacks()) # set the current project name lib.setup.current_project = 'test_read_store_and_write' tests = testing.input_dict_test_files(inclusive_filters=filters) data_outputs = dict() for format in self.formats: data_outputs[format] = self.data_output for idx, testfile in enumerate(tests.keys()): logger.info("test: * New profile: #%03d *" % idx) lib.import_data(data_path=testfile, data_format=tests[testfile].name) lib.store_data() lib.export_data(data_paths=data_outputs, data_formats=self.formats)