def test_set_db_loc(self): """ Verifies that the database location can be set """ import os data_dir = os.getcwd() settings = RaseSettings() settings.setDataDirectory(data_dir) assert data_dir == settings.getDataDirectory()
def complete_tests(): """Make sure no sample spectra are left after the final test is run""" settings = RaseSettings() original_data_dir = settings.getDataDirectory() settings.setDataDirectory(os.path.join(os.getcwd(), '__temp_test_rase')) yield None # anything before this line will be run prior to the tests print('CLEANING UP') # run after the last test settings = RaseSettings() if os.path.isdir(settings.getSampleDirectory()): shutil.rmtree(settings.getSampleDirectory()) if os.path.isfile(settings.getDatabaseFilepath()): os.remove(settings.getDatabaseFilepath()) settings.setDataDirectory(original_data_dir) print('CLEANUP COMPLETE')
class SettingsDialog(ui_prefs_dialog.Ui_Dialog, QDialog): def __init__(self, parent): QDialog.__init__(self, parent) self.settings = RaseSettings() self.setupUi(self) self.txtDataDir.setReadOnly(True) self.txtDataDir.setText(self.settings.getDataDirectory()) self.dataDirectoryChanged = False self.algoDictionary = {} algoCount = 0 for name, data in inspect.getmembers(sampling_algos, predicate=inspect.isfunction): try: readable_name = data.__doc__.splitlines()[0].strip() if readable_name == '': raise Exception("") except: readable_name = name self.downSapmplingAlgoComboBox.addItem(readable_name) self.algoDictionary[algoCount] = data if data == self.settings.getSamplingAlgo(): self.downSapmplingAlgoComboBox.setCurrentIndex(algoCount) algoCount += 1 self.algorithmSelected = False self.downSapmplingAlgoComboBox.currentIndexChanged.connect( self.chooseSamplingAlgo) @pyqtSlot(bool) def on_btnBrowseDataDir_clicked(self, checked): """ Selects Data Directory """ options = QFileDialog.ShowDirsOnly if sys.platform.startswith('win'): options = QFileDialog.DontUseNativeDialog dir = QFileDialog.getExistingDirectory( self, 'Choose RASE Data Directory', self.settings.getDataDirectory(), options) if dir: self.txtDataDir.setText(dir) self.dataDirectoryChanged = True def chooseSamplingAlgo(self, index): """ Selects Sampling Algo """ self.algorithmSelected = True @pyqtSlot() def accept(self): if self.dataDirectoryChanged: self.settings.setDataDirectory( os.path.normpath(self.txtDataDir.text())) idx = self.downSapmplingAlgoComboBox.currentIndex() if self.algorithmSelected: self.settings.setSamplingAlgo(self.algoDictionary[idx]) # if current state is different from initial state (somehow record the initial state so if the user toggles # but then toggles back the user is not prompted to reset RASE) super().accept()