def setup_method(self):
     self.botui = BatchOperationToolUI()
     self.botui.add_tab(EMSConversionTab, name='EMS conversion tab')
     self.botui.add_tab(DeleteTab, name='Delete files')
     # match the default_settings.json files from the library
     self.dt_filter_parameters = {
         'string_list': [''],
         'extension_list': [''],
         'ignore_string_bool': False,
         'ignore_string_list': [''],
         'ignore_string_path_bool': False,
         'ignore_string_path_list': [''],
         'ignore_filename_extension_bool': False,
         'ignore_filename_extension_list': ['']
     }
     self.dt_main_parameters = {
         'subdirectory': False,
         'directory': os.getcwd()
     }
     self.emst_filter_parameters = {
         'string_list': [''],
         'extension_list': [''],
         'ignore_string_bool': False,
         'ignore_string_list': [''],
         'ignore_string_path_bool': False,
         'ignore_string_path_list': [''],
         'ignore_filename_extension_bool': False,
         'ignore_filename_extension_list': ['']
     }
     self.emst_main_parameters = {
         'subdirectory': False,
         'directory': self.botui.tab['EMS conversion tab'].dname
     }
Exemplo n.º 2
0
class Test_DeleteTab:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.filter_parameters = {
            'string_list': [''],
            'extension_list': ['ext', 'ext2', 'abc'],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.main_parameters = {'subdirectory': True, 'directory': os.getcwd()}

        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.dt = DeleteTab(self.botui.fill_tables, parent=self.botui)
        self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']

    def test_set_filter_parameters(self):
        self.dt.set_filter_parameters(**self.filter_parameters)
        for key in list(self.filter_parameters.keys()):
            assert self.dt.filter_widget.parameters[
                key] == self.filter_parameters[key]
Exemplo n.º 3
0
class Test_DeleteTab:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.filter_parameters = {'string_list':[''],
                                  'extension_list':['ext', 'ext2', 'abc'],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
        self.main_parameters = {'subdirectory':True,
                                'directory':os.getcwd()}  

        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.dt = DeleteTab(self.botui.fill_tables, parent=self.botui)
        self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
        
