-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow passing a config from command line (#257)
* ENH: Allow passing a config from command line * enh: address review * test: update tests for new cli args * test: use warnings instead of napari for pytest * fixup --------- Co-authored-by: Talley Lambert <[email protected]>
- Loading branch information
1 parent
e5a6f9c
commit 41a9943
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from napari_micromanager.__main__ import main | ||
from pymmcore_plus import CMMCorePlus | ||
|
||
|
||
def test_cli_main() -> None: | ||
@pytest.mark.parametrize( | ||
"argv", | ||
[ | ||
[], | ||
["--config", str(Path(__file__).parent / "test_config.cfg")], | ||
["-c", "nonexistant"], | ||
], | ||
) | ||
def test_cli_main(argv: list) -> None: | ||
import napari | ||
from napari.qt import QtViewer | ||
|
||
with patch("napari.run") as mock_run: | ||
with patch("qtpy.QtWidgets.QMainWindow.show") as mock_show: | ||
main() | ||
if "nonexistant" in argv: | ||
with pytest.warns(): | ||
main(argv) | ||
else: | ||
main(argv) | ||
|
||
mock_run.assert_called_once() | ||
mock_show.assert_called_once() | ||
|
||
if argv and "test_config" in argv[-1]: | ||
assert len(CMMCorePlus.instance().getLoadedDevices()) > 1 | ||
|
||
# this is to prevent a leaked widget error in the NEXT test | ||
napari.current_viewer().close() | ||
QtViewer._instances.clear() |