Skip to content

Commit 4df1ae1

Browse files
committed
enh: allow curve_list_update to fail
1 parent fcbc6ad commit 4df1ae1

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

pyjibe/fd/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import hashlib
2+
import importlib.resources
23
import io
4+
import logging
35
import os
46
import pathlib
5-
import importlib.resources
67
import time
8+
import traceback
79

810
import afmformats.errors
911
import nanite
@@ -21,6 +23,8 @@
2123
from . import rating_iface
2224

2325

26+
logger = logging.getLogger(__name__)
27+
2428
# load QWidget from ui file
2529
dlg_ref = importlib.resources.files("pyjibe.fd") / "dlg_autosave_design.ui"
2630
with importlib.resources.as_file(dlg_ref) as dlg_autosave_path:
@@ -501,12 +505,21 @@ def on_fit_all(self):
501505
if bar.wasCanceled():
502506
break
503507
try:
508+
# preprocessing could fail for bad data
504509
self.tab_preprocess.apply_preprocessing(fdist)
510+
# external fitting model could fail
505511
self.tab_fit.fit_approach_retract(fdist, update_ui=False)
506512
except BaseException as e:
513+
logger.error(traceback.format_exc())
507514
errored.append([fdist.path, e.__class__.__name__, e.args])
508515
finally:
509-
self.curve_list_update(item=ii)
516+
try:
517+
# updating curve list may not be possible
518+
self.curve_list_update(item=ii)
519+
except BaseException as e:
520+
logger.error(traceback.format_exc())
521+
errored.append([fdist.path, e.__class__.__name__, e.args])
522+
510523
bar.setValue(ii+1)
511524

512525
# display qmap

tests/test_fd_fit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_ancillary_update_init(qtbot):
2828
model_key="test1"):
2929

3030
main_window = pyjibe.head.PyJibe()
31+
qtbot.addWidget(main_window)
3132
main_window.load_data(files=make_directory_with_data(2))
3233
war = main_window.subwindows[0].widget()
3334
# clear data
@@ -57,6 +58,7 @@ def test_ancillary_update_init(qtbot):
5758
war.list_curves.setCurrentItem(it)
5859
assert itab.item(0, 1).text() == "2000"
5960
assert atab.item(0, 1).text() == "2000"
61+
main_window.close()
6062

6163

6264
def test_ancillary_update_nan(qtbot):
@@ -68,6 +70,7 @@ def test_ancillary_update_nan(qtbot):
6870
model_key="test1"):
6971

7072
main_window = pyjibe.head.PyJibe()
73+
qtbot.addWidget(main_window)
7174
main_window.load_data(files=make_directory_with_data(2))
7275
war = main_window.subwindows[0].widget()
7376
# clear data
@@ -85,6 +88,7 @@ def test_ancillary_update_nan(qtbot):
8588
atab = war.tab_fit.table_parameters_anc
8689
assert atab.item(0, 1).text() == "nan"
8790
assert itab.item(0, 1).text() == "3000"
91+
main_window.close()
8892

8993

9094
def test_ancillary_update_preproc_change(qtbot):
@@ -98,6 +102,7 @@ def test_ancillary_update_preproc_change(qtbot):
98102
model_key="test1"):
99103

100104
main_window = pyjibe.head.PyJibe()
105+
qtbot.addWidget(main_window)
101106
main_window.load_data(files=make_directory_with_data(2))
102107
war = main_window.subwindows[0].widget()
103108
# clear data
@@ -130,6 +135,7 @@ def test_ancillary_update_preproc_change(qtbot):
130135
assert len(war.tab_preprocess.current_preprocessing()[0]) == 2
131136
assert atab.item(0, 1).text() == "2345"
132137
assert itab.item(0, 1).text() == "2345"
138+
main_window.close()
133139

134140

135141
@pytest.mark.filterwarnings('ignore::UserWarning')
@@ -153,6 +159,7 @@ def test_apply_and_fit_all_with_bad_data(qtbot, monkeypatch):
153159

154160
# initialize
155161
main_window = pyjibe.head.PyJibe()
162+
qtbot.addWidget(main_window)
156163
main_window.load_data(files=files)
157164
war = main_window.subwindows[0].widget()
158165
war.tab_preprocess.set_preprocessing(
@@ -173,10 +180,12 @@ def test_apply_and_fit_all_with_bad_data(qtbot, monkeypatch):
173180
assert float(bad.data(2, 0)) == -1 # column 2 shows the rating
174181
good2 = war.list_curves.topLevelItem(2)
175182
assert float(good2.data(2, 0)) > 0 # column 2 shows the rating
183+
main_window.close()
176184

177185

178186
def test_change_model_keep_parms(qtbot):
179187
main_window = pyjibe.head.PyJibe()
188+
qtbot.addWidget(main_window)
180189
main_window.load_data(files=make_directory_with_data(2))
181190
war = main_window.subwindows[0].widget()
182191
# clear data
@@ -194,10 +203,12 @@ def test_change_model_keep_parms(qtbot):
194203
war.tab_fit.cb_model.setCurrentIndex(pyr_idx)
195204
# check that contact point is still the same
196205
assert float(itab.item(3, 1).text()) == 12345
206+
main_window.close()
197207

198208

199209
def test_remember_initial_params(qtbot):
200210
main_window = pyjibe.head.PyJibe()
211+
qtbot.addWidget(main_window)
201212
main_window.load_data(files=make_directory_with_data(2))
202213
war = main_window.subwindows[0].widget()
203214
# clear data
@@ -220,10 +231,12 @@ def test_remember_initial_params(qtbot):
220231
cl2 = war.list_curves.itemBelow(cl1)
221232
war.list_curves.setCurrentItem(cl2)
222233
assert float(itab.item(1, 1).text()) == 5
234+
main_window.close()
223235

224236

225237
def test_set_indentation_depth_manually_infdoublespinbox(qtbot):
226238
main_window = pyjibe.head.PyJibe()
239+
qtbot.addWidget(main_window)
227240
main_window.load_data(files=make_directory_with_data(2))
228241
war = main_window.subwindows[0].widget()
229242
# perform fitting with standard parameters
@@ -248,3 +261,4 @@ def test_set_indentation_depth_manually_infdoublespinbox(qtbot):
248261
war.tab_fit.sp_range_1.clear()
249262
qtbot.keyClicks(war.tab_fit.sp_range_1, text_entered)
250263
assert war.tab_fit.sp_range_1.value() == resulting_value
264+
main_window.close()

0 commit comments

Comments
 (0)