Exemple #1
0
 def test_no_cfg_file(self):
     """Verify Configure handles non-existent config file"""
     no_such_file = os.path.join(os.path.dirname(__file__), "_config.cfg")
     self.assertFalse(os.path.exists(no_such_file))
     cfg = config.Configure(no_such_file)
     self.assertIsNone(cfg.get_app_option('path'))
     cfg.set_app_option({'path': pathfinder.app_path()})
     # App option should now be set in newly-created file
     self.assertTrue(os.path.exists(no_such_file))
     self.assertEqual(cfg.get_app_option('path'), pathfinder.app_path())
     if os.path.exists(no_such_file):
         os.remove(no_such_file)
 def test_import_data(self):
     """Verify import_data successfully imports data"""
     sample_data_folder = os.path.join(pathfinder.app_path(), 'models', 'tests', 'support_files')
     sample_utwin_file = os.path.join(sample_data_folder, 'CScanData.csc')
     utwin_data = dataio.get_utwin_data(sample_utwin_file)
     expected_utwin_data = {}
     for data_type in utwin_data.keys():
         for idx in range(len(utwin_data[data_type])):
             expected_utwin_data[data_type + str(idx)] = utwin_data[data_type][idx]
     output_fnames = []
     root, ext = os.path.splitext(os.path.basename(sample_utwin_file))
     for dataset in expected_utwin_data:
         output_fnames.append(os.path.join(pathfinder.data_path(), root + "_" + dataset + ".hdf5"))
     batchui_ctrl.import_data(sample_utwin_file)
     for dataset in expected_utwin_data:
         if expected_utwin_data[dataset] is not None:
             fname = os.path.join(pathfinder.data_path(), root + "_" + dataset + ".hdf5")
             self.assertTrue(os.path.exists(fname))
             self.assertTrue(np.array_equal(expected_utwin_data[dataset], dataio.get_data(fname)))
     for fname in output_fnames:
         try:
             if os.path.exists(fname):
                 os.remove(fname)
         except WindowsError: # file in use (Windows)
             pass
         except OSError: # other OS error
             pass
 def test_read_data(self):
     """Verify returning NumPy data from a file"""
     sample_data_folder = os.path.join(pathfinder.app_path(), 'models', 'tests', 'support_files')
     # Verify Winspect 6/7 retrieval
     sample_winspect_file = os.path.join(sample_data_folder, 'sample_data.sdt')
     winspect_adapter = self.create_adapter(sample_winspect_file)
     winspect_adapter.read_data()
     returned_winspect_data = dataio.get_winspect_data(sample_winspect_file)
     for dataset in returned_winspect_data:
         expected_winspect_data = dataset.data
         retrieved_winspect_data = winspect_adapter.data[dataset.data_type + "0"]
         self.assertTrue(np.array_equal(expected_winspect_data, retrieved_winspect_data))
     # Verify bitmap retrieval
     sample_img_file = os.path.join(sample_data_folder, 'austin_sky320x240.jpg')
     expected_img_data = dataio.get_img_data(sample_img_file)
     img_adapter = self.create_adapter(sample_img_file)
     img_adapter.read_data()
     retrieved_img_data = img_adapter.data
     self.assertTrue(np.array_equal(expected_img_data, retrieved_img_data))
     # Verify UTWin retrieval
     sample_utwin_file = os.path.join(sample_data_folder, 'CScanData.csc')
     utwin_adapter = self.create_adapter(sample_utwin_file)
     utwin_data = dataio.get_utwin_data(sample_utwin_file)
     expected_utwin_data = {}
     for data_type in utwin_data.keys():
         for idx in range(len(utwin_data[data_type])):
             expected_utwin_data[data_type + str(idx)] = utwin_data[data_type][idx]
     utwin_adapter.read_data()
     retrieved_utwin_data = utwin_adapter.data
     for dataset in expected_utwin_data:
         if expected_utwin_data[dataset] is not None:
             self.assertTrue(np.array_equal(expected_utwin_data[dataset], retrieved_utwin_data[dataset]))
 def test_read_data(self):
     """Verify returning converted data from various file formats"""
     sample_data_folder = os.path.join(pathfinder.app_path(), 'models', 'tests', 'support_files')
     # Verify Winspect 6/7 data retrieval
     sample_winspect_file = os.path.join(sample_data_folder, 'sample_data.sdt')
     expected_winspect_data = dataio.get_winspect_data(sample_winspect_file)
     retrieved_winspect_data = batchui_ctrl.read_data(sample_winspect_file)
     for dataset in expected_winspect_data:
         self.assertTrue(np.array_equal(dataset.data, retrieved_winspect_data[dataset.data_type + "0"]))
     # Verify bitmap retrieval
     sample_img_file = os.path.join(sample_data_folder, 'austin_sky320x240.jpg')
     expected_img_data = dataio.get_img_data(sample_img_file)
     retrieved_img_data = batchui_ctrl.read_data(sample_img_file)
     self.assertTrue(np.array_equal(expected_img_data, retrieved_img_data))
     # Verify UTWin Retrieval
     sample_utwin_file = os.path.join(sample_data_folder, "CScanData.csc")
     utwin_data = dataio.get_utwin_data(sample_utwin_file)
     retrieved_utwin_data = batchui_ctrl.read_data(sample_utwin_file)
     expected_utwin_data = {}
     for data_type in utwin_data.keys():
         for idx in range(len(utwin_data[data_type])):
             expected_utwin_data[data_type + str(idx)] = utwin_data[data_type][idx]
     for dataset in expected_utwin_data:
         if expected_utwin_data is not None:
             self.assertTrue(np.array_equal(expected_utwin_data[dataset], retrieved_utwin_data[dataset]))
 def test_get_cmap(self):
     """Verify returning a valid matplotlib Colormap (predefined or user-created)"""
     colormap_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = self.model.get_system_colormaps()
     colormaps.extend(self.model.get_user_colormaps(colormap_folder))
     for cmap_name in colormaps:
         cmap = self.model.get_cmap(cmap_name, colormap_folder)
         self.assertTrue(isinstance(cmap, matplotlib.colors.Colormap))
 def test_load_colormap(self):
     """Verify load_colormap returns a valid matplotlib Colormap"""
     colormap_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = self.model.get_user_colormaps(colormap_folder)
     for cmap_name in colormaps:
         cmap_file = os.path.join(colormap_folder, cmap_name)
         cmap = self.model.load_colormap(cmap_file)
         self.assertTrue(isinstance(cmap, matplotlib.colors.Colormap))
 def on_about_license(self, evt):
     """Handles the License Information event"""
     license_file = os.path.join(pathfinder.app_path(), 'license.txt')
     with open(license_file, 'rb') as fidin:
         license = fidin.readlines()
         license_dlg = dlg.TextDisplayDialog(parent=self.view, text=''.join(license),
                                             title="License Information",
                                             style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
         license_dlg.Show()
 def copy_system_colormaps(self):
     """Verify system colormaps are copied to user's folder"""
     colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = os.listdir(colormaps_folder)
     self.remove_system_files(colormaps, pathfinder.colormaps_path())
     self.model.copy_system_colormaps()
     for cmap in colormaps:
         installed_cmap = os.path.join(pathfinder.colormaps_path(), cmap)
         self.assertTrue(os.path.exists(installed_cmap))
Exemple #9
0
 def write_cfg(self):
     """Write some basic configuration options to the config file"""
     self.config.set_app_option({'path': pathfinder.app_path()})
     self.config.set_app_option({'Should Run': False})
     self.config.set_app_option({'alpha': 1, 'beta': -2.2})
     self.config.set_app_option({'labels': ('mon', 'wed', 'fri', 3.14)})
     self.config.set(section='Plugins', options={'medfilter': True,
                                                 'normalize': False})
     self.config.set(section='Coordinates', options={'app': (21, -42)})
     self.config.set(section='Coordinates', options={'alpha': 1, 'beta': -2.2})
 def test_get_user_colormaps(self):
     """Verify returning a list of user-defined colormaps"""
     colormap_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     expected_colormaps = []
     for root, dirs, files in os.walk(colormap_folder):
         for fname in files:
             with open(os.path.join(root, fname), "r") as fidin:
                 cmap_dict = json.load(fidin)
                 expected_colormaps.append(cmap_dict.get('name', fname))
     self.assertListEqual(expected_colormaps, self.model.get_user_colormaps(colormap_folder))
 def test_save_colormap(self):
     """Verify saving a colormap"""
     shipped_colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     shipped_colormaps = os.listdir(shipped_colormaps_folder)
     for shipped_colormap in shipped_colormaps:
         shipped_colormap_file = os.path.join(shipped_colormaps_folder, shipped_colormap)
         with open(shipped_colormap_file, "r") as fidin:
             cmap_dict = json.load(fidin)
             self.model.save_colormap(cmap_dict)
             cmap_file = os.path.join(pathfinder.colormaps_path(), cmap_dict['name'])
             self.assertTrue(os.path.exists(cmap_file))
Exemple #12
0
 def test_save_colormap(self):
     """Verify saving a colormap"""
     shipped_colormaps_folder = os.path.join(pathfinder.app_path(),
                                             'colormaps')
     shipped_colormaps = os.listdir(shipped_colormaps_folder)
     for shipped_colormap in shipped_colormaps:
         shipped_colormap_file = os.path.join(shipped_colormaps_folder,
                                              shipped_colormap)
         with open(shipped_colormap_file, "r") as fidin:
             cmap_dict = json.load(fidin)
             self.model.save_colormap(cmap_dict)
             cmap_file = os.path.join(pathfinder.colormaps_path(),
                                      cmap_dict['name'])
             self.assertTrue(os.path.exists(cmap_file))
Exemple #13
0
 def test_read_options(self):
     """Verify reading of options"""
     self.write_cfg()
     self.assertEqual(pathfinder.app_path(),
                      self.config.get_app_option('path'))
     self.assertFalse(self.config.get_app_option_boolean('Should Run'))
     self.assertEqual(self.config.get_app_option_int('alpha'), 1)
     self.assertAlmostEqual(self.config.get_app_option_float('beta'), -2.2)
     self.assertListEqual(self.config.get_app_option_list('labels'),
         ['mon', 'wed', 'fri', '3.14'])
     self.assertTrue(self.config.get_boolean('Plugins', 'medfilter'))
     self.assertFalse(self.config.get_boolean('Plugins', 'normalize'))
     self.assertListEqual(self.config.get_list('Coordinates', 'app'), ['21', '-42'])
     self.assertEqual(self.config.get_int('Coordinates', 'alpha'), 1)
     self.assertAlmostEqual(self.config.get_float('Coordinates', 'beta'), -2.2)
Exemple #14
0
 def write_cfg(self):
     """Write some basic configuration options to the config file"""
     self.config.set_app_option({'path': pathfinder.app_path()})
     self.config.set_app_option({'Should Run': False})
     self.config.set_app_option({'alpha': 1, 'beta': -2.2})
     self.config.set_app_option({'labels': ('mon', 'wed', 'fri', 3.14)})
     self.config.set(section='Plugins',
                     options={
                         'medfilter': True,
                         'normalize': False
                     })
     self.config.set(section='Coordinates', options={'app': (21, -42)})
     self.config.set(section='Coordinates',
                     options={
                         'alpha': 1,
                         'beta': -2.2
                     })
Exemple #15
0
 def test_read_options(self):
     """Verify reading of options"""
     self.write_cfg()
     self.assertEqual(pathfinder.app_path(),
                      self.config.get_app_option('path'))
     self.assertFalse(self.config.get_app_option_boolean('Should Run'))
     self.assertEqual(self.config.get_app_option_int('alpha'), 1)
     self.assertAlmostEqual(self.config.get_app_option_float('beta'), -2.2)
     self.assertListEqual(self.config.get_app_option_list('labels'),
                          ['mon', 'wed', 'fri', '3.14'])
     self.assertTrue(self.config.get_boolean('Plugins', 'medfilter'))
     self.assertFalse(self.config.get_boolean('Plugins', 'normalize'))
     self.assertListEqual(self.config.get_list('Coordinates', 'app'),
                          ['21', '-42'])
     self.assertEqual(self.config.get_int('Coordinates', 'alpha'), 1)
     self.assertAlmostEqual(self.config.get_float('Coordinates', 'beta'),
                            -2.2)
 def test_run_plugin_multi_datasets(self):
     """Verify run_plugin convenience function correctly handles datafiles with
     multiple datasets"""
     sample_data_folder = os.path.join(pathfinder.app_path(), 'models', 'tests', 'support_files')
     sample_utwin_file = os.path.join(sample_data_folder, 'CScanData.csc')
     utwin_data = dataio.get_utwin_data(sample_utwin_file)
     expected_utwin_data = {}
     for data_type in utwin_data.keys():
         for idx in range(len(utwin_data[data_type])):
             expected_utwin_data[data_type + str(idx)] = utwin_data[data_type][idx]
     output_fnames = []
     root, ext = os.path.splitext(os.path.basename(sample_utwin_file))
     for dataset in expected_utwin_data:
         output_fnames.append(os.path.join(pathfinder.batchoutput_path(), root + "_" + dataset + ".hdf5"))
     # Verify no output saved
     batchui_ctrl.run_plugin(self.toolkit_class, sample_utwin_file, save_data=False)
     for fname in output_fnames:
         self.assertFalse(os.path.exists(fname))
     # Verify output saved
     batchui_ctrl.run_plugin(self.toolkit_class, sample_utwin_file, save_data=True)
     for dataset in expected_utwin_data:
         if expected_utwin_data[dataset] is not None:
             fname = os.path.join(pathfinder.batchoutput_path(), root + "_" + dataset + ".hdf5")
             self.assertTrue(os.path.exists(fname))
             plugin_names, plugin_classes = self.get_available_plugins()
             for idx in range(len(plugin_names)):
                 if plugin_names[idx] == self.toolkit_class:
                     plugin_instance = plugin_classes[idx]()
                     plugin_instance.data = expected_utwin_data[dataset]
                     plugin_instance.run()
                     expected_data = plugin_instance.data
                     returned_data = dataio.get_data(fname)
                     self.assertTrue(np.array_equal(expected_data, returned_data))
                     break
     for fname in output_fnames:
         try:
             if os.path.exists(fname):
                 os.remove(fname)
         except WindowsError: # file in use (Windows)
             pass
         except OSError: # other OS error
             pass
 def test_read_data(self):
     """Verify returning NumPy data from a file"""
     sample_data_folder = os.path.join(pathfinder.app_path(), 'models',
                                       'tests', 'support_files')
     # Verify Winspect 6/7 retrieval
     sample_winspect_file = os.path.join(sample_data_folder,
                                         'sample_data.sdt')
     winspect_adapter = self.create_adapter(sample_winspect_file)
     winspect_adapter.read_data()
     returned_winspect_data = dataio.get_winspect_data(sample_winspect_file)
     for dataset in returned_winspect_data:
         expected_winspect_data = dataset.data
         retrieved_winspect_data = winspect_adapter.data[dataset.data_type +
                                                         "0"]
         self.assertTrue(
             np.array_equal(expected_winspect_data,
                            retrieved_winspect_data))
     # Verify bitmap retrieval
     sample_img_file = os.path.join(sample_data_folder,
                                    'austin_sky320x240.jpg')
     expected_img_data = dataio.get_img_data(sample_img_file)
     img_adapter = self.create_adapter(sample_img_file)
     img_adapter.read_data()
     retrieved_img_data = img_adapter.data
     self.assertTrue(np.array_equal(expected_img_data, retrieved_img_data))
     # Verify UTWin retrieval
     sample_utwin_file = os.path.join(sample_data_folder, 'CScanData.csc')
     utwin_adapter = self.create_adapter(sample_utwin_file)
     utwin_data = dataio.get_utwin_data(sample_utwin_file)
     expected_utwin_data = {}
     for data_type in utwin_data.keys():
         for idx in range(len(utwin_data[data_type])):
             expected_utwin_data[data_type +
                                 str(idx)] = utwin_data[data_type][idx]
     utwin_adapter.read_data()
     retrieved_utwin_data = utwin_adapter.data
     for dataset in expected_utwin_data:
         if expected_utwin_data[dataset] is not None:
             self.assertTrue(
                 np.array_equal(expected_utwin_data[dataset],
                                retrieved_utwin_data[dataset]))
 def test_app_path(self):
     """Verify pathfinder reports the correct application path"""
     self.assertEqual(self.app_path, pathfinder.app_path())
 def copy_system_colormaps(cls):
     """Copies matplotlib colormaps that ship with the application to the user's colormaps folder."""
     colormaps_folder = os.path.join(pathfinder.app_path(), 'colormaps')
     colormaps = os.listdir(colormaps_folder)
     for colormap_file in colormaps:
         shutil.copy(os.path.join(colormaps_folder, colormap_file), pathfinder.colormaps_path())
 def copy_system_gates(cls):
     """Copies ultrasonic gate plugins that ship with the application to the user's gates folder."""
     system_gates_folder = os.path.join(pathfinder.app_path(), 'gates')
     MainModel.copy_system_files(system_gates_folder, pathfinder.gates_path())
 def copy_system_plugins(cls):
     """Copies plugins that ship with the application to the user's plugins folder."""
     system_plugins_folder = os.path.join(pathfinder.app_path(), 'plugins')
     MainModel.copy_system_files(system_plugins_folder, pathfinder.plugins_path())
 def test_app_path(self):
     """Verify pathfinder reports the correct application path"""
     self.assertEqual(self.app_path, pathfinder.app_path())
Exemple #23
0
 def copy_system_plugins(cls):
     """Copies plugins that ship with the application to the user's plugins folder."""
     system_plugins_folder = os.path.join(pathfinder.app_path(), 'plugins')
     MainModel.copy_system_files(system_plugins_folder,
                                 pathfinder.plugins_path())
Exemple #24
0
 def copy_system_gates(cls):
     """Copies ultrasonic gate plugins that ship with the application to the user's gates folder."""
     system_gates_folder = os.path.join(pathfinder.app_path(), 'gates')
     MainModel.copy_system_files(system_gates_folder,
                                 pathfinder.gates_path())