-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
from nbautoexport.utils import cleared_argv | ||
|
||
|
||
def test_cleared_argv(monkeypatch): | ||
"""cleared_argv context manager clears sys.argv and restores it on exit | ||
""" | ||
mocked_argv = ["nbautoexport", "convert", "the_notebook.ipynb", "-f", "script"] | ||
monkeypatch.setattr(sys, "argv", mocked_argv) | ||
|
||
assert sys.argv == mocked_argv | ||
|
||
with cleared_argv(): | ||
assert sys.argv == mocked_argv[:1] | ||
|
||
assert sys.argv == mocked_argv | ||
|
||
|
||
def test_cleared_argv_with_error(monkeypatch): | ||
"""cleared_argv context manager restores sys.argv even with exception | ||
""" | ||
mocked_argv = ["nbautoexport", "convert", "the_notebook.ipynb", "-f", "script"] | ||
monkeypatch.setattr(sys, "argv", mocked_argv) | ||
|
||
assert sys.argv == mocked_argv | ||
|
||
with pytest.raises(Exception): | ||
with cleared_argv(): | ||
assert sys.argv == mocked_argv[:1] | ||
raise Exception | ||
|
||
assert sys.argv == mocked_argv |