def test_parse_user_input_to_files_returns_full_filepath(self): files = [ "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs", "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs" ] for file_name in files: parsed_file = utils.parse_user_input_to_files(file_name) self.assertEqual(parsed_file, [file_name])
def get_filenames_from_user(self): file_filter = file_utils.filter_for_extensions( file_utils.allowed_extensions) directory = "" filenames = self._view.show_file_browser_and_return_selection( file_filter, [directory], multiple_files=self._multiple_files) # validate filenames = file_utils.parse_user_input_to_files(";".join(filenames)) filenames = file_utils.remove_duplicated_files_from_list(filenames) return filenames
def test_parse_user_input_to_files_filters_files_with_incorrect_extension( self): user_input = "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs;" \ "C:" + os.sep + "dir1" + os.sep + "dir2" + \ os.sep + "EMU0001235.txt;C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001236.png" files = [ "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs" ] parsed_file = utils.parse_user_input_to_files(user_input, ['nxs']) self.assertEqual(parsed_file, files)
def test_parse_user_input_to_files_returns_list_correctly(self): user_input = "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs;" \ "C:" + os.sep + "dir1" + os.sep + "dir2" + \ os.sep + "EMU0001235.nxs;C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001236.nxs" files = [ "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001234.nxs", "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001235.nxs", "C:" + os.sep + "dir1" + os.sep + "dir2" + os.sep + "EMU0001236.nxs" ] parsed_file = utils.parse_user_input_to_files(user_input) self.assertEqual(parsed_file, files)
def handle_file_changed_by_user(self): user_input = self._view.get_file_edit_text() filenames = file_utils.parse_user_input_to_files(user_input) filenames = file_utils.remove_duplicated_files_from_list(filenames) self.filenames = filenames if not filenames: self._view.reset_edit_to_cached_value() return if not self._multiple_files and len(filenames) > 1: self._view.warning_popup( "Multiple files selected in single file mode") self._view.reset_edit_to_cached_value() return if self._multiple_file_mode == "Co-Add": # We don't want to allow messy appending when co-adding self.clear_loaded_data() self.handle_loading(filenames)
def test_parse_user_input_to_files_returns_single_file_as_list(self): filename = "EMU0001234.nxs" parsed_file = utils.parse_user_input_to_files(filename) self.assertEqual(parsed_file, [filename])