本文整理汇总了Python中utils_for_tests.create_test_string函数的典型用法代码示例。如果您正苦于以下问题:Python create_test_string函数的具体用法?Python create_test_string怎么用?Python create_test_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_test_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_db_locale_se
def test_create_db_locale_se(self, mock_locale):
mock_locale.return_value = [u'se_SV']
self.midvatten.new_db(u'sv_SE')
test_string = utils_for_tests.create_test_string(utils.sql_load_fr_db(u'select * from zz_strat'))
reference_string = ur"""(True, [(okänt, white, , white, NoBrush, not in ('berg','b','rock','ro','grovgrus','grg','coarse gravel','cgr','grus','gr','gravel','mellangrus','grm','medium gravel','mgr','fingrus','grf','fine gravel','fgr','grovsand','sag','coarse sand','csa','sand','sa','mellansand','sam','medium sand','msa','finsand','saf','fine sand','fsa','silt','si','lera','ler','le','clay','cl','morän','moran','mn','till','ti','torv','t','peat','pt','fyll','fyllning','f','made ground','mg','land fill')), (berg, red, x, red, DiagCrossPattern, in ('berg','b','rock','ro')), (grovgrus, DarkGreen, O, darkGreen, Dense7Pattern, in ('grovgrus','grg','coarse gravel','cgr')), (grus, DarkGreen, O, darkGreen, Dense7Pattern, in ('grus','gr','gravel')), (mellangrus, DarkGreen, o, darkGreen, Dense6Pattern, in ('mellangrus','grm','medium gravel','mgr')), (fingrus, DarkGreen, o, darkGreen, Dense6Pattern, in ('fingrus','grf','fine gravel','fgr')), (grovsand, green, *, green, Dense5Pattern, in ('grovsand','sag','coarse sand','csa')), (sand, green, *, green, Dense5Pattern, in ('sand','sa')), (mellansand, green, ., green, Dense4Pattern, in ('mellansand','sam','medium sand','msa')), (finsand, DarkOrange, ., orange, Dense5Pattern, in ('finsand','saf','fine sand','fsa')), (silt, yellow, \\, yellow, BDiagPattern, in ('silt','si')), (lera, yellow, -, yellow, HorPattern, in ('lera','ler','le','clay','cl')), (morän, cyan, /, yellow, CrossPattern, in ('morän','moran','mn','till','ti')), (torv, DarkGray, +, darkGray, NoBrush, in ('torv','t','peat','pt')), (fyll, white, +, white, DiagCrossPattern, in ('fyll','fyllning','f','made ground','mg','land fill'))])"""
assert test_string == reference_string
开发者ID:mirouml,项目名称:qgis-midvatten-plugin,代码行数:7,代码来源:test_create_db.py
示例2: test_parse_hobologger_file_convert_tz
def test_parse_hobologger_file_convert_tz(self, mock_messagelog):
f = ('"Plot Title: temp"',
'"#","Date Time, GMT+03:00","Temp, °C (LGR S/N: 1234, SEN S/N: 1234, LBL: Rb1)","Coupler Detached (LGR S/N: 1234)","Coupler Attached (LGR S/N: 1234)","Stopped (LGR S/N: 1234)","End Of File (LGR S/N: 1234)"',
'1,07/19/18 10:00:00 fm,4.558,Logged,,,',
'2,07/19/18 11:00:00 fm,4.402,,,,',
'3,07/19/18 12:00:00 em,4.402,,,,',
'4,07/19/18 01:00:00 em,4.402,,,,')
charset_of_hobologgerfile = 'utf-8'
#tz_string = get_tz_string('Date Time, GMT+02:00')
tzconverter = TzConverter()
tzconverter.target_tz = 'GMT+01:00'
#tzconverter.source_tz = tz_string
with utils.tempinput('\n'.join(f), charset_of_hobologgerfile) as path:
file_data = HobologgerImport.parse_hobologger_file(path, charset_of_hobologgerfile, tz_converter=tzconverter)
test_string = utils_for_tests.create_test_string(file_data[0])
reference_string = '[[date_time, head_cm, temp_degc, cond_mscm], [2018-07-19 08:00:00, , 4.558, ], [2018-07-19 09:00:00, , 4.402, ], [2018-07-19 10:00:00, , 4.402, ], [2018-07-19 11:00:00, , 4.402, ]]'
#print(str(test_string))
#print(str(reference_string))
#print(str(mock_messagelog.mock_calls))
assert test_string == reference_string
assert os.path.basename(path) == file_data[1]
assert file_data[2] == 'Rb1'
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:25,代码来源:test_import_hobologger.py
示例3: test_calibrlogger_adjust_trend
def test_calibrlogger_adjust_trend(self, mock_messagebar):
db_utils.sql_alter_db("INSERT INTO obs_points (obsid) VALUES ('rb1')")
db_utils.sql_alter_db("INSERT INTO w_levels_logger (obsid, date_time, level_masl) VALUES ('rb1', '2017-02-01 00:00', 100)")
db_utils.sql_alter_db("INSERT INTO w_levels_logger (obsid, date_time, level_masl) VALUES ('rb1', '2017-02-10 00:00', 200)")
db_utils.sql_alter_db("INSERT INTO w_levels (obsid, date_time, level_masl) VALUES ('rb1', '2017-02-01 00:00', 200)")
db_utils.sql_alter_db("INSERT INTO w_levels (obsid, date_time, level_masl) VALUES ('rb1', '2017-02-10 00:00', 100)")
calibrlogger = Calibrlogger(self.iface.mainWindow(), self.ms)
gui_utils.set_combobox(calibrlogger.combobox_obsid, 'rb1 (uncalibrated)')
calibrlogger.update_plot()
calibrlogger.FromDateTime.setDateTime(date_utils.datestring_to_date('2000-01-01 00:00:00'))
calibrlogger.L1_date.setDateTime(date_utils.datestring_to_date('2017-02-01 00:00'))
calibrlogger.L2_date.setDateTime(date_utils.datestring_to_date('2017-02-10 00:00'))
calibrlogger.M1_date.setDateTime(date_utils.datestring_to_date('2017-02-01 00:00'))
calibrlogger.M2_date.setDateTime(date_utils.datestring_to_date('2017-02-10 00:00'))
calibrlogger.adjust_trend_func()
res = db_utils.sql_load_fr_db('SELECT * FROM w_levels_logger')
l = list(res[1][1])
l[5] = '%.11e'%Decimal(l[5])
res[1][1] = tuple(l)
test = utils_for_tests.create_test_string(res)
print(mock_messagebar.mock_calls)
print(test)
ref = '(True, [(rb1, 2017-02-01 00:00, None, None, None, 100.0, None), (rb1, 2017-02-10 00:00, None, None, None, -2.84217094304e-14, None)])'
assert test == ref
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:29,代码来源:test_wlevels_calc_calibr_postgis.py
示例4: test_add_triggers_not_change_existing
def test_add_triggers_not_change_existing(self):
""" Adding triggers should not automatically change the db """
utils.sql_alter_db(u'''INSERT INTO obs_points ("obsid", "east", "north") VALUES ('rb1', 1, 1)''')
test_string = utils_for_tests.create_test_string(utils.sql_load_fr_db(u'select obsid, east, north, AsText(geometry) from obs_points'))
utils.add_triggers_to_obs_points()
reference_string = u'(True, [(rb1, 1.0, 1.0, None)])'
assert test_string == reference_string
开发者ID:mirouml,项目名称:qgis-midvatten-plugin,代码行数:7,代码来源:test_create_db.py
示例5: test_plot_section
def test_plot_section(self, mock_messagebar):
"""For now, the test only initiates the plot. Check that it does not crash """
db_utils.sql_alter_db('''INSERT INTO obs_lines (obsid, geometry) VALUES ('L1', ST_GeomFromText('LineString(633466.711659 6720684.24498, 633599.530455 6720727.016568)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P1', ST_GeomFromText('POINT(633466 711659)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P2', ST_GeomFromText('POINT(6720727 016568)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P3', ST_GeomFromText('POINT(6720728 016569)', 3006))''')
self.create_and_select_vlayer()
@mock.patch('db_utils.QgsProject.instance', utils_for_tests.MidvattenTestPostgisNotCreated.mock_instance_settings_database)
@mock.patch('db_utils.get_postgis_connections', utils_for_tests.MidvattenTestPostgisNotCreated.mock_postgis_connections)
@mock.patch('midvatten_utils.getselectedobjectnames', autospec=True)
@mock.patch('qgis.utils.iface', autospec=True)
def _test_plot_section(self, mock_iface, mock_getselectedobjectnames):
mock_iface.mapCanvas.return_value.currentLayer.return_value = self.vlayer
mock_getselectedobjectnames.return_value = ('P1', 'P2', 'P3')
mock_mapcanvas = mock_iface.mapCanvas.return_value
mock_mapcanvas.layerCount.return_value = 0
self.midvatten.plot_section()
self.myplot = self.midvatten.myplot
self.myplot.drillstoplineEdit.setText("%berg%")
self.myplot.draw_plot()
self.selected_obsids = self.myplot.selected_obsids
_test_plot_section(self)
assert """call.info(log_msg='Settings {""" in str(mock_messagebar.mock_calls)
assert self.myplot.drillstoplineEdit.text() == '%berg%'
assert utils_for_tests.create_test_string(self.myplot.selected_obsids) == "['P1' 'P2' 'P3']"
assert not mock_messagebar.warning.called
assert not mock_messagebar.critical.called
assert len(self.myplot.p) == len(self.myplot.Labels)
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:31,代码来源:test_sectionplot_postgis.py
示例6: test_load_file
def test_load_file(self):
f = [
"LOCATION;DATE;TIME;VALUE;TYPE\n",
"Rb1202.sample;30-03-2016;15:31:30;hej2;s.comment\n",
"Rb1608.level;30-03-2016;15:34:40;testc;l.comment\n",
"Rb1615.flow;30-03-2016;15:30:09;357;f.Accvol.m3\n",
"Rb1615.flow;30-03-2016;15:30:09;gick bra;f.comment\n",
"Rb1608.level;30-03-2016;15:34:13;ergv;l.comment\n",
"Rb1608.level;30-03-2016;15:34:13;555;l.meas.m\n",
"Rb1512.sample;30-03-2016;15:31:30;899;s.turbiditet.FNU\n",
"Rb1505.quality;30-03-2016;15:29:26;hej;q.comment\n",
"Rb1505.quality;30-03-2016;15:29:26;863;q.konduktivitet.µS/cm\n",
"Rb1512.quality;30-03-2016;15:30:39;test;q.comment\n",
"Rb1512.quality;30-03-2016;15:30:39;67;q.syre.mg/L\n",
"Rb1512.quality;30-03-2016;15:30:39;8;q.temperatur.grC\n",
"Rb1512.quality;30-03-2016;15:30:40;58;q.syre.%\n",
]
with utils.tempinput(''.join(f)) as filename:
@mock.patch('import_fieldlogger.utils.QtWidgets.QFileDialog.getOpenFileNames')
@mock.patch('import_fieldlogger.utils.QtWidgets.QInputDialog.getText')
@mock.patch('import_fieldlogger.utils.MessagebarAndLog')
def _test(self, filename, mock_MessagebarAndLog, mock_charset, mock_savefilename ):
mock_charset.return_value = ('utf-8', True)
mock_savefilename.return_value = [[filename]]
test_string = create_test_string(sorted(FieldloggerImport.select_file_and_parse_rows(FieldloggerImport.parse_rows), key=itemgetter('date_time', 'parametername', 'sublocation')))
return test_string
test_string = _test(self, filename)
reference = utils_for_tests.create_test_string(sorted([{'date_time': '2016-03-30 15:29:26', 'parametername': 'q.comment', 'sublocation': 'Rb1505.quality', 'value': 'hej'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.syre.mg/L', 'sublocation': 'Rb1512.quality', 'value': '67'}, {'date_time': '2016-03-30 15:31:30', 'parametername': 's.turbiditet.FNU', 'sublocation': 'Rb1512.sample', 'value': '899'}, {'date_time': '2016-03-30 15:29:26', 'parametername': 'q.konduktivitet.µS/cm', 'sublocation': 'Rb1505.quality', 'value': '863'}, {'date_time': '2016-03-30 15:30:09', 'parametername': 'f.comment', 'sublocation': 'Rb1615.flow', 'value': 'gick bra'}, {'date_time': '2016-03-30 15:30:40', 'parametername': 'q.syre.%', 'sublocation': 'Rb1512.quality', 'value': '58'}, {'date_time': '2016-03-30 15:34:13', 'parametername': 'l.meas.m', 'sublocation': 'Rb1608.level', 'value': '555'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.comment', 'sublocation': 'Rb1512.quality', 'value': 'test'}, {'date_time': '2016-03-30 15:31:30', 'parametername': 's.comment', 'sublocation': 'Rb1202.sample', 'value': 'hej2'}, {'date_time': '2016-03-30 15:34:40', 'parametername': 'l.comment', 'sublocation': 'Rb1608.level', 'value': 'testc'}, {'date_time': '2016-03-30 15:30:09', 'parametername': 'f.Accvol.m3', 'sublocation': 'Rb1615.flow', 'value': '357'}, {'date_time': '2016-03-30 15:34:13', 'parametername': 'l.comment', 'sublocation': 'Rb1608.level', 'value': 'ergv'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.temperatur.grC', 'sublocation': 'Rb1512.quality', 'value': '8'}], key=itemgetter('date_time', 'parametername', 'sublocation')))
assert test_string == reference
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:33,代码来源:test_import_fieldlogger.py
示例7: test_plot_section_length_along_slope
def test_plot_section_length_along_slope(self, mock_messagebar):
db_utils.sql_alter_db('''INSERT INTO obs_lines (obsid, geometry) VALUES ('L1', ST_GeomFromText('LineString(2 0, 10 10)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P1', ST_GeomFromText('POINT(1 0)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P2', ST_GeomFromText('POINT(3 0)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P3', ST_GeomFromText('POINT(5 0)', 3006))''')
self.create_and_select_vlayer()
@mock.patch('midvatten_utils.getselectedobjectnames', autospec=True)
@mock.patch('qgis.utils.iface', autospec=True)
def _test(midvatten, vlayer, mock_iface, mock_getselectedobjectnames):
mock_iface.mapCanvas.return_value.currentLayer.return_value = vlayer
mock_getselectedobjectnames.return_value = ('P1', 'P2', 'P3')
mock_mapcanvas = mock_iface.mapCanvas.return_value
mock_mapcanvas.layerCount.return_value = 0
midvatten.plot_section()
self.myplot = midvatten.myplot
self.myplot.drillstoplineEdit.setText("%berg%")
self.myplot.draw_plot()
_test(self.midvatten, self.vlayer)
test_string = utils_for_tests.create_test_string(self.myplot.LengthAlong)
assert any([test_string == "[ 0. 0.62469505 1.87408514]",
test_string == "[0. 0.62469505 1.87408514]"])
assert not mock_messagebar.warning.called
assert not mock_messagebar.critical.called
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:28,代码来源:test_sectionplot_postgis.py
示例8: test_export_spatialite_zz_tables
def test_export_spatialite_zz_tables(self, mock_skip_popup, mock_iface, mock_find_layer, mock_newdbpath, mock_verify, mock_locale, mock_createdb_crs_question, mock_messagebar):
mock_find_layer.return_value.crs.return_value.authid.return_value = 'EPSG:3006'
mock_createdb_crs_question.return_value = [3006, True]
dbconnection = db_utils.DbConnectionManager()
mock_newdbpath.return_value = (EXPORT_DB_PATH, '')
mock_verify.return_value = 0
"""
insert into zz_strat(geoshort,strata) values('land fill','fyll');
insert into zz_stratigraphy_plots (strata,color_mplot,hatch_mplot,color_qt,brush_qt) values('torv','DarkGray','+','darkGray','NoBrush');
insert into zz_capacity (capacity,explanation) values('6 ','mycket god');
insert into zz_capacity (capacity,explanation) values('6+','mycket god');
insert into zz_capacity_plots (capacity,color_qt) values('', 'gray');
"""
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P1', ST_GeomFromText('POINT(633466 711659)', 3006))''', dbconnection=dbconnection)
dbconnection.execute('''PRAGMA foreign_keys='off' ''')
dbconnection.execute('''UPDATE zz_strat SET strata = 'filling' WHERE geoshort = 'land fill' ''')
dbconnection.execute('''INSERT INTO zz_stratigraphy_plots (strata,color_mplot,hatch_mplot,color_qt,brush_qt) values ('filling','Yellow','+','darkGray','NoBrush') ''')
dbconnection.execute('''UPDATE zz_stratigraphy_plots SET color_mplot = 'OrangeFIX' WHERE strata = 'made ground' ''')
dbconnection.execute('''UPDATE zz_capacity SET explanation = 'anexpl' WHERE capacity = 0 ''')
dbconnection.execute('''UPDATE zz_capacity_plots SET color_qt = 'whiteFIX' WHERE capacity = 0 ''')
#print(str(dbconnection.execute_and_fetchall('select * from zz_strat')))
dbconnection.commit_and_closedb()
print("Before export")
mock_locale.return_value.answer = 'ok'
mock_locale.return_value.value = 'en_US'
self.midvatten.export_spatialite()
sql_list = ['''SELECT geoshort, strata FROM zz_strat WHERE geoshort IN ('land fill', 'rock') ''',
'''SELECT strata, color_mplot FROM zz_stratigraphy_plots WHERE strata IN ('made ground', 'rock', 'filling') ''',
'''SELECT capacity, explanation FROM zz_capacity WHERE capacity IN (0, 1)''',
'''SELECT capacity, color_qt FROM zz_capacity_plots WHERE capacity IN (0, 1) ''']
conn = db_utils.connect_with_spatialite_connect(EXPORT_DB_PATH)
curs = conn.cursor()
test_list = []
for sql in sql_list:
test_list.append('\n' + sql + '\n')
test_list.append(curs.execute(sql).fetchall())
conn.commit()
conn.close()
test_string = utils_for_tests.create_test_string(test_list)
reference_string = ['''[''',
'''SELECT geoshort, strata FROM zz_strat WHERE geoshort IN ('land fill', 'rock') ''',
''', [(land fill, filling), (rock, rock)], ''',
'''SELECT strata, color_mplot FROM zz_stratigraphy_plots WHERE strata IN ('made ground', 'rock', 'filling') ''',
''', [(filling, Yellow), (made ground, OrangeFIX), (rock, red)], ''',
'''SELECT capacity, explanation FROM zz_capacity WHERE capacity IN (0, 1)''',
''', [(0, anexpl), (1, above gwl)], ''',
'''SELECT capacity, color_qt FROM zz_capacity_plots WHERE capacity IN (0, 1) ''',
''', [(0, whiteFIX), (1, red)]]''']
reference_string = '\n'.join(reference_string)
assert test_string == reference_string
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:60,代码来源:test_export_data_spatialite.py
示例9: test_load_file_comma_separated
def test_load_file_comma_separated(self):
f = [
"LOCATION,DATE,TIME,VALUE,TYPE\n",
"Rb1202.sample,30-03-2016,15:31:30,hej2,s.comment\n",
"Rb1608.level,30-03-2016,15:34:40,testc,l.comment\n",
"Rb1615.flow,30-03-2016,15:30:09,357,f.Accvol.m3\n",
"Rb1615.flow,30-03-2016,15:30:09,gick bra,f.comment\n",
"Rb1608.level,30-03-2016,15:34:13,ergv,l.comment\n",
"Rb1608.level,30-03-2016,15:34:13,555,l.meas.m\n",
"Rb1512.sample,30-03-2016,15:31:30,899,s.turbiditet.FNU\n",
"Rb1505.quality,30-03-2016,15:29:26,hej,q.comment\n",
"Rb1505.quality,30-03-2016,15:29:26,863,q.konduktivitet.µS/cm\n",
"Rb1512.quality,30-03-2016,15:30:39,test,q.comment\n",
"Rb1512.quality,30-03-2016,15:30:39,67,q.syre.mg/L\n",
"Rb1512.quality,30-03-2016,15:30:39,8,q.temperatur.grC\n",
"Rb1512.quality,30-03-2016,15:30:40,58,q.syre.%\n",
]
with utils.tempinput(''.join(f)) as filename:
@mock.patch('import_fieldlogger.utils.QtWidgets.QFileDialog.getOpenFileNames')
@mock.patch('import_fieldlogger.utils.QtWidgets.QInputDialog.getText')
@mock.patch('import_fieldlogger.utils.MessagebarAndLog')
def _test(self, filename, mock_MessagebarAndLog, mock_charset, mock_savefilename ):
mock_charset.return_value = ('utf-8', True)
mock_savefilename.return_value = [[filename]]
test_string = create_test_string(sorted(FieldloggerImport.select_file_and_parse_rows(FieldloggerImport.parse_rows), key=itemgetter('date_time', 'parametername', 'sublocation')))
return test_string
test_string = _test(self, filename)
reference = utils_for_tests.create_test_string(sorted([{'date_time': '2016-03-30 15:29:26', 'parametername': 'q.comment', 'sublocation': 'Rb1505.quality', 'value': 'hej'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.syre.mg/L', 'sublocation': 'Rb1512.quality', 'value': '67'}, {'date_time': '2016-03-30 15:31:30', 'parametername': 's.turbiditet.FNU', 'sublocation': 'Rb1512.sample', 'value': '899'}, {'date_time': '2016-03-30 15:29:26', 'parametername': 'q.konduktivitet.µS/cm', 'sublocation': 'Rb1505.quality', 'value': '863'}, {'date_time': '2016-03-30 15:30:09', 'parametername': 'f.comment', 'sublocation': 'Rb1615.flow', 'value': 'gick bra'}, {'date_time': '2016-03-30 15:30:40', 'parametername': 'q.syre.%', 'sublocation': 'Rb1512.quality', 'value': '58'}, {'date_time': '2016-03-30 15:34:13', 'parametername': 'l.meas.m', 'sublocation': 'Rb1608.level', 'value': '555'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.comment', 'sublocation': 'Rb1512.quality', 'value': 'test'}, {'date_time': '2016-03-30 15:31:30', 'parametername': 's.comment', 'sublocation': 'Rb1202.sample', 'value': 'hej2'}, {'date_time': '2016-03-30 15:34:40', 'parametername': 'l.comment', 'sublocation': 'Rb1608.level', 'value': 'testc'}, {'date_time': '2016-03-30 15:30:09', 'parametername': 'f.Accvol.m3', 'sublocation': 'Rb1615.flow', 'value': '357'}, {'date_time': '2016-03-30 15:34:13', 'parametername': 'l.comment', 'sublocation': 'Rb1608.level', 'value': 'ergv'}, {'date_time': '2016-03-30 15:30:39', 'parametername': 'q.temperatur.grC', 'sublocation': 'Rb1512.quality', 'value': '8'}], key=itemgetter('date_time', 'parametername', 'sublocation')))
assert test_string == reference
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:34,代码来源:test_import_fieldlogger.py
示例10: test_plot_section_length_along
def test_plot_section_length_along(self, mock_messagebar):
"""For now, the test only initiates the plot. Check that it does not crash """
db_utils.sql_alter_db('''INSERT INTO obs_lines (obsid, geometry) VALUES ('L1', ST_GeomFromText('LineString(0 0, 1 0, 10 0)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P1', ST_GeomFromText('POINT(1 0)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P2', ST_GeomFromText('POINT(3 5)', 3006))''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid, geometry) VALUES ('P3', ST_GeomFromText('POINT(5 10)', 3006))''')
self.create_and_select_vlayer()
@mock.patch('midvatten_utils.getselectedobjectnames', autospec=True)
@mock.patch('qgis.utils.iface', autospec=True)
def _test(midvatten, vlayer, mock_iface, mock_getselectedobjectnames):
mock_iface.mapCanvas.return_value.currentLayer.return_value = vlayer
mock_getselectedobjectnames.return_value = ('P1', 'P2', 'P3')
mock_mapcanvas = mock_iface.mapCanvas.return_value
mock_mapcanvas.layerCount.return_value = 0
midvatten.plot_section()
myplot = midvatten.myplot
myplot.drillstoplineEdit.setText("%berg%")
myplot.draw_plot()
return myplot
myplot = _test(self.midvatten, self.vlayer)
test_string = utils_for_tests.create_test_string(myplot.LengthAlong)
assert any([test_string == "[ 1. 3. 5.]", test_string == "[1. 3. 5.]"])
assert mock.call.info(log_msg='Hidden features, obsids and length along section:\nP1;P2;P3\\1.0;3.0;5.0') in mock_messagebar.mock_calls
assert not mock_messagebar.warning.called
assert not mock_messagebar.critical.called
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:28,代码来源:test_sectionplot_postgis.py
示例11: test_wlvllogg_import_from_diveroffice_files_skip_missing_water_level
def test_wlvllogg_import_from_diveroffice_files_skip_missing_water_level(self):
files = [('Location=rb1',
'Date/time,Water head[cm],Temperature[°C]',
'2016/03/15 10:30:00,1,10',
'2016/03/15 11:00:00,,101'),
('Location=rb2',
'Date/time,Water head[cm],Temperature[°C]',
'2016/04/15 10:30:00,2,20',
'2016/04/15 11:00:00,21,201'),
('Location=rb3',
'Date/time,Water head[cm],Temperature[°C],Conductivity[mS/cm]',
'2016/05/15 10:30:00,3,30,5',
'2016/05/15 11:00:00,31,301,6')
]
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid) VALUES ('rb1')''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid) VALUES ('rb2')''')
db_utils.sql_alter_db('''INSERT INTO obs_points (obsid) VALUES ('rb3')''')
db_utils.sql_alter_db('''INSERT INTO w_levels_logger (obsid, date_time, head_cm) VALUES ('rb1', '2016-03-15 10:31', '5.0')''')
DiverofficeImport.charsetchoosen = 'utf-8'
with utils.tempinput('\n'.join(files[0]), DiverofficeImport.charsetchoosen) as f1:
with utils.tempinput('\n'.join(files[1]), DiverofficeImport.charsetchoosen) as f2:
with utils.tempinput('\n'.join(files[2]), DiverofficeImport.charsetchoosen) as f3:
filenames = [f1, f2, f3]
@mock.patch('import_data_to_db.utils.NotFoundQuestion')
@mock.patch('db_utils.QgsProject.instance', utils_for_tests.MidvattenTestPostgisNotCreated.mock_instance_settings_database)
@mock.patch('db_utils.get_postgis_connections', utils_for_tests.MidvattenTestPostgisNotCreated.mock_postgis_connections)
@mock.patch('import_data_to_db.utils.Askuser')
@mock.patch('qgis.utils.iface', autospec=True)
@mock.patch('qgis.PyQt.QtWidgets.QInputDialog.getText')
@mock.patch('import_data_to_db.utils.pop_up_info', autospec=True)
@mock.patch('import_data_to_db.utils.select_files')
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.import_all_data.checked = True
importer.confirm_names.checked = False
importer.skip_rows.checked = True
importer.start_import(importer.files,
importer.skip_rows.checked,
importer.confirm_names.checked,
importer.import_all_data.checked)
_test_wlvllogg_import_from_diveroffice_files(self, filenames)
test_string = utils_for_tests.create_test_string(db_utils.sql_load_fr_db('''SELECT obsid, date_time, head_cm, temp_degc, cond_mscm, level_masl, comment FROM w_levels_logger'''))
reference_string = r'''(True, [(rb1, 2016-03-15 10:31, 5.0, None, None, None, None), (rb1, 2016-03-15 10:30:00, 1.0, 10.0, None, None, None), (rb2, 2016-04-15 10:30:00, 2.0, 20.0, None, None, None), (rb2, 2016-04-15 11:00:00, 21.0, 201.0, None, None, None), (rb3, 2016-05-15 10:30:00, 3.0, 30.0, 5.0, None, None), (rb3, 2016-05-15 11:00:00, 31.0, 301.0, 6.0, None, None)])'''
assert test_string == reference_string
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:60,代码来源:test_import_diveroffice_postgis.py
示例12: test_interlab4_full_test_to_db_staff_0
def test_interlab4_full_test_to_db_staff_0(self):
db_utils.sql_alter_db(u'''INSERT INTO obs_points (obsid) VALUES ('anobsid')''')
interlab4_lines = (
'#Interlab',
'#Version=4.0',
'#Tecken=UTF-8',
'#Textavgränsare=Nej',
'#Decimaltecken=,',
'#Provadm',
'Lablittera;Namn;Adress;Postnr;Ort;Kommunkod;Projekt;Laboratorium;Provtyp;Provtagare;Registertyp;ProvplatsID;Provplatsnamn;Specifik provplats;Provtagningsorsak;Provtyp;Provtypspecifikation;Bedömning;Kemisk bedömning;Mikrobiologisk bedömning;Kommentar;År;Provtagningsdatum;Provtagningstid;Inlämningsdatum;Inlämningstid;',
'DM-990908-2773;MFR;PG Vejdes väg 15;351 96;Växjö;0780;Demoproj;Demo-Laboratoriet;NSG;0;;Demo1 vattenverk;;Föreskriven regelbunden undersökning enligt SLVFS 2001:30;Dricksvatten enligt SLVFS 2001:30;Utgående;Nej;Tjänligt;;;;2010;2010-09-07;10:15;2010-09-07;14:15;',
'#Provdat',
'Lablittera;Metodbeteckning;Parameter;Mätvärdetext;Mätvärdetal;Mätvärdetalanm;Enhet;Rapporteringsgräns;Detektionsgräns;Mätosäkerhet;Mätvärdespår;Parameterbedömning;Kommentar;',
'DM-990908-2773;SS-EN ISO 7887-1/4;Kalium;<2,5;2,5;;mg/l Pt;;;;;;;',
'DM-990908-2773;SS-EN ISO 7887-1/4;Kalium;<1;1;;mg/l Pt;;;;;;;',
'#Slut'
)
with utils.tempinput(u'\n'.join(interlab4_lines), 'utf-8') as filename:
@mock.patch('midvatten_utils.NotFoundQuestion')
@mock.patch('db_utils.QgsProject.instance', utils_for_tests.MidvattenTestSpatialiteNotCreated.mock_instance_settings_database)
@mock.patch('import_data_to_db.utils.Askuser', mocks_for_tests.mock_askuser.get_v)
@mock.patch('qgis.utils.iface', autospec=True)
@mock.patch('import_data_to_db.utils.pop_up_info', autospec=True)
@mock.patch('import_data_to_db.qgis.PyQt.QtWidgets.QFileDialog.getOpenFileNames')
def _test(self, filename, mock_filenames, mock_skippopup, mock_iface, mock_not_found_question):
mock_not_found_question.return_value.answer = 'ok'
mock_not_found_question.return_value.value = 'anobsid'
mock_not_found_question.return_value.reuse_column = 'obsid'
mock_filenames.return_value = [[filename]]
importer = Interlab4Import(self.iface.mainWindow(), self.ms)
importer.parse_observations_and_populate_gui()
importer.start_import(importer.all_lab_results, importer.metadata_filter.get_selected_lablitteras())
_test(self, filename)
test_string = utils_for_tests.create_test_string(db_utils.sql_load_fr_db(u'''SELECT * FROM w_qual_lab'''))
reference_string = '''(True, [(anobsid, None, DM-990908-2773, Demoproj, 0, 2010-09-07 10:15:00, SS-EN ISO 7887-1/4, Kalium, 2.5, <2,5, mg/l Pt, provtagningsorsak: Dricksvatten enligt SLVFS 2001:30. provtyp: Utgående. provtypspecifikation: Nej. bedömning: Tjänligt. provplatsid: Demo1 vattenverk. specifik provplats: Föreskriven regelbunden undersökning enligt SLVFS 2001:30), (anobsid, None, DM-990908-2773, Demoproj, 0, 2010-09-07 10:15:00, SS-EN ISO 7887-1/4, Kalium (dubblett 1), 1.0, <1, mg/l Pt, provtagningsorsak: Dricksvatten enligt SLVFS 2001:30. provtyp: Utgående. provtypspecifikation: Nej. bedömning: Tjänligt. provplatsid: Demo1 vattenverk. specifik provplats: Föreskriven regelbunden undersökning enligt SLVFS 2001:30)])'''
print(reference_string)
print(test_string)
assert test_string == reference_string
test_string = utils_for_tests.create_test_string(db_utils.sql_load_fr_db(u'''SELECT * FROM zz_staff'''))
reference_string = '(True, [(0, None)])'
assert test_string == reference_string
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:47,代码来源:test_import_interlab4_spatialite.py
示例13: test_translate_and_reorder_file_data
def test_translate_and_reorder_file_data(self):
file_data = [['obsid', 'acol', 'acol2'],
['rb1', '1', '2']]
translation_dict = {'obsid': ['obsid'], 'acol': ['num', 'txt'], 'acol2': ['comment']}
test_string = utils_for_tests.create_test_string(GeneralCsvImportGui.translate_and_reorder_file_data(file_data, translation_dict))
reference_string = '[[num, txt, comment, obsid], [1, 1, 2, rb1]]'
assert test_string == reference_string
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:9,代码来源:test_import_general_csv_gui.py
示例14: test_filter_dates_from_filedata
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
开发者ID:jkall,项目名称:qgis-midvatten-plugin,代码行数:9,代码来源:test_import_diveroffice.py
示例15: test_add_east_north_from_geometry
def test_add_east_north_from_geometry(self):
""" Test that adding triggers and adding obsid with geometry also adds east, north
:return:
"""
utils.add_triggers_to_obs_points()
utils.sql_alter_db(u"""INSERT INTO obs_points (obsid, geometry) VALUES ('rb1', GeomFromText('POINT(1.0 1.0)', 3006))""")
test_string = utils_for_tests.create_test_string(utils.sql_load_fr_db(u'select obsid, east, north, AsText(geometry) from obs_points'))
reference_string = u'(True, [(rb1, 1.0, 1.0, POINT(1 1))])'
assert test_string == reference_string
开发者ID:mirouml,项目名称:qgis-midvatten-plugin,代码行数:10,代码来源:test_create_db.py
注:本文中的utils_for_tests.create_test_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论