You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I'm starting to create unit tests for ZotQuery, and I'm struggling to get alfred-workflow to work with me. While I'm certain to have other issues, my initial problem concerns the assertEqual function within unittest.
Specifically, I can't assertEqual when running a test query through my filter script. Here's my function:
When I run filter.main(self.wf), it will print the "No Results" xml to the console, but I can't trap it in a var to assertEqual. How can I write unittests for a workflow written in alfred-workflow?
The text was updated successfully, but these errors were encountered:
Typically, you shouldn't call your main function in unit tests. You should keep it simple and move the functionality to other functions/classes that you call from a barebones main. The general rule is that if you can't isolate a function to unit test it, it isn't designed well and you need to refactor the code anyway.
That won't help you capture the output of Workflow however. To do that you would temporarily reassign sys.stdout (which is what Workflow writes its XML output to) to a StringIO object and read the results from there:
fromStringIOimportStringIOfp=StringIO()
# reassign sys.stdout to StringIO instanceorig_stdout=sys.stdoutsys.stdout=fp# whatever code that makes `Workflow` do its thing herewf.send_feedback()
# set sys.stdout back to its proper value (a `finally` clause may be a better place for this)sys.stdout=orig_stdout# retrieve Workflow output from the StringIO instanceself.assertEqual(fp.getvalue(), expected_value)
So I'm starting to create unit tests for ZotQuery, and I'm struggling to get alfred-workflow to work with me. While I'm certain to have other issues, my initial problem concerns the
assertEqual
function withinunittest
.Specifically, I can't
assertEqual
when running a test query through myfilter
script. Here's my function:When I run
filter.main(self.wf)
, it will print the "No Results" xml to the console, but I can't trap it in a var toassertEqual
. How can I write unittests for a workflow written in alfred-workflow?The text was updated successfully, but these errors were encountered: