Fix for misc.save_script_parameters (Issue #136)#140
Conversation
Attempt to fix the problem in a new branch, see imcf#136 for details.
This is necessary as calling globals from inside the method lead to no variables from the call time.
m (Issue #136) misc.save_script_parameters (Issue #136)
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #140 +/- ##
====================================
+ Coverage 30% 32% +2%
====================================
Files 25 25
Lines 1748 1782 +34
====================================
+ Hits 526 563 +37
+ Misses 1222 1219 -3 β View full report in Codecov by Sentry. π New features to boost your workflow:
|
|
Is there anything to be done for the codecov failing? There is no way to really test this part |
The previous approach of "fetching" it within the function didn't work out, so having it as an optional parameter doesn't make much sense any more. π¨ WARNING π¨ This change will break any existing scripts that were using the function from a pre-release of imcflibs!
With switching to monkeypatch, it's not needed any more.
| @@ -115,13 +115,15 @@ def _is_password_style(item): | |||
| monkeypatch.setattr(imcflibs.imagej.misc, "_is_password_style", _is_password_style) | |||
|
|
|||
| script_module = ScriptModule( | |||
There was a problem hiding this comment.
@rohangirishrao let's discuss together what makes sense in terms of testing once you're back!
π§ We also need to verify if the modified code in save_script_parameters() still works in ImageJ / Jython as expected / intended! π§
There was a problem hiding this comment.
TODO: it is better to keep them split, as using the same output_dir from script params for example, in all methods is easier. The name of the file can be changed separately from the path, we have other methods where we pass the output_dir so for consistency, I think it's best to keep both.
_is_password_style() looks great, thanks for that! I think the tests are good, we could test for the save_file_name being correct, but maybe that's not so necessary. We can take a look together tomorrow, and I'll see if I can test it in Fiji till then.
There was a problem hiding this comment.
- Regarding the two separate parameters: understood, that's what my (very faint) memory told me anyway, hence the question. β‘οΈ β
- The saved file is already re-read by the test, so that should be fine. Regarding testing in Fiji, I have now updated the corresponding file in
tests/interactive-imagej/(and renamed it fromtest_save_params.mdtosave-script-parameters.py), which also lead to the discovery of a bug that got fixed in e8140ed. Let's have another look together tomorrow, but I believe we should be fine here.
There was a problem hiding this comment.
it is better to keep them split, as using the same
output_dirfrom script params for example, in all methods is easier. The name of the file can be changed separately from the path, we have other methods where we pass theoutput_dirso for consistency, I think it's best to keep both.
Done (added a comment to explain the intent) in 8b208cb β
| # TODO: discuss if this approach is fine within Fiji/Jython | ||
| try: | ||
| val = inputs.get(key) | ||
| if not val: # required for testing in CPython | ||
| raise KeyError("failure looking up value for '%s'" % key) | ||
| f.write("%s: %s\n" % (key, str(val))) | ||
| saved += 1 | ||
| except: | ||
| log.warning("Unable to fetch value for parameter: %s", key) | ||
| pass |
There was a problem hiding this comment.
π§ This needs to be validated (cf. comment in tests)! π§
There was a problem hiding this comment.
The code in the state as shown here would ignore / exclude boolean parameters with a value of False - as mentioned in the previous comment, this is now fixed in e8140ed.
The previous "if not val" also triggers if the parameter is a boolean that has the value "False" and therefore wrongly excludes those. Checking for "is None" only triggers if the .get() call fails and returns its default value (None).
The workflow described in TESTING.md states to drag and drop the script onto Fiji, so for the time being let's stick to that
|
Actually... While doing all of this a few more ideas for this function popped π‘ up:
|
|
After discussing today we decided to:
|
The function now accepts
globals()as a parameter - this is a workaround as calling globals() from the method did not work, see #136.