    def test_set_filter_parameters(self):
        self.dt.set_filter_parameters(**self.filter_parameters)
        for key in list(self.filter_parameters.keys()):
            assert self.dt.filter_widget.parameters[key] == self.filter_parameters[key]
 def setup_method(self):
     self.parameters = {'string_list':[''],
                        'extension_list':['ext', 'ext2', 'abc'],
                       'ignore_string_bool':False,
                       'ignore_string_list':[''],
                       'ignore_string_path_bool':False,
                       'ignore_string_path_list':[''],
                       'ignore_filename_extension_bool':False,
                       'ignore_filename_extension_list':['']}
     self.botui = BatchOperationToolUI(load_settings=None)
     name ='Delete files'
     self.botui.add_tab(DeleteTab, name=name)
     self.fw = FilterWidget(parent=self.botui.tab[name])
     self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
Exemplo n.º 5
0
    def setup_method(self):
        self.filter_parameters = {'string_list':[''],
                                  'extension_list':['ext', 'ext2', 'abc'],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
        self.main_parameters = {'subdirectory':True,
                                'directory':os.getcwd()}  

        self.botui = BatchOperationToolUI(load_settings=None)
        # dummy tab required for initialisation
        self.botui.add_tab(DeleteTab)
        self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)
 def setup_method(self):
     self.botui = BatchOperationToolUI()
     self.botui.add_tab(EMSConversionTab, name='EMS conversion tab')
     self.botui.add_tab(DeleteTab, name='Delete files')
     # match the default_settings.json files from the library
     self.dt_filter_parameters = {'string_list':[''],
                                  'extension_list':[''],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
     self.dt_main_parameters = {'subdirectory':False,
                                'directory':os.getcwd()}
     self.emst_filter_parameters = {'string_list':[''],
                                    'extension_list':[''],
                                    'ignore_string_bool':False,
                                    'ignore_string_list':[''],
                                    'ignore_string_path_bool':False,
                                    'ignore_string_path_list':[''],
                                    'ignore_filename_extension_bool':False,
                                    'ignore_filename_extension_list':['']}
     self.emst_main_parameters = {'subdirectory':False,
                                  'directory':self.botui.tab['EMS conversion tab'].dname}
Exemplo n.º 7
0
    def setup_method(self):
        self.filter_parameters = {
            'string_list': [''],
            'extension_list': ['ext', 'ext2', 'abc'],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.main_parameters = {'subdirectory': True, 'directory': os.getcwd()}

        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.dt = DeleteTab(self.botui.fill_tables, parent=self.botui)
        self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
 def setup_method(self):
     self.parameters = {
         'string_list': [''],
         'extension_list': ['ext', 'ext2', 'abc'],
         'ignore_string_bool': False,
         'ignore_string_list': [''],
         'ignore_string_path_bool': False,
         'ignore_string_path_list': [''],
         'ignore_filename_extension_bool': False,
         'ignore_filename_extension_list': ['']
     }
     self.tests_dir = get_dirname_file()
     self.botui = BatchOperationToolUI(load_settings=None)
     self.botui.add_tab(DeleteTab)
     self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)
     self.fw = FilterWidgetBase(parent=self.bt)
     self.fw.dname = self.tests_dir
     self.fl_short = [
         'fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc'
     ]
     self.fl = self._convert_file_list(sorted(self.fl_short))
    def setup_method(self):
        self.operation_parameters = {
            'extension_list': [],
            'data_type': 'image',
            'log_to_linear_scale': True,
            'overwrite': False
        }

        self.botui = BatchOperationToolUI(load_settings=None)
        self.emsct = EMSConversionTab(self.botui.fill_tables,
                                      parent=self.botui)
        self.emscw = EMSConversionWidget(self.emsct.get_files_lists,
                                         parent=self.emsct)
class Test_FilterWidget:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()
    
    def setup_method(self):
        self.parameters = {'string_list':[''],
                           'extension_list':['ext', 'ext2', 'abc'],
                          'ignore_string_bool':False,
                          'ignore_string_list':[''],
                          'ignore_string_path_bool':False,
                          'ignore_string_path_list':[''],
                          'ignore_filename_extension_bool':False,
                          'ignore_filename_extension_list':['']}
        self.botui = BatchOperationToolUI(load_settings=None)
        name ='Delete files'
        self.botui.add_tab(DeleteTab, name=name)
        self.fw = FilterWidget(parent=self.botui.tab[name])
        self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
    
    def test_set_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.fw.parameters['string_list'] == self.fw.stringLineEdit.text().split(', ')
        assert self.fw.parameters['extension_list'] == self.fw.extentionLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_string_bool'] == self.fw.ignoreStringCheckBox.isChecked()
        assert self.fw.parameters['ignore_string_list'] == self.fw.ignoreStringLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_string_path_bool'] == self.fw.ignoreStringPathCheckBox.isChecked()
        assert self.fw.parameters['ignore_string_path_list'] == self.fw.ignoreStringPathLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_filename_extension_bool'] == self.fw.ignorefilenameextensionCheckBox.isChecked()
        assert self.fw.parameters['ignore_filename_extension_list'] == self.fw.ignorefilenameextensionLineEdit.text().split(', ')

    def test_get_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.parameters == self.fw.get_parameters()
    def setup_method(self):
        self.filter_parameters = {
            'string_list': [''],
            'extension_list': ['ext', 'ext2', 'abc'],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.main_parameters = {'subdirectory': True, 'directory': os.getcwd()}
        self.operation_parameters = {
            'extension_list': [],
            'data_type': 'image',
            'log_to_linear_scale': True,
            'overwrite': False
        }

        self.botui = BatchOperationToolUI(load_settings=None)
        name = 'EMS conversion'
        self.botui.add_tab(EMSConversionTab, name=name)
        self.emsct = self.botui.tab[name]
Exemplo n.º 12
0
    def setup_method(self):
        self.filter_parameters = {'string_list':[''],
                                  'extension_list':['ext', 'ext2', 'abc'],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
        self.main_parameters = {'subdirectory':True,
                                'directory':os.getcwd()}  

        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.dt = DeleteTab(self.botui.fill_tables, parent=self.botui)
        self.fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
 def setup_method(self):
     self.parameters = {'string_list':[''],
                        'extension_list':['ext', 'ext2', 'abc'],
                        'ignore_string_bool':False,
                        'ignore_string_list':[''],
                        'ignore_string_path_bool':False,
                        'ignore_string_path_list':[''],
                        'ignore_filename_extension_bool':False,
                        'ignore_filename_extension_list':['']}
     self.tests_dir = get_dirname_file()
     self.botui = BatchOperationToolUI(load_settings=None)
     self.botui.add_tab(DeleteTab)
     self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)
     self.fw = FilterWidgetBase(parent=self.bt)
     self.fw.dname = self.tests_dir
     self.fl_short = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
     self.fl = self._convert_file_list(sorted(self.fl_short))
 def setup_method(self):
     self.filter_parameters = {'string_list':[''],
                               'extension_list':['ext', 'ext2', 'abc'],
                               'ignore_string_bool':False,
                               'ignore_string_list':[''],
                               'ignore_string_path_bool':False,
                               'ignore_string_path_list':['']}
     self.main_parameters = {'subdirectory':True,
                             'directory':os.getcwd()}  
     self.operation_parameters = {'extension_list':[],
                                  'data_type':'image',
                                  'log_to_linear_scale':True,
                                  'overwrite':False}
     
     self.botui = BatchOperationToolUI(load_settings=None)
     name ='EMS conversion'
     self.botui.add_tab(EMSConversionTab, name=name)
     self.emsct = self.botui.tab[name]
 def setUp(self):
     self.botui = BatchOperationToolUI()
     # match the default_settings.json files from the library
     self.dt_filter_parameters = {'string_list':[''],
                                  'extension_list':[''],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
     self.dt_main_parameters = {'subdirectory':False,
                                'directory':os.getcwd()}
     self.emst_filter_parameters = {'string_list':[''],
                                    'extension_list':[''],
                                    'ignore_string_bool':False,
                                    'ignore_string_list':[''],
                                    'ignore_string_path_bool':False,
                                    'ignore_string_path_list':[''],
                                    'ignore_filename_extension_bool':False,
                                    'ignore_filename_extension_list':['']}
     self.emst_main_parameters = {'subdirectory':False,
                                  'directory':self.botui.ems_conversion_tab.get_dname()}
class test_BatchOperationToolUI:
    @classmethod
    def setup_class(self):
        self.app = QtGui.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setUp(self):
        self.botui = BatchOperationToolUI()
        # match the default_settings.json files from the library
        self.dt_filter_parameters = {'string_list':[''],
                                     'extension_list':[''],
                                     'ignore_string_bool':False,
                                     'ignore_string_list':[''],
                                     'ignore_string_path_bool':False,
                                     'ignore_string_path_list':[''],
                                     'ignore_filename_extension_bool':False,
                                     'ignore_filename_extension_list':['']}
        self.dt_main_parameters = {'subdirectory':False,
                                   'directory':os.getcwd()}
        self.emst_filter_parameters = {'string_list':[''],
                                       'extension_list':[''],
                                       'ignore_string_bool':False,
                                       'ignore_string_list':[''],
                                       'ignore_string_path_bool':False,
                                       'ignore_string_path_list':[''],
                                       'ignore_filename_extension_bool':False,
                                       'ignore_filename_extension_list':['']}
        self.emst_main_parameters = {'subdirectory':False,
                                     'directory':self.botui.ems_conversion_tab.get_dname()}

    def test_create_header_tabs_loading_None(self):
        self.botui._create_header_tabs(load_settings=None)
        assert type(self.botui.ems_conversion_tab) == EMSConversionTab
        assert type(self.botui.delete_tab) == DeleteTab

    def test_create_header_tabs_loading_default(self):
        self.botui._create_header_tabs(load_settings='default')
        assert type(self.botui.ems_conversion_tab) == EMSConversionTab
        assert type(self.botui.delete_tab) == DeleteTab
#        assert self.botui.delete_tab.filter_widget.get_parameters() == self.dt_filter_parameters
#        assert self.botui.delete_tab._get_main_parameters() == self.dt_main_parameters
#        assert self.botui.ems_conversion_tab.filter_widget.get_parameters() == self.emst_filter_parameters
#        assert self.botui.ems_conversion_tab._get_main_parameters() == self.emst_main_parameters

    @raises(ValueError)
    def test_create_header_tabs_loading_exception(self):
        self.botui._create_header_tabs('')
        assert type(self.botui.ems_conversion_tab) == EMSConversionTab
        assert type(self.botui.delete_tab) == DeleteTab
        
    def test_create_tables_widget(self):
        assert type(self.botui.tables_widget) == QtGui.QTabWidget
        assert self.botui.tables_widget.widget(0) == self.botui.files_table
        assert self.botui.tables_widget.widget(1) == self.botui.ignore_table
    
    def test_setup_tables(self):
        assert type(self.botui.files_table) == QtGui.QTableWidget
        assert type(self.botui.ignore_table) == QtGui.QTableWidget

    def test_fill_table_files(self):
        self._fill_table(self.botui.files_table)
        self._fill_table(self.botui.ignore_table)

    def _fill_table(self, table):
        fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
        table = self.botui.files_table
        fl = [os.getcwd()+ fname for fname in fl]
        self.botui._fill_table(table, fl)
        assert table.rowCount() == len(fl)
        for i, fullfilename in enumerate(fl):
            fulldirname, filename = os.path.split(fullfilename)
            path, dirname = os.path.split(fulldirname)
            assert table.item(i, 0).text() == path
            assert table.item(i, 1).text() == dirname
            assert table.item(i, 2).text() == filename
        
    def test_get_current_tab_widget(self):
        self.botui._create_header_tabs()
        self.botui.headers_tab.setCurrentWidget(self.botui.delete_tab)
        assert self.botui._get_current_tab_widget() == self.botui.delete_tab
        self.botui.headers_tab.setCurrentWidget(self.botui.ems_conversion_tab)
        assert self.botui._get_current_tab_widget() == self.botui.ems_conversion_tab
class Test_FilterWidgetBase:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.parameters = {
            'string_list': [''],
            'extension_list': ['ext', 'ext2', 'abc'],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.tests_dir = get_dirname_file()
        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)
        self.fw = FilterWidgetBase(parent=self.bt)
        self.fw.dname = self.tests_dir
        self.fl_short = [
            'fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc'
        ]
        self.fl = self._convert_file_list(sorted(self.fl_short))

    def _convert_file_list(self, file_list):
        return convert_file_list_absolute_path(file_list, self.tests_dir)

    def test_set_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.fw.parameters[
            'string_list'] == self.fw.stringLineEdit.text().split(', ')
        assert self.fw.parameters[
            'extension_list'] == self.fw.extentionLineEdit.text().split(', ')
        assert self.fw.parameters[
            'ignore_string_bool'] == self.fw.ignoreStringCheckBox.isChecked()
        assert self.fw.parameters[
            'ignore_string_list'] == self.fw.ignoreStringLineEdit.text().split(
                ', ')
        assert self.fw.parameters[
            'ignore_string_path_bool'] == self.fw.ignoreStringPathCheckBox.isChecked(
            )
        assert self.fw.parameters[
            'ignore_string_path_list'] == self.fw.ignoreStringPathLineEdit.text(
            ).split(', ')
        assert self.fw.parameters[
            'ignore_filename_extension_bool'] == self.fw.ignorefilenameextensionCheckBox.isChecked(
            )
        assert self.fw.parameters[
            'ignore_filename_extension_list'] == self.fw.ignorefilenameextensionLineEdit.text(
            ).split(', ')

    def test_get_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.parameters == self.fw.get_parameters()


#    def test_update_files_lists(self):
#        # Create files
#        create_files(self.fl)
#        self.fw.set_parameters(**self.parameters)
#        self.fw.set_parameters(string_list=self.fl_short)
#        print self.fw.dname, self.fw.parameters['string_list']
#        self.fw.update_files_lists()
#        # Expected results
#        files_to_use_list = [os.path.join(self.tests_dir, fname) for fname in self.fl]
#        files_to_ignore_list = substract_lists(os.listdir('.'), self.fl)
#
#        list_temp = listdir_absolute_path(self.tests_dir)
#        files_to_ignore_list = sorted(substract_lists(list_temp, self.fl))
#
#        print '1:', len(files_to_use_list), files_to_use_list
#        print '12:', len(self.fw.files_to_use_list), self.fw.files_to_use_list
##        print '2:', len(files_to_ignore_list), files_to_ignore_list
##        print '22:', len(self.fw.get_files_lists()[1]), self.fw.get_files_lists()[1]
#
#        assert self.fw.get_files_lists() == (files_to_use_list, files_to_ignore_list)
#        # Remove files
#        remove_files(self.fl)

    def test_get_subdirectory(self):
        subdirectory = self.bt.get_subdirectory()
        assert subdirectory == self.fw._get_subdirectory()

    def test_dname(self):
        dname = 'dummy_dname'
        self.fw.dname = dname
        assert self.fw.dname == dname
class Test_BatchOperationToolUI:
    def setup_method(self):
        self.botui = BatchOperationToolUI()
        self.botui.add_tab(EMSConversionTab, name='EMS conversion tab')
        self.botui.add_tab(DeleteTab, name='Delete files')
        # match the default_settings.json files from the library
        self.dt_filter_parameters = {'string_list':[''],
                                     'extension_list':[''],
                                     'ignore_string_bool':False,
                                     'ignore_string_list':[''],
                                     'ignore_string_path_bool':False,
                                     'ignore_string_path_list':[''],
                                     'ignore_filename_extension_bool':False,
                                     'ignore_filename_extension_list':['']}
        self.dt_main_parameters = {'subdirectory':False,
                                   'directory':os.getcwd()}
        self.emst_filter_parameters = {'string_list':[''],
                                       'extension_list':[''],
                                       'ignore_string_bool':False,
                                       'ignore_string_list':[''],
                                       'ignore_string_path_bool':False,
                                       'ignore_string_path_list':[''],
                                       'ignore_filename_extension_bool':False,
                                       'ignore_filename_extension_list':['']}
        self.emst_main_parameters = {'subdirectory':False,
                                     'directory':self.botui.tab['EMS conversion tab'].dname}

    def test_add_tabs_loading_None(self):
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab

    def test_add_tabs_loading_default(self):
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab
#        assert self.botui.tab['Delete files'].filter_widget.get_parameters() == self.dt_filter_parameters
#        assert self.botui.tab['Delete files']._get_main_parameters() == self.dt_main_parameters
#        assert self.botui.tab['EMS conversion tab'].filter_widget.get_parameters() == self.emst_filter_parameters
#        assert self.botui.tab['EMS conversion tab']._get_main_parameters() == self.emst_main_parameters

    @raises(ValueError)
    def test_add_tabs_loading_exception(self):
        self.botui.add_tab(EMSConversionTab, load_settings='')
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab
        
    def test_create_tables_widget(self):
        assert type(self.botui.tables_widget) == QtWidgets.QTabWidget
        assert self.botui.tables_widget.widget(0) == self.botui.files_table
        assert self.botui.tables_widget.widget(1) == self.botui.ignore_table
    
    def test_setup_tables(self):
        assert type(self.botui.files_table) == QtWidgets.QTableWidget
        assert type(self.botui.ignore_table) == QtWidgets.QTableWidget

    def test_fill_table_files(self):
        self._fill_table(self.botui.files_table)
        self._fill_table(self.botui.ignore_table)

    def _fill_table(self, table):
        fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
        table = self.botui.files_table
        fl = [os.getcwd()+ fname for fname in fl]
        self.botui._fill_table(table, fl)
        assert table.rowCount() == len(fl)
        for i, fullfilename in enumerate(fl):
            fulldirname, filename = os.path.split(fullfilename)
            path, dirname = os.path.split(fulldirname)
            assert table.item(i, 0).text() == path
            assert table.item(i, 1).text() == dirname
            assert table.item(i, 2).text() == filename

    def test_get_tab_with_name(self):
        name = 'Delete files'
        tab = self.botui.get_tab_with_name(name)
        assert tab.name == 'Delete files'
        assert isinstance(tab, DeleteTab)
        assert self.botui.tab[name].name == 'Delete files'

    def test_get_current_tab_widget(self):
        # select delete tab
        name = 'Delete files'
        tab = self.botui.get_tab_with_name(name)
        self.botui.headers_tab.setCurrentWidget(tab)
        assert self.botui._get_current_tab_widget() == tab
class Test_BatchOperationToolUI:
    def setup_method(self):
        self.botui = BatchOperationToolUI()
        self.botui.add_tab(EMSConversionTab, name='EMS conversion tab')
        self.botui.add_tab(DeleteTab, name='Delete files')
        # match the default_settings.json files from the library
        self.dt_filter_parameters = {
            'string_list': [''],
            'extension_list': [''],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.dt_main_parameters = {
            'subdirectory': False,
            'directory': os.getcwd()
        }
        self.emst_filter_parameters = {
            'string_list': [''],
            'extension_list': [''],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.emst_main_parameters = {
            'subdirectory': False,
            'directory': self.botui.tab['EMS conversion tab'].dname
        }

    def test_add_tabs_loading_None(self):
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab

    def test_add_tabs_loading_default(self):
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab
#        assert self.botui.tab['Delete files'].filter_widget.get_parameters() == self.dt_filter_parameters
#        assert self.botui.tab['Delete files']._get_main_parameters() == self.dt_main_parameters
#        assert self.botui.tab['EMS conversion tab'].filter_widget.get_parameters() == self.emst_filter_parameters
#        assert self.botui.tab['EMS conversion tab']._get_main_parameters() == self.emst_main_parameters

    @raises(ValueError)
    def test_add_tabs_loading_exception(self):
        self.botui.add_tab(EMSConversionTab, load_settings='')
        assert type(self.botui.tab['EMS conversion tab']) == EMSConversionTab

    def test_create_tables_widget(self):
        assert type(self.botui.tables_widget) == QtWidgets.QTabWidget
        assert self.botui.tables_widget.widget(0) == self.botui.files_table
        assert self.botui.tables_widget.widget(1) == self.botui.ignore_table

    def test_setup_tables(self):
        assert type(self.botui.files_table) == QtWidgets.QTableWidget
        assert type(self.botui.ignore_table) == QtWidgets.QTableWidget

    def test_fill_table_files(self):
        self._fill_table(self.botui.files_table)
        self._fill_table(self.botui.ignore_table)

    def _fill_table(self, table):
        fl = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
        table = self.botui.files_table
        fl = [os.getcwd() + fname for fname in fl]
        self.botui._fill_table(table, fl)
        assert table.rowCount() == len(fl)
        for i, fullfilename in enumerate(fl):
            fulldirname, filename = os.path.split(fullfilename)
            path, dirname = os.path.split(fulldirname)
            assert table.item(i, 0).text() == path
            assert table.item(i, 1).text() == dirname
            assert table.item(i, 2).text() == filename

    def test_get_tab_with_name(self):
        name = 'Delete files'
        tab = self.botui.get_tab_with_name(name)
        assert tab.name == 'Delete files'
        assert isinstance(tab, DeleteTab)
        assert self.botui.tab[name].name == 'Delete files'

    def test_get_current_tab_widget(self):
        # select delete tab
        name = 'Delete files'
        tab = self.botui.get_tab_with_name(name)
        self.botui.headers_tab.setCurrentWidget(tab)
        assert self.botui._get_current_tab_widget() == tab
Exemplo n.º 20
0
def main():
    app = QtGui.QApplication(sys.argv)
    batch_operation_widget = BatchOperationToolUI()
    batch_operation_widget.show()
    sys.exit(app.exec_())
class Test_EMSConversionTab:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.filter_parameters = {'string_list':[''],
                                  'extension_list':['ext', 'ext2', 'abc'],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':['']}
        self.main_parameters = {'subdirectory':True,
                                'directory':os.getcwd()}  
        self.operation_parameters = {'extension_list':[],
                                     'data_type':'image',
                                     'log_to_linear_scale':True,
                                     'overwrite':False}
        
        self.botui = BatchOperationToolUI(load_settings=None)
        name ='EMS conversion'
        self.botui.add_tab(EMSConversionTab, name=name)
        self.emsct = self.botui.tab[name]

    def test_set_filter_parameters(self):
        self.emsct.set_filter_parameters(**self.filter_parameters)
        for key in list(self.filter_parameters.keys()):
            assert self.emsct.filter_widget.parameters[key] == self.filter_parameters[key]

    def test_set_operation_parameters(self):
        self.emsct.set_operation_parameters(**self.operation_parameters)
        for key in list(self.operation_parameters.keys()):
            assert self.emsct.ems_conversion_widget.parameters[key] == self.operation_parameters[key]

    def test_load_config(self):       
        config_fname = 'default_settings.json'
        path = get_dirname_file(__file__)
        self.emsct.load_config(os.path.join(path, config_fname))
        assert self.emsct.main_parameters['directory'] == os.path.expanduser("~")
        assert self.emsct.main_parameters['subdirectory'] == False

        assert self.emsct.filter_widget.parameters['string_list'] == [""]
        assert self.emsct.filter_widget.parameters['extension_list'] == [""]
        assert self.emsct.filter_widget.parameters['ignore_string_bool'] == False
        assert self.emsct.filter_widget.parameters['ignore_string_list'] == [""]
        assert self.emsct.filter_widget.parameters['ignore_string_path_bool'] == False
        assert self.emsct.filter_widget.parameters['ignore_string_path_list'] == [""]

        assert self.emsct.ems_conversion_widget.parameters['extension_list'] == []
        assert self.emsct.ems_conversion_widget.parameters['data_type'] == 'image'
        assert self.emsct.ems_conversion_widget.parameters['log_to_linear_scale'] == True
        assert self.emsct.ems_conversion_widget.parameters['overwrite'] == False
        
    def test_save_config(self):
        # setting parameters
        self.emsct._set_main_parameters(**self.main_parameters)
        self.emsct.set_filter_parameters(**self.filter_parameters)
        self.emsct.set_operation_parameters(**self.operation_parameters)
        parameters = merge_two_dicts(self.main_parameters, self.filter_parameters)
        # saving parameters
        fname = 'test_save_config.json'
        self.emsct._save_config(fname)
        # test
        with open(fname, "r") as data_file:
            config = json.load(data_file)
        config_parameters = merge_two_dicts(config['Main'], config['Filter'])

        for key in list(config_parameters.keys()):
            assert config_parameters[key] == parameters[key]

        os.remove(fname)
class Test_EMSConversionTab:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.filter_parameters = {
            'string_list': [''],
            'extension_list': ['ext', 'ext2', 'abc'],
            'ignore_string_bool': False,
            'ignore_string_list': [''],
            'ignore_string_path_bool': False,
            'ignore_string_path_list': [''],
            'ignore_filename_extension_bool': False,
            'ignore_filename_extension_list': ['']
        }
        self.main_parameters = {'subdirectory': True, 'directory': os.getcwd()}
        self.operation_parameters = {
            'extension_list': [],
            'data_type': 'image',
            'log_to_linear_scale': True,
            'overwrite': False
        }

        self.botui = BatchOperationToolUI(load_settings=None)
        name = 'EMS conversion'
        self.botui.add_tab(EMSConversionTab, name=name)
        self.emsct = self.botui.tab[name]

    def test_set_filter_parameters(self):
        self.emsct.set_filter_parameters(**self.filter_parameters)
        for key in list(self.filter_parameters.keys()):
            assert self.emsct.filter_widget.parameters[
                key] == self.filter_parameters[key]

    def test_set_operation_parameters(self):
        self.emsct.set_operation_parameters(**self.operation_parameters)
        for key in list(self.operation_parameters.keys()):
            assert self.emsct.ems_conversion_widget.parameters[
                key] == self.operation_parameters[key]

    def test_load_config(self):
        config_fname = 'default_settings.json'
        path = get_dirname_file(__file__)
        self.emsct.load_config(os.path.join(path, config_fname))
        assert self.emsct.main_parameters['directory'] == os.path.expanduser(
            "~")
        assert self.emsct.main_parameters['subdirectory'] == False

        assert self.emsct.filter_widget.parameters['string_list'] == [""]
        assert self.emsct.filter_widget.parameters['extension_list'] == [""]
        assert self.emsct.filter_widget.parameters[
            'ignore_string_bool'] == False
        assert self.emsct.filter_widget.parameters['ignore_string_list'] == [
            ""
        ]
        assert self.emsct.filter_widget.parameters[
            'ignore_string_path_bool'] == False
        assert self.emsct.filter_widget.parameters[
            'ignore_string_path_list'] == [""]

        assert self.emsct.ems_conversion_widget.parameters[
            'extension_list'] == []
        assert self.emsct.ems_conversion_widget.parameters[
            'data_type'] == 'image'
        assert self.emsct.ems_conversion_widget.parameters[
            'log_to_linear_scale'] == True
        assert self.emsct.ems_conversion_widget.parameters[
            'overwrite'] == False

    def test_save_config(self):
        # setting parameters
        self.emsct._set_main_parameters(**self.main_parameters)
        self.emsct.set_filter_parameters(**self.filter_parameters)
        self.emsct.set_operation_parameters(**self.operation_parameters)
        parameters = merge_two_dicts(self.main_parameters,
                                     self.filter_parameters)
        # saving parameters
        fname = 'test_save_config.json'
        self.emsct._save_config(fname)
        # test
        with open(fname, "r") as data_file:
            config = json.load(data_file)
        config_parameters = merge_two_dicts(config['Main'], config['Filter'])

        for key in list(config_parameters.keys()):
            assert config_parameters[key] == parameters[key]

        os.remove(fname)
Exemplo n.º 23
0
class Test_BaseTab:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()

    def setup_method(self):
        self.filter_parameters = {'string_list':[''],
                                  'extension_list':['ext', 'ext2', 'abc'],
                                  'ignore_string_bool':False,
                                  'ignore_string_list':[''],
                                  'ignore_string_path_bool':False,
                                  'ignore_string_path_list':[''],
                                  'ignore_filename_extension_bool':False,
                                  'ignore_filename_extension_list':['']}
        self.main_parameters = {'subdirectory':True,
                                'directory':os.getcwd()}  

        self.botui = BatchOperationToolUI(load_settings=None)
        # dummy tab required for initialisation
        self.botui.add_tab(DeleteTab)
        self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)

    def test_init_main_parameters(self):
        self.bt._init_main_parameters(False)
        assert self.bt.main_parameters['directory'] == os.getcwd()
        assert self.bt.main_parameters['subdirectory'] == False

        self.bt._init_main_parameters(True)
        assert self.bt.main_parameters['directory'] == os.getcwd()
        assert self.bt.main_parameters['subdirectory'] == True
        
    def test_load_config(self):       
        config_fname = 'default_settings.json'
        path = os.path.join(os.path.dirname(__file__))
        self.bt.load_config(os.path.join(path, config_fname))
        assert self.bt.main_parameters['directory'] == os.path.expanduser("~")
        assert self.bt.main_parameters['subdirectory'] == True

        assert self.bt.filter_widget.parameters['string_list'] == [""]
        assert self.bt.filter_widget.parameters['extension_list'] == [""]
        assert self.bt.filter_widget.parameters['ignore_string_bool'] == False
        assert self.bt.filter_widget.parameters['ignore_string_list'] == [""]
        assert self.bt.filter_widget.parameters['ignore_string_path_bool'] == False
        assert self.bt.filter_widget.parameters['ignore_string_path_list'] == [""]
        assert self.bt.filter_widget.parameters['ignore_filename_extension_bool'] == False
        assert self.bt.filter_widget.parameters['ignore_filename_extension_list'] == [""]
        
    def test_save_config(self):
        # setting parameters
        self.bt._set_main_parameters(**self.main_parameters)
        self.bt.set_filter_parameters(**self.filter_parameters)
        parameters = merge_two_dicts(self.main_parameters, self.filter_parameters)
        # saving parameters
        fname = 'test_save_config.json'
        self.bt._save_config(fname)
        # test
        with open(fname, "r") as data_file:
            config = json.load(data_file)
        config_parameters = merge_two_dicts(config['Main'], config['Filter'])

        for key in list(config_parameters.keys()):
            assert config_parameters[key] == parameters[key]

        os.remove(fname)

    def test_set_main_parameters(self):      
        self.bt._set_main_parameters(**self.main_parameters)
        for key in list(self.main_parameters.keys()):
            assert self.bt.main_parameters[key] == self.main_parameters[key]
    
    def test_get_main_parameters(self):   
        self.bt._set_main_parameters(**self.main_parameters)
        assert self.main_parameters == self.bt._get_main_parameters()

    def test_update_subdirectory(self):
        pass
    
    def test_get_files_lists(self):
        pass

    def test_set_filter_parameters(self):
        self.bt.set_filter_parameters(**self.filter_parameters)
        for key in list(self.filter_parameters.keys()):
            assert self.bt.filter_widget.parameters[key] == self.filter_parameters[key]
    
    def test_dname(self):
        dname = 'dummy_dname'
        self.bt.dname = dname
        assert self.bt.filter_widget.dname == dname
        assert self.bt.dname == dname
        
    def test_set_subdirectory(self):
        subdirectory = True
        self.bt.set_subdirectory(subdirectory)
        assert self.bt.main_parameters['subdirectory'] == subdirectory
    
    def test_get_subdirectory(self):
        subdirectory = True
        self.bt.set_subdirectory(subdirectory)
        assert self.bt.get_subdirectory() == subdirectory
class Test_FilterWidgetBase:
    @classmethod
    def setup_class(self):
        self.app = QtWidgets.QApplication(sys.argv)

    @classmethod
    def teardown_class(self):
        self.app.quit()
    
    def setup_method(self):
        self.parameters = {'string_list':[''],
                           'extension_list':['ext', 'ext2', 'abc'],
                           'ignore_string_bool':False,
                           'ignore_string_list':[''],
                           'ignore_string_path_bool':False,
                           'ignore_string_path_list':[''],
                           'ignore_filename_extension_bool':False,
                           'ignore_filename_extension_list':['']}
        self.tests_dir = get_dirname_file()
        self.botui = BatchOperationToolUI(load_settings=None)
        self.botui.add_tab(DeleteTab)
        self.bt = BaseTab(self.botui.fill_tables, parent=self.botui)
        self.fw = FilterWidgetBase(parent=self.bt)
        self.fw.dname = self.tests_dir
        self.fl_short = ['fname0.ext', 'fname1.ext', 'fname2.ext2', 'fname3.abc']
        self.fl = self._convert_file_list(sorted(self.fl_short))

    def _convert_file_list(self, file_list):
        return convert_file_list_absolute_path(file_list, self.tests_dir)
    
    def test_set_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.fw.parameters['string_list'] == self.fw.stringLineEdit.text().split(', ')
        assert self.fw.parameters['extension_list'] == self.fw.extentionLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_string_bool'] == self.fw.ignoreStringCheckBox.isChecked()
        assert self.fw.parameters['ignore_string_list'] == self.fw.ignoreStringLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_string_path_bool'] == self.fw.ignoreStringPathCheckBox.isChecked()
        assert self.fw.parameters['ignore_string_path_list'] == self.fw.ignoreStringPathLineEdit.text().split(', ')
        assert self.fw.parameters['ignore_filename_extension_bool'] == self.fw.ignorefilenameextensionCheckBox.isChecked()
        assert self.fw.parameters['ignore_filename_extension_list'] == self.fw.ignorefilenameextensionLineEdit.text().split(', ')

    def test_get_parameter(self):
        self.fw.set_parameters(**self.parameters)
        assert self.parameters == self.fw.get_parameters()   
    
#    def test_update_files_lists(self):
#        # Create files
#        create_files(self.fl)
#        self.fw.set_parameters(**self.parameters)
#        self.fw.set_parameters(string_list=self.fl_short)
#        print self.fw.dname, self.fw.parameters['string_list']
#        self.fw.update_files_lists()
#        # Expected results
#        files_to_use_list = [os.path.join(self.tests_dir, fname) for fname in self.fl]
#        files_to_ignore_list = substract_lists(os.listdir('.'), self.fl)
#
#        list_temp = listdir_absolute_path(self.tests_dir)
#        files_to_ignore_list = sorted(substract_lists(list_temp, self.fl))
#
#        print '1:', len(files_to_use_list), files_to_use_list
#        print '12:', len(self.fw.files_to_use_list), self.fw.files_to_use_list
##        print '2:', len(files_to_ignore_list), files_to_ignore_list
##        print '22:', len(self.fw.get_files_lists()[1]), self.fw.get_files_lists()[1]     
#        
#        assert self.fw.get_files_lists() == (files_to_use_list, files_to_ignore_list)
#        # Remove files
#        remove_files(self.fl)    
       
    def test_get_subdirectory(self):
        subdirectory = self.bt.get_subdirectory()
        assert subdirectory == self.fw._get_subdirectory()
        
    def test_dname(self):
        dname = 'dummy_dname'
        self.fw.dname = dname
        assert self.fw.dname == dname