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_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_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_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_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_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_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(): 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_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_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_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_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_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_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_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_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_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_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