test_dataladcmd_exec.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from datalad.tests.utils_pytest import (
  2. assert_equal,
  3. assert_in,
  4. assert_result_count,
  5. )
  6. from ..dataladcmd_exec import GooeyDataladCmdExec
  7. def test_GooeyDataladCmdExec(qtbot):
  8. executor = GooeyDataladCmdExec()
  9. cmd = 'nonsense'
  10. with qtbot.waitSignal(executor.execution_failed) as block_for_fail, \
  11. qtbot.assertNotEmitted(executor.execution_started), \
  12. qtbot.assertNotEmitted(executor.execution_finished), \
  13. qtbot.assertNotEmitted(executor.results_received):
  14. executor.execute(cmd, {}, {})
  15. # Note: blocker.args delivers the arguments to the signal
  16. assert_equal(block_for_fail.args[1], "nonsense")
  17. assert_in("module 'datalad.api' has no attribute 'nonsense'",
  18. block_for_fail.args[-1].format_short())
  19. cmd = 'wtf'
  20. # MultSignalBlocker via waitSignals() doesn't "work". It blocks
  21. # correctly, but signal args are inaccessible contrary to the pytest-qt
  22. # docs. Hence, use the uglier way here:
  23. with qtbot.waitSignal(executor.execution_started) as block_start, \
  24. qtbot.waitSignal(executor.execution_finished) as block_finish, \
  25. qtbot.waitSignal(executor.results_received) as block_result, \
  26. qtbot.assertNotEmitted(executor.execution_failed):
  27. executor.execute(cmd, {}, {})
  28. # command
  29. assert_equal(block_start.args[1], "wtf")
  30. assert_equal(block_finish.args[1], "wtf")
  31. # thread_id matches:
  32. assert_equal(block_start.args[0], block_finish.args[0])
  33. # results received:
  34. # command class
  35. assert_equal(block_result.args[0].__qualname__,
  36. 'WTF')
  37. # actual results:
  38. res = block_result.args[1]
  39. assert_result_count(res, 1, action="wtf", status="ok")