-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_results.py
130 lines (92 loc) · 4.31 KB
/
test_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'''
Created on Jun. 26, 2022
@author: cefect
unit tests for CanFlood's 'results' toolset
'''
from qgis.core import (
QgsCoordinateReferenceSystem, QgsVectorLayer, QgsProject, QgsReport, QgsReportSectionLayout,
)
from PyQt5.Qt import Qt
from PyQt5.QtTest import QTest
from PyQt5.QtWidgets import QAction, QFileDialog, QListWidget, QTableWidgetItem
from pandas.testing import assert_frame_equal
from pytest import fail
from pytest_qgis.utils import clean_qgis_layer
from results.dialog import ResultsDialog
import pandas as pd
import pytest, os, shutil
#===============================================================================
# fixtures-------
#===============================================================================
@pytest.fixture(scope='module')
def crs():
return QgsCoordinateReferenceSystem('EPSG:3005')
@pytest.fixture(scope='function')
def dial(session, cf_fp): #configured dialog
dial = session.Dialog
#===========================================================================
# copy over control file
#===========================================================================
cf_fp = shutil.copy2(cf_fp, os.path.join(session.out_dir, os.path.basename(cf_fp)))
#===========================================================================
# setup
#===========================================================================
dial._change_tab('tab_setup')
assert os.path.exists(cf_fp)
#set the working directory
dial.lineEdit_wdir.setText(str(session.out_dir))
#set the control file
dial.lineEdit_cf_fp.setText(cf_fp)
dial.radioButton.setChecked(True) #save plots to file
dial.checkBox_SSoverwrite.setChecked(False)
return dial
#===============================================================================
# tests---------
#===============================================================================
@pytest.mark.parametrize('dialogClass',[ResultsDialog], indirect=True)
@pytest.mark.parametrize('cf_fp',[r'tests2\data\test_model_02_r2_ModelDialog_t0\CanFlood_test_01.txt'], indirect=True) #from build test_07
def test_res_01_riskPlot(dial): #test risk plots
dial._change_tab('tab_riskPlot')
QTest.mouseClick(dial.pushButton_RP_plot, Qt.LeftButton)
# If an SVG is created, we can assume that the plotter has completed
svg_fp = os.path.join(dial.out_dir, [e for e in os.listdir(dial.out_dir) if e.endswith('.svg')][0])
if os.path.exists(svg_fp):
pass
else:
fail('Failed to create risk plot svg')
@pytest.mark.dev
@pytest.mark.parametrize('dialogClass',[ResultsDialog], indirect=True)
@pytest.mark.parametrize('cf_fp',[r'tests2\data\test_model_02_r2_ModelDialog_t0\CanFlood_test_01.txt'], indirect=True) #from build test_07
@pytest.mark.parametrize('finv_fp',[r'tutorials\2\finv_tut2.geojson'], indirect=True)
def test_res_02_pdf_report(dial, finv_fp):
"""generate a pdf report, validate
TODO:
add additional cases (e.g., no vector layer)
write to file (spent 20 mins and couldn't figure this out)
"""
report = res_02_reporter(dial, finv_fp=finv_fp, vsect_cnt=6)
def res_02_reporter(dial, finv_fp=None, vsect_cnt = 5):
"""build and test report
refacorted for use in tutoirals test
ResultsDialog.run_reporter()
"""
dial._change_tab('tab_report')
#===========================================================================
# attach layer
#===========================================================================
if not finv_fp is None:
finv_vlay = dial.session.load_vlay(finv_fp)
dial.comboBox_rpt_vlay.setLayer(finv_vlay)
#===========================================================================
# build report
#===========================================================================
QTest.mouseClick(dial.pushButton_rpt_create, Qt.LeftButton)
report = dial.report
#===========================================================================
# validate
#===========================================================================
assert isinstance(report, QgsReport)
sections = report.childSections()
if not len(sections) == vsect_cnt:
fail('expected %i sections got %i'%(vsect_cnt, len(sections)))
return report