def _test_wlvllogg_import_from_diveroffice_files(self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion, mock_messagebarandlog): mocks_notfoundquestion = [] for answer, value in [['ok', 'rb1'], ['ok', 'rb2'], ['skip', 'rb3']]: a_mock = MagicMock() a_mock.answer = answer a_mock.value = value a_mock.reuse_column = 'location' mocks_notfoundquestion.append(a_mock) mock_notfoundquestion.side_effect = mocks_notfoundquestion mock_filenames.return_value = filenames mock_encoding.return_value = ['utf-8'] ms = MagicMock() ms.settingsdict = OrderedDict() importer = DiverofficeImport(self.iface.mainWindow(), ms) importer.select_files_and_load_gui() importer.start_import(importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked) print('\n'.join([str(x) for x in mock_messagebarandlog.mock_calls]))
def _test_wlvllogg_import_from_diveroffice_files(self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion): mock_notfoundquestion.return_value.answer = 'ok' mock_notfoundquestion.return_value.value = 'rb1' mock_notfoundquestion.return_value.reuse_column = 'location' mock_filenames.return_value = filenames mock_encoding.return_value = ['utf-8'] ms = MagicMock() ms.settingsdict = OrderedDict() importer = DiverofficeImport(self.iface.mainWindow(), ms) importer.select_files_and_load_gui() importer.start_import(importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked)
def test_filter_dates_from_filedata(self): file_data = [['obsid', 'date_time'], ['rb1', '2015-05-01 00:00:00'], ['rb1', '2016-05-01 00:00'], ['rb2', '2015-05-01 00:00:00'], ['rb2', '2016-05-01 00:00'], ['rb3', '2015-05-01 00:00:00'], ['rb3', '2016-05-01 00:00']] obsid_last_imported_dates = {'rb1': [(datestring_to_date('2016-01-01 00:00:00'),)], 'rb2': [(datestring_to_date('2017-01-01 00:00:00'),)]} test_file_data = utils_for_tests.create_test_string(DiverofficeImport.filter_dates_from_filedata(file_data, obsid_last_imported_dates)) reference_file_data = '''[[obsid, date_time], [rb1, 2016-05-01 00:00], [rb3, 2015-05-01 00:00:00], [rb3, 2016-05-01 00:00]]''' assert test_file_data == reference_file_data
def _test_wlvllogg_import_from_diveroffice_files( self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion, mock_messagebarandlog): mocks_notfoundquestion = [] for answer, value in [['ok', 'rb1'], ['ok', 'rb2'], ['skip', 'rb3']]: a_mock = MagicMock() a_mock.answer = answer a_mock.value = value a_mock.reuse_column = 'location' mocks_notfoundquestion.append(a_mock) mock_notfoundquestion.side_effect = mocks_notfoundquestion mock_filenames.return_value = filenames mock_encoding.return_value = ['utf-8'] ms = MagicMock() ms.settingsdict = OrderedDict() importer = DiverofficeImport(self.iface.mainWindow(), ms) importer.select_files_and_load_gui() importer.start_import(importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked) print('\n'.join([ str(x) for x in mock_messagebarandlog.mock_calls ]))
def _test_wlvllogg_import_from_diveroffice_files( self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion): mock_notfoundquestion.return_value.answer = 'cancel' mock_notfoundquestion.return_value.value = 'rb1' mock_notfoundquestion.return_value.reuse_column = 'location' mock_filenames.return_value = filenames mock_encoding.return_value = ['utf-8'] ms = MagicMock() ms.settingsdict = OrderedDict() importer = DiverofficeImport(self.iface.mainWindow(), ms) importer.select_files_and_load_gui() importer.import_all_data.checked = True importer.confirm_names.checked = False answer = importer.start_import( importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked) return answer
def test_parse_diveroffice_warning_missing_date_time( self, mock_messagebarandlog): f = (u'Location=rb1', u'Temperature[°C];2:Spec.cond.[mS/cm];dada', u'5.18;2;2016/03/15 10:30:00', u'0.6;3;2016/03/15 11:00:00') charset_of_diverofficefile = u'cp1252' with utils.tempinput(u'\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file( path, charset_of_diverofficefile) assert file_data == u'skip' assert len(mock_messagebarandlog.mock_calls) == 1
def test_parse_diveroffice_warning_missing_date_time(self, mock_messagebarandlog): f = ('Location=rb1', 'Temperature[°C];2:Spec.cond.[mS/cm];dada', '5.18;2;2016/03/15 10:30:00', '0.6;3;2016/03/15 11:00:00' ) charset_of_diverofficefile = 'cp1252' with utils.tempinput('\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file(path, charset_of_diverofficefile) assert file_data == 'skip' assert len(mock_messagebarandlog.mock_calls) == 1
def test_parse_diveroffice_file_comma_sep_comma_dec_failed(self): f = ('Location=rb1', 'Date/time,Water head[cm],Temperature[°C]', '2016/03/15 10:30:00,26,9,5,18', '2016/03/15 11:00:00,157,7,0,6' ) charset_of_diverofficefile = 'cp1252' with utils.tempinput('\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file(path, charset_of_diverofficefile) test_string = utils_for_tests.create_test_string(file_data) reference_string = 'cancel' assert test_string == reference_string
def test_parse_diveroffice_file_changed_order(self): f = ('Location=rb1', 'Temperature[°C];2:Spec.cond.[mS/cm];Date/time;Water head[cm]', '5.18;2;2016/03/15 10:30:00;26.9', '0.6;3;2016/03/15 11:00:00;157.7' ) charset_of_diverofficefile = 'cp1252' with utils.tempinput('\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file(path, charset_of_diverofficefile) test_string = utils_for_tests.create_test_string(file_data[0]) reference_string = '[[date_time, head_cm, temp_degc, cond_mscm], [2016-03-15 10:30:00, 26.9, 5.18, 2.0], [2016-03-15 11:00:00, 157.7, 0.6, 3.0]]' assert test_string == reference_string assert os.path.basename(path) == file_data[1] assert file_data[2] == 'rb1'
def test_parse_diveroffice_file_semicolon_sep(self): f = ('Location=rb1', 'Date/time;Water head[cm];Temperature[°C]', '2016/03/15 10:30:00;26.9;5.18', '2016/03/15 11:00:00;157.7;0.6' ) charset_of_diverofficefile = 'cp1252' with utils.tempinput('\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file(path, charset_of_diverofficefile) test_string = utils_for_tests.create_test_string(file_data[0]) reference_string = '[[date_time, head_cm, temp_degc, cond_mscm], [2016-03-15 10:30:00, 26.9, 5.18, ], [2016-03-15 11:00:00, 157.7, 0.6, ]]' assert test_string == reference_string assert os.path.basename(path) == file_data[1] assert file_data[2] == 'rb1'
def test_parse_diveroffice_warning_missing_head_cm(self, mock_messagebarandlog): f = (u'Location=rb1', u'Temperature[°C];2:Spec.cond.[mS/cm];Date/time', u'5.18;2;2016/03/15 10:30:00', u'0.6;3;2016/03/15 11:00:00') charset_of_diverofficefile = u'cp1252' with utils.tempinput(u'\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file( path, charset_of_diverofficefile) test_string = utils_for_tests.create_test_string(file_data[0]) reference_string = u'[[date_time, head_cm, temp_degc, cond_mscm], [2016-03-15 10:30:00, , 5.18, 2.0], [2016-03-15 11:00:00, , 0.6, 3.0]]' assert len(mock_messagebarandlog.mock_calls) == 1 assert test_string == reference_string assert os.path.basename(path) == file_data[1] assert file_data[2] == u'rb1'
def test_parse_diveroffice_warning_missing_head_cm(self, mock_messagebarandlog): f = ('Location=rb1', 'Temperature[°C];2:Spec.cond.[mS/cm];Date/time', '5.18;2;2016/03/15 10:30:00', '0.6;3;2016/03/15 11:00:00' ) charset_of_diverofficefile = 'cp1252' with utils.tempinput('\n'.join(f), charset_of_diverofficefile) as path: file_data = DiverofficeImport.parse_diveroffice_file(path, charset_of_diverofficefile) test_string = utils_for_tests.create_test_string(file_data[0]) reference_string = '[[date_time, head_cm, temp_degc, cond_mscm], [2016-03-15 10:30:00, , 5.18, 2.0], [2016-03-15 11:00:00, , 0.6, 3.0]]' assert len(mock_messagebarandlog.mock_calls) == 1 assert test_string == reference_string assert os.path.basename(path) == file_data[1] assert file_data[2] == 'rb1'
def _test_wlvllogg_import_from_diveroffice_files( self, filenames, mock_filenames, mock_skippopup, mock_encoding, mock_iface, mock_askuser, mock_notfoundquestion): mock_notfoundquestion.return_value.answer = u'ok' mock_notfoundquestion.return_value.value = u'rb1' mock_notfoundquestion.return_value.reuse_column = u'location' mock_filenames.return_value = filenames mock_encoding.return_value = [u'utf-8'] ms = MagicMock() ms.settingsdict = OrderedDict() importer = DiverofficeImport(self.iface.mainWindow(), ms) importer.select_files_and_load_gui() importer.import_all_data.checked = True importer.confirm_names.checked = False importer.date_time_filter.from_date = u'2016-03-15 11:00:00' importer.date_time_filter.to_date = u'2016-04-15 10:30:00' importer.start_import(importer.files, importer.skip_rows.checked, importer.confirm_names.checked, importer.import_all_data.checked, importer.date_time_filter.from_date, importer.date_time_filter.to_date)