def test_create_parameter_groups_using_stored_settings_no_settings(): stored_settings = [(0, (('key0_1', 'value0_1'), ('key0_2', 'value0_2'))), (1, (('key1_1', 'value1_1'), ('key1_2', 'value1_2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) stored_settings = ExportToFieldLogger.update_stored_settings(parameter_groups) assert stored_settings == []
def test_create_export_printlist_assert_no_critical_msg( mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = { u'1': (123, 465), u'2': (123, 465), u'3': (123, 465) } stored_settings = [(0, ((u'input_field_group_list', [ u'p1.u1;it1:h1', u'l.comment;test;make a comment' ]), (u'location_suffix', u'ls'), (u'sublocation_suffix', u'with_p1_u1_and_l_comment'))), (1, ((u'input_field_group_list', [u'comment;test;make a general comment' ]), (u'location_suffix', u'ls'), (u'sublocation_suffix', u'with_comment')))] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings( stored_settings, mock_connect) parameter_groups[0]._obsid_list.paste_data([u'1', u'2', u'3']) parameter_groups[1]._obsid_list.paste_data([u'1', u'2', u'3']) printlist = ExportToFieldLogger.create_export_printlist( parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_not_called() reference_string = u'[FileVersion 1;3, NAME;INPUTTYPE;HINT, p1.u1;it1:h1 , l.comment;test;make a comment , comment;test;make a general comment , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.ls;1.ls.with_comment;123;465;comment, 1.ls;1.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 2.ls;2.ls.with_comment;123;465;comment, 2.ls;2.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 3.ls;3.ls.with_comment;123;465;comment, 3.ls;3.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment]' assert test_string == reference_string
def test_create_export_printlist_correct_order(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = { u'1': (u'lat1', u'lon1'), u'2': (u'lat2', u'lon2'), u'4': (u'lat4', u'lon4') } tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [ (0, ((u'input_field_group_list', [u'par4;type1;hint1', u'par1;type1;hint1']), (u'sublocation_suffix', u'group'), (u'location_suffix', u'proj'))), (1, ((u'input_field_group_list', [u'par2;type2;hint2']), (u'sublocation_suffix', u'group'), (u'location_suffix', u'proj2'))) ] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings( stored_settings, mock_connect) parameter_groups[0]._obsid_list.paste_data([u'1', u'4']) parameter_groups[1]._obsid_list.paste_data([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist( parameter_groups) test_string = create_test_string(printlist) reference_string = u'[FileVersion 1;3, NAME;INPUTTYPE;HINT, par4;type1;hint1 , par1;type1;hint1 , par2;type2;hint2 , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par4|par1, 2.proj2;2.proj2.group;lat2;lon2;par2, 4.proj;4.proj.group;lat4;lon4;par4|par1, 4.proj2;4.proj2.group;lat4;lon4;par2]' assert reference_string == test_string
def test_create_export_objects_using_stored_settings_no_settings(): tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'key0_1', u'value0_1'), (u'key0_2', u'value0_2'))), (1, ((u'key1_1', u'value1_1'), (u'key1_2', u'value1_2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) stored_settings = ExportToFieldLogger.update_stored_settings(export_objects) assert stored_settings == []
def test_create_parameter_groups_using_stored_settings(): stored_settings = [(0, (('input_field_group_list', ['p1.u1;it1:h1, p2.u2;it2:h2']), ('key0_2', 'value0_2'))), (1, (('location_suffix', 'value1_1'), ('key1_2', 'value1_2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(parameter_groups)) reference = '[[0, ((input_field_group_list, [p1.u1;it1:h1, p2.u2;it2:h2]))], [1, ((location_suffix, value1_1))]]' assert stored_settings == reference
def test_create_parameter_groups_using_stored_settings_nonexisting_variable_name_empty_result(): stored_settings = [(0, (('parameter_liöst', ['p1.u1;it1:h1, p2.u2;it2:h2']), ('key0_2', 'value0_2'))), (1, (('location_s%uffix', 'value1_1'), ('key1_2', 'value1_2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(parameter_groups)) reference = '[]' assert stored_settings == reference
def test_create_parameter_groups_using_stored_settings_nonexisting_variable_name(): stored_settings = [(0, (('parameter_input_field_lNONEXISTING', ['p1.u1;it1:h1, p2.u2;it2:h2']), ('key0_2', 'value0_2'))), (1, (('location_suffix', 'value1_1'), ('key1_2', 'value1_2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(parameter_groups)) reference = '[[0, ((location_suffix, value1_1))]]' assert stored_settings == reference
def test_create_parameter_browser_using_stored_settings_nonexisting_variable_name(): tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('input_field_lNONEXISTING', ['p1.u1;it1:h1', 'p2.u2;it2:h2']), ('key0_2', 'value0_2'))), (1, (('location_suffix', 'value1_1'), ('key1_2', 'value1_2')))] parameter_browser = export_fieldlogger.ParameterBrowser(tables_columns) ExportToFieldLogger.update_parameter_browser_using_stored_settings(stored_settings, parameter_browser) test_string = create_test_string(ExportToFieldLogger.update_stored_settings([parameter_browser])) reference = '[]' assert test_string == reference
def test_create_export_objects_using_stored_settings(): tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'value0_1'), (u'key0_2', u'value0_2'))), (1, ((u'location_suffix', u'value1_1'), (u'key1_2', u'value1_2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) stored_settings = create_test_string(ExportToFieldLogger.update_stored_settings(export_objects)) reference = u'[(0, ((final_parameter_name, value0_1))), (1, ((location_suffix, value1_1)))]' assert stored_settings == reference
def test_create_parameter_groups_using_stored_settings_no_settings(): stored_settings = [ (0, ((u'key0_1', u'value0_1'), (u'key0_2', u'value0_2'))), (1, ((u'key1_1', u'value1_1'), (u'key1_2', u'value1_2'))) ] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings( stored_settings, mock_connect) stored_settings = ExportToFieldLogger.update_stored_settings( parameter_groups) assert stored_settings == []
def test_create_export_printlist_assert_empty_input_field_group_list(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {'1': (None, None)} tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('final_parameter_name', 'par1'), ('sublocation_suffix', 'group'), ('location_suffix', 'proj')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) parameter_groups[0]._obsid_list.paste_data(['1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.warning.assert_called_with(bar_msg='Warning: Empty input fields list for group nr 1')
def test_create_export_printlist_assert_no_latlon(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {'1': (None, None)} tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('input_field_group_list', ['p1.u1;it1:h1 ']), ('sublocation_suffix', 'proj.group'), ('location_suffix', 'proj')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) parameter_groups[0]._obsid_list.paste_data(['1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_called_with(bar_msg='Critical: Obsid 1 did not have lat-lon coordinates. Check obs_points table')
def test_create_parameter_groups_using_stored_settings_string(self, mock_iface, mock_tables_columns, mock_settingsstrings, mock_settingsbarandlog, mock_popup): mock_tables_columns.return_value = {} mock_ms = MagicMock() mock_ms.settingsdict = {'fieldlogger_export_pbrowser': '', 'fieldlogger_export_pgroups': ''} mock_settingsstrings.side_effect = [('[[0, (("input_field_list", ["DO.mg/L;numberDecimal|numberSigned; ", "comment;text;Obsid related comment"], ), )]]', True), ('[[0, (("input_field_group_list", ["DO.mg/L;numberDecimal|numberSigned; ", "comment;text;Obsid related comment"], ), ("location_suffix", "2766", ), ("sublocation_suffix", "level", ), )], [1, (("input_field_group_list", ["comment;text;Obsid related comment"], ), ("location_suffix", "1234", ), ("sublocation_suffix", "comment", ), )]]', True)] exportfieldlogger = ExportToFieldLogger(None, mock_ms) exportfieldlogger.settings_strings_dialogs() assert mock_ms.settingsdict['fieldlogger_export_pbrowser'] == '[[0, (("input_field_list", ["DO.mg/L;numberDecimal|numberSigned; ", "comment;text;Obsid related comment"], ), )]]' assert mock_ms.settingsdict['fieldlogger_export_pgroups'] == '[[0, (("input_field_group_list", ["DO.mg/L;numberDecimal|numberSigned; ", "comment;text;Obsid related comment"], ), ("location_suffix", "2766", ), ("sublocation_suffix", "level", ), )], [1, (("input_field_group_list", ["comment;text;Obsid related comment"], ), ("location_suffix", "1234", ), ("sublocation_suffix", "comment", ), )]]'
def test_create_parameter_groups_using_stored_settings_nonexisting_variable_name( ): stored_settings = [ (0, ((u'parameter_liöst', [u'p1.u1;it1:h1, p2.u2;it2:h2']), (u'key0_2', u'value0_2'))), (1, ((u'location_suffix', u'value1_1'), (u'key1_2', u'value1_2'))) ] mock_connect = MagicMock() parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings( stored_settings, mock_connect) stored_settings = create_test_string( ExportToFieldLogger.update_stored_settings(parameter_groups)) reference = u'[[0, ((location_suffix, value1_1))]]' assert stored_settings == reference
def test_create_export_printlist_assert_no_critical_msg(mock_MessagebarAndLog): latlons = {'1': (123, 465), '2': (123, 465), '3': (123, 465)} stored_settings = [(0, (('input_field_group_list', ['p1.u1;it1:h1', 'l.comment;test;make a comment']), ('location_suffix', 'ls'), ('sublocation_suffix', 'with_p1_u1_and_l_comment'))), (1, (('input_field_group_list', ['comment;test;make a general comment']), ('location_suffix', 'ls'), ('sublocation_suffix', 'with_comment')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, None) parameter_groups[0]._obsid_list.paste_data(['1', '2', '3']) parameter_groups[1]._obsid_list.paste_data(['1', '2', '3']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups, latlons) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_not_called() reference_string = '[NAME;INPUTTYPE;HINT, p1.u1;it1:h1 , l.comment;test;make a comment , comment;test;make a general comment , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.ls;1.ls.with_comment;123;465;comment, 1.ls;1.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 2.ls;2.ls.with_comment;123;465;comment, 2.ls;2.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 3.ls;3.ls.with_comment;123;465;comment, 3.ls;3.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment]' assert test_string == reference_string
def test_create_export_printlist_duplicate_sub_location_suffixes(mock_MessagebarAndLog): latlons = {'1': ('lat1', 'lon1')} tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('input_field_group_list', ['par1;type1;hint1']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj'))), (1, (('input_field_group_list', ['par2;type2;hint2']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, None) parameter_groups[0]._obsid_list.paste_data(['1']) parameter_groups[1]._obsid_list.paste_data(['1']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups, latlons) test_string = create_test_string(printlist) reference = '[NAME;INPUTTYPE;HINT, par1;type1;hint1 , par2;type2;hint2 , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par1|par2]' assert test_string == reference
def test_create_export_printlist_correct_order(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {'1': ('lat1', 'lon1'), '2': ('lat2', 'lon2'), '4': ('lat4', 'lon4')} tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('input_field_group_list', ['par4;type1;hint1', 'par1;type1;hint1']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj'))), (1, (('input_field_group_list', ['par2;type2;hint2']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) parameter_groups[0]._obsid_list.paste_data(['1', '4']) parameter_groups[1]._obsid_list.paste_data(['2', '3', '4']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) reference_string = '[NAME;INPUTTYPE;HINT, par4;type1;hint1 , par1;type1;hint1 , par2;type2;hint2 , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par4|par1, 2.proj2;2.proj2.group;lat2;lon2;par2, 4.proj;4.proj.group;lat4;lon4;par4|par1, 4.proj2;4.proj2.group;lat4;lon4;par2]' assert reference_string == test_string
def test_get_stored_settings(): mock_ms = MagicMock() mock_ms.settingsdict = {u'test_settings_key': u'0;final_parameter_name:testname;test:gotten_test/1;key1:value1;key2:value2;key3:value3'} settingskey = u'test_settings_key' stored_settings = create_test_string(ExportToFieldLogger.get_stored_settings(mock_ms, settingskey)) reference_string = u'((0, ((final_parameter_name, testname), (test, gotten_test))), (1, ((key1, value1), (key2, value2), (key3, value3))))' assert stored_settings == reference_string
def test_create_export_printlist_not_same_latlon(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {'1': ('lat1', 'lon1'), '2': ('lat2', 'lon2'), '4': ('lat4', 'lon4')} tables_columns = OrderedDict([('testtable', ('col1', 'col2'))]) stored_settings = [(0, (('input_field_group_list', ['par1;type1;hint1']), ('sublocation_suffix', 'group1'), ('location_suffix', 'proj'))), (1, (('input_field_group_list', ['par2;type2;hint2']), ('sublocation_suffix', 'group2'), ('location_suffix', 'proj')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) parameter_groups[0]._obsid_list.paste_data(['1', '4']) parameter_groups[1]._obsid_list.paste_data(['2', '3', '4']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) reference_string = '[NAME;INPUTTYPE;HINT, par1;type1;hint1 , par2;type2;hint2 , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.proj;1.proj.group1;lat1;lon1;par1, 2.proj;2.proj.group2;lat2;lon2;par2, 4.proj;4.proj.group1;lat4;lon4;par1, 4.proj;4.proj.group2;lat4;lon4;par2]' assert reference_string == test_string
def test_create_export_printlist_assert_no_latlon(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1'), u'2': (u'lat2', u'lon2'), u'4': (u'lat4', u'lon4')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par2'), (u'sublocation_suffix', u'proj2.group'), (u'location_suffix', u'proj2'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1', u'4']) export_objects[1].obsid_list.addItems([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist(export_objects) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_called_with(bar_msg=u'Critical: Obsid did not have lat-lon coordinates. Check obs_points table')
def test_create_export_printlist_assert_no_critical_msg(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {'1': (123, 465), '2': (123, 465), '3': (123, 465)} stored_settings = [(0, (('input_field_group_list', ['p1.u1;it1:h1', 'l.comment;test;make a comment']), ('location_suffix', 'ls'), ('sublocation_suffix', 'with_p1_u1_and_l_comment'))), (1, (('input_field_group_list', ['comment;test;make a general comment']), ('location_suffix', 'ls'), ('sublocation_suffix', 'with_comment')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings) parameter_groups[0]._obsid_list.paste_data(['1', '2', '3']) parameter_groups[1]._obsid_list.paste_data(['1', '2', '3']) printlist = ExportToFieldLogger.create_export_printlist(parameter_groups) test_string = create_test_string(printlist) mock_MessagebarAndLog.critical.assert_not_called() reference_string = '[NAME;INPUTTYPE;HINT, p1.u1;it1:h1 , l.comment;test;make a comment , comment;test;make a general comment , NAME;SUBNAME;LAT;LON;INPUTFIELD, 1.ls;1.ls.with_comment;123;465;comment, 1.ls;1.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 2.ls;2.ls.with_comment;123;465;comment, 2.ls;2.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment, 3.ls;3.ls.with_comment;123;465;comment, 3.ls;3.ls.with_p1_u1_and_l_comment;123;465;p1.u1|l.comment]' assert test_string == reference_string
def test_create_export_printlist(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1'), u'2': (u'lat2', u'lon2'), u'4': (u'lat4', u'lon4')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par2'), (u'sublocation_suffix', u'proj2.group'), (u'location_suffix', u'proj2'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1', u'4']) export_objects[1].obsid_list.addItems([u'2', u'3', u'4']) printlist = ExportToFieldLogger.create_export_printlist(export_objects) test_string = create_test_string(printlist) reference_string = u'[FileVersion 1;2, NAME;INPUTTYPE;HINT, par1;type1;hint1, par2;type2;hint2, NAME;sublocation;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par1, 2.proj2;2.proj2.group;lat2;lon2;par2, 4.proj;4.proj.group;lat4;lon4;par1, 4.proj2;4.proj2.group;lat4;lon4;par2]' assert reference_string == test_string
def test_create_parameter_browser_using_stored_settings(): tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [ (0, ((u'input_field_list', [u'p1.u1;it1:h1', u'p2.u2;it2:h2']), (u'key0_2', u'value0_2'))), (1, ((u'location_suffix', u'value1_1'), (u'key1_2', u'value1_2'))) ] mock_connect = MagicMock() parameter_browser = export_fieldlogger.ParameterBrowser( tables_columns, mock_connect) ExportToFieldLogger.update_parameter_browser_using_stored_settings( stored_settings, parameter_browser) test_string = create_test_string( ExportToFieldLogger.update_stored_settings([parameter_browser])) reference = u'[[0, ((input_field_list, [p1.u1;it1:h1, p2.u2;it2:h2]))]]' assert test_string == reference
def test_update_stored_settings(): parameter_groups = [MagicMock(), MagicMock()] parameter_groups[0].get_settings.return_value = (('key0_1', 'value0_1'), ('key0_2', 'value0_2')) parameter_groups[1].get_settings.return_value = (('key1_1', 'value1_1'), ('key1_2', 'value1_2')) stored_settings = ExportToFieldLogger.update_stored_settings(parameter_groups) test_string = create_test_string(stored_settings) reference_string = '[[0, ((key0_1, value0_1), (key0_2, value0_2))], [1, ((key1_1, value1_1), (key1_2, value1_2))]]' assert test_string == reference_string
def test_update_stored_settings(): export_objects = [MagicMock(), MagicMock()] export_objects[0].get_settings.return_value = ((u'key0_1', u'value0_1'), (u'key0_2', u'value0_2')) export_objects[1].get_settings.return_value = ((u'key1_1', u'value1_1'), (u'key1_2', u'value1_2')) stored_settings = ExportToFieldLogger.update_stored_settings(export_objects) test_string = create_test_string(stored_settings) reference_string = u'[(0, ((key0_1, value0_1), (key0_2, value0_2))), (1, ((key1_1, value1_1), (key1_2, value1_2)))]' assert test_string == reference_string
def test_create_export_printlist_duplicate_parameters(mock_latlons, mock_MessagebarAndLog): mock_latlons.return_value = {u'1': (u'lat1', u'lon1')} tables_columns = OrderedDict([(u'testtable', (u'col1', u'col2'))]) stored_settings = [(0, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type1'), (u'hint', u'hint1'))), (1, ((u'final_parameter_name', u'par1'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type2'), (u'hint', u'hint2'))), (2, ((u'final_parameter_name', u'comment'), (u'sublocation_suffix', u'proj.group'), (u'location_suffix', u'proj'), (u'input_type', u'type2'), (u'hint', u'hint2')))] mock_connect = MagicMock() export_objects = ExportToFieldLogger.create_export_objects_using_stored_settings(stored_settings, tables_columns, mock_connect) export_objects[0].obsid_list.addItems([u'1']) export_objects[1].obsid_list.addItems([u'1']) test_string = create_test_string(ExportToFieldLogger.create_export_printlist(export_objects)) parameter = u'par1' mock_MessagebarAndLog.warning.assert_called_with(bar_msg=u"Warning: Parameter " + parameter + u' error. See log message panel', log_msg=u'The parameter ' + parameter + u' already exists. Only the first occurence one will be written to file.') reference_string = u'[FileVersion 1;2, NAME;INPUTTYPE;HINT, par1;type1;hint1, comment;type2;hint2, NAME;sublocation;LAT;LON;INPUTFIELD, 1.proj;1.proj.group;lat1;lon1;par1]' assert test_string == reference_string
def test_laton_from_vectorlayer(mock_tables_columns, mock_write_printlist_to_file, mock_MessagebarAndLog): mock_ms = mock.MagicMock() mock_ms.settingsdict = {} mock_tables_columns.return_value = {} _fields = [QgsField('id', QVariant.Int, QVariant.typeToName(QVariant.Int)), QgsField('obsid', QVariant.String, QVariant.typeToName(QVariant.String))] data = [[1, 'obsid1'], [2, 'obsid2'], [3, 'obsid3']] geometries = [QgsGeometry.fromWkt('POINT(1000000.0 100000.0)'), QgsGeometry.fromWkt('POINT(2000000.0 200000.0)'), QgsGeometry.fromWkt('POINT(3000000.0 300000.0)')] vlayer = create_vectorlayer(_fields, data, geometries=geometries, geomtype='Point', crs=3006) mock_iface = QWidget() mock_iface.legendInterface = mock.Mock() mock_iface.legendInterface.return_value.layers.return_value = [vlayer] exporttofieldlogger = ExportToFieldLogger(mock_iface, mock_ms) stored_settings = [(0, (('input_field_group_list', ['par1;type1;hint1']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj'))), (1, (('input_field_group_list', ['par2;type2;hint2']), ('sublocation_suffix', 'group'), ('location_suffix', 'proj2')))] parameter_groups = ExportToFieldLogger.create_parameter_groups_using_stored_settings(stored_settings, None) parameter_groups[0]._obsid_list.paste_data(['obsid1', 'obsid2']) parameter_groups[1]._obsid_list.paste_data(['obsid3']) exporttofieldlogger.parameter_groups = parameter_groups exporttofieldlogger.obs_from_vlayer.setChecked(True) exporttofieldlogger.export() print("printlist" + str(mock_write_printlist_to_file.mock_calls)) assert mock_write_printlist_to_file.mock_calls == [mock.call(['NAME;INPUTTYPE;HINT', 'par1;type1;hint1 ', 'par2;type2;hint2 ', 'NAME;SUBNAME;LAT;LON;INPUTFIELD', 'obsid1.proj;obsid1.proj.group;0.9019366063889334;19.489297537299507;par1', 'obsid2.proj;obsid2.proj.group;1.7601631374427096;28.363010767336505;par1', 'obsid3.proj2;obsid3.proj2.group;2.5166567545976224;36.93072164080035;par2'])]
def test_update_stored_settings_using_real_parameter_groups(): parameter_groups = [export_fieldlogger.ParameterGroup(), export_fieldlogger.ParameterGroup()] setattr(parameter_groups[0], 'input_field_group_list', ['p1.u1;it1:h1', 'p2.u2;it2:h2']) setattr(parameter_groups[1], 'location_suffix', 'loc1') setattr(parameter_groups[1], 'sublocation_suffix', 'subloc1') stored_settings = ExportToFieldLogger.update_stored_settings(parameter_groups) test_string = create_test_string(stored_settings) reference_string = '[[0, ((input_field_group_list, [p1.u1;it1:h1, p2.u2;it2:h2]))], [1, ((location_suffix, loc1), (sublocation_suffix, subloc1))]]' assert test_string == reference_string
def test_update_stored_settings_using_real_export_objects(): mock_connect = MagicMock() export_objects = [export_fieldlogger.ExportObject(mock_connect), export_fieldlogger.ExportObject(mock_connect)] setattr(export_objects[0], 'final_parameter_name', 'testname1') setattr(export_objects[1], 'final_parameter_name', 'testname2') setattr(export_objects[1], 'location_suffix', 'locationsuffix2') stored_settings = ExportToFieldLogger.update_stored_settings(export_objects) test_string = create_test_string(stored_settings) reference_string = u'[(0, ((final_parameter_name, testname1))), (1, ((final_parameter_name, testname2), (location_suffix, locationsuffix2)))]' assert test_string == reference_string
class TestExportFieldlogger(): qual_params = MockUsingReturnValue(((u'redoxpotential', (u'mV',)), (u'syre', (u'mg/L', u'%')), (u'pH', (u'',)))) flow_params = MockUsingReturnValue(((u'Momflow', (u'l/s',)), (u'Accvol', (u'm3',)))) sample_params = MockUsingReturnValue(((u'turbiditet', (u'FNU',)),)) the_obsids = MockUsingReturnValue((u'Rb1301', u'Rb1302')) the_latlons = MockUsingReturnValue({u'Rb1301': (60.0, 10.0), u'Rb1302': (50.0, 4.0)}) selected_obsids_from_map = MockUsingReturnValue((u'Rb1302',)) empty_dict = MockUsingReturnValue({}) importinstance = MockUsingReturnValue(MockUsingReturnValue(int)) importinstance.get_v().parse_wells_file = lambda : {u'Rb1301': {u'level': [(u'comment', u''), (u'meas', u'm')], u'quality': [(u'comment', u''), (u'syre', u'mg/L'), (u'konduktivitet', u'µS/cm'), (u'redoxpotential', u'mV'), (u'pH', u'')], u'sample': [(u'temperatur', u'grC'), (u'comment', u''), (u'turbiditet', u'FNU')]}, u'Rb1302': {u'quality': [(u'comment', u''), (u'syre', u'mg/L'), (u'konduktivitet', u'µS/cm'), (u'redoxpotential', u'mV'), (u'pH', u'')], u'sample': [(u'temperatur', u'grC'), (u'comment', u''), (u'turbiditet', u'FNU')]}} skip_popup = MockUsingReturnValue('') @mock.patch('export_fieldlogger.standard_parameters_for_wquality', qual_params.get_v) @mock.patch('export_fieldlogger.standard_parameters_for_wflow', flow_params.get_v) @mock.patch('export_fieldlogger.standard_parameters_for_wsample', sample_params.get_v) @mock.patch('export_fieldlogger.utils.get_all_obsids', the_obsids.get_v) def setUp(self): self.iface = DummyInterface() widget = QtGui.QWidget() self.export_fieldlogger_obj = ExportToFieldLogger(widget) @mock.patch('export_fieldlogger.standard_parameters_for_wquality', qual_params.get_v) @mock.patch('export_fieldlogger.standard_parameters_for_wflow', flow_params.get_v) @mock.patch('export_fieldlogger.standard_parameters_for_wsample', sample_params.get_v) def test_create_parameters(self): parameters = [(types, parametername, parameter.hint) for types, parameterdict in sorted(self.export_fieldlogger_obj.create_parameters().iteritems()) for parametername, parameter in sorted(parameterdict.iteritems())] assert parameters == [(u'flow', u'Accvol', u'm3'), (u'flow', u'Momflow', u'l/s'), (u'flow', u'comment', u'make comment...'), (u'level', u'comment', u'make comment...'), (u'level', u'meas', u'm'), (u'quality', u'comment', u'make comment...'), (u'quality', u'pH', u'pH'), (u'quality', u'redoxpotential', u'mV'), (u'quality', u'syre.%', u'%'), (u'quality', u'syre.mg/L', u'mg/L'), (u'sample', u'comment', u'make comment...'), (u'sample', u'turbiditet', u'FNU')] @mock.patch('export_fieldlogger.utils.get_latlon_for_all_obsids', the_latlons.get_v) def test_select_all_momflow(self): self.export_fieldlogger_obj.select_all(u'flow.Momflow', True) printlist = self.export_fieldlogger_obj.create_export_printlist() assert printlist == [u'FileVersion 1;2', u'NAME;INPUTTYPE;HINT', u'f.Momflow.l/s;numberDecimal|numberSigned;l/s', u'f.comment;text;make comment...', u'NAME;SUBNAME;LAT;LON;INPUTFIELD', u'Rb1301;Rb1301.flow;60.0;10.0;f.Momflow.l/s|f.comment', u'Rb1302;Rb1302.flow;50.0;4.0;f.Momflow.l/s|f.comment'] @mock.patch('export_fieldlogger.utils.get_selected_features_as_tuple', selected_obsids_from_map.get_v) @mock.patch('export_fieldlogger.utils.get_latlon_for_all_obsids', the_latlons.get_v) def test_select_from_map_click(self): self.export_fieldlogger_obj.select_from_map(u'quality.syre.%') printlist = self.export_fieldlogger_obj.create_export_printlist() assert printlist == [u'FileVersion 1;2', u'NAME;INPUTTYPE;HINT', u'q.syre.%;numberDecimal|numberSigned;%', u'q.comment;text;make comment...', u'NAME;SUBNAME;LAT;LON;INPUTFIELD', u'Rb1302;Rb1302.quality;50.0;4.0;q.comment|q.syre.%'] @mock.patch('export_fieldlogger.utils.get_selected_features_as_tuple', selected_obsids_from_map.get_v) @mock.patch('export_fieldlogger.utils.get_latlon_for_all_obsids', the_latlons.get_v) def test_select_three_from_map_click(self): self.export_fieldlogger_obj.select_from_map(u'quality.syre.%') self.export_fieldlogger_obj.select_from_map(u'quality.syre.mg/L') self.export_fieldlogger_obj.select_from_map(u'sample.turbiditet') printlist = self.export_fieldlogger_obj.create_export_printlist() assert printlist == [u'FileVersion 1;5', u'NAME;INPUTTYPE;HINT', u'q.syre.mg/L;numberDecimal|numberSigned;mg/L', u'q.syre.%;numberDecimal|numberSigned;%', u'q.comment;text;make comment...', u's.turbiditet.FNU;numberDecimal|numberSigned;FNU', u's.comment;text;make comment...', u'NAME;SUBNAME;LAT;LON;INPUTFIELD', u'Rb1302;Rb1302.quality;50.0;4.0;q.comment|q.syre.mg/L|q.syre.%', u'Rb1302;Rb1302.sample;50.0;4.0;s.comment|s.turbiditet.FNU'] @mock.patch('export_fieldlogger.utils.get_latlon_for_all_obsids', autospec=True) @mock.patch('export_fieldlogger.midv_data_importer', autospec=True) @mock.patch('import_data_to_db.utils.pop_up_info', autospec=True) def test_select_from_wells(self, mock_skip_popup, mock_midv_data_importer, mock_latlons): mock_midv_data_importer.return_value.parse_wells_file.return_value = {u'Rb1301': {u'level': [(u'comment', u''), (u'meas', u'm')], u'quality': [(u'comment', u''), (u'syre', u'mg/L'), (u'konduktivitet', u'µS/cm'), (u'redoxpotential', u'mV'), (u'pH', u'')], u'sample': [(u'temperatur', u'grC'), (u'comment', u''), (u'turbiditet', u'FNU')]}, u'Rb1302': {u'quality': [(u'comment', u''), (u'syre', u'mg/L'), (u'konduktivitet', u'µS/cm'), (u'redoxpotential', u'mV'), (u'pH', u'')], u'sample': [(u'temperatur', u'grC'), (u'comment', u''), (u'turbiditet', u'FNU')]}} mock_latlons.return_value = {u'Rb1301': (60.0, 10.0), u'Rb1302': (50.0, 4.0)} self.export_fieldlogger_obj.select_from_wells() printlist = self.export_fieldlogger_obj.create_export_printlist() assert printlist == [u'FileVersion 1;8', u'NAME;INPUTTYPE;HINT', u'l.meas.m;numberDecimal|numberSigned;m', u'l.comment;text;make comment...', u'q.redoxpotential.mV;numberDecimal|numberSigned;mV', u'q.syre.mg/L;numberDecimal|numberSigned;mg/L', u'q.pH;numberDecimal|numberSigned;pH', u'q.comment;text;make comment...', u's.turbiditet.FNU;numberDecimal|numberSigned;FNU', u's.comment;text;make comment...', u'NAME;SUBNAME;LAT;LON;INPUTFIELD', u'Rb1301;Rb1301.level;60.0;10.0;l.comment|l.meas.m', u'Rb1301;Rb1301.quality;60.0;10.0;q.pH|q.syre.mg/L|q.redoxpotential.mV|q.comment', u'Rb1301;Rb1301.sample;60.0;10.0;s.comment|s.turbiditet.FNU', u'Rb1302;Rb1302.quality;50.0;4.0;q.pH|q.syre.mg/L|q.redoxpotential.mV|q.comment', u'Rb1302;Rb1302.sample;50.0;4.0;s.comment|s.turbiditet.FNU'] @mock.patch('export_fieldlogger.utils.get_latlon_for_all_obsids', autospec=True) @mock.patch('export_fieldlogger.midv_data_importer', autospec=True) @mock.patch('import_data_to_db.utils.pop_up_info', autospec=True) def test_select_from_wells_cancel(self, mock_skip_popup, mock_midv_data_importer, mock_latlons): mock_midv_data_importer.return_value.parse_wells_file.return_value = {} mock_latlons.return_value = {u'Rb1301': (60.0, 10.0), u'Rb1302': (50.0, 4.0)} self.export_fieldlogger_obj.select_from_wells() printlist = self.export_fieldlogger_obj.create_export_printlist() assert printlist == [u'FileVersion 1;0', u'NAME;INPUTTYPE;HINT', u'NAME;SUBNAME;LAT;LON;INPUTFIELD'] def tearDown(self): self.iface = None self.export_fieldlogger_obj = None pass
def setUp(self): self.iface = DummyInterface() widget = QtGui.QWidget() self.export_fieldlogger_obj = ExportToFieldLogger(widget)