Skip to content
Snippets Groups Projects
Commit be0b01c4 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Test xfel_calibrate without needing to monkeypatch sys.argv

parent 536bfed6
No related branches found
No related tags found
1 merge request!575Refactor parsing arguments and loading main notebook
......@@ -227,14 +227,13 @@ class CalibrateCall:
if extra_args:
self.args.extend(extra_args)
with mock.patch.object(sys, "argv", self.args):
with mock.patch.object(calibrate, "temp_path", str(tmp_path)):
calibrate.run()
with mock.patch.object(calibrate, "temp_path", str(tmp_path)):
calibrate.run(argv=self.args)
out, err = capsys.readouterr()
out, err = capsys.readouterr()
self.out: str = out
self.err: str = err
self.out: str = out
self.err: str = err
Paths = NamedTuple(
"Paths",
......
......@@ -30,10 +30,9 @@ class TestBasicCalls:
that the expected output is present in stdout
"""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "--help"])
def test_help(self, capsys):
with pytest.raises(SystemExit):
calibrate.run()
calibrate.run(["xfel-calibrate", "--help"])
out, err = capsys.readouterr()
......@@ -43,10 +42,9 @@ class TestBasicCalls:
assert err == ""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "TEST", "-h"])
def test_help_detector(self, capsys):
with pytest.raises(SystemExit):
calibrate.run()
calibrate.run(["xfel-calibrate", "TEST", "-h"])
out, err = capsys.readouterr()
......@@ -55,10 +53,9 @@ class TestBasicCalls:
assert err == ""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "TEST", "-h"])
def test_help_user_notebook(self, capsys):
with pytest.raises(SystemExit):
calibrate.run()
calibrate.run(["xfel-calibrate", "TEST", "-h"])
out, err = capsys.readouterr()
......@@ -67,15 +64,13 @@ class TestBasicCalls:
assert err == ""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "TEST-RAISES-ERRORS", "--help"])
def test_help_bad_config(self):
with pytest.raises(KeyError):
calibrate.run()
calibrate.run(["xfel-calibrate", "TEST-RAISES-ERRORS", "--help"])
@mock.patch.object(sys, "argv", ["xfel-calibrate", "NotADetector", "beep", "-h"])
def test_unknown_detector(self, capsys):
with pytest.raises(SystemExit) as exit_exception:
calibrate.run()
calibrate.run(["xfel-calibrate", "NotADetector", "beep", "-h"])
out, err = capsys.readouterr()
......@@ -85,10 +80,9 @@ class TestBasicCalls:
assert err == ""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "NotADetector", "-h"])
def test_unknown_detector_h(self, capsys):
with pytest.raises(SystemExit) as exit_exception:
calibrate.run()
calibrate.run(["xfel-calibrate", "NotADetector", "-h"])
out, err = capsys.readouterr()
......@@ -98,10 +92,9 @@ class TestBasicCalls:
assert err == ""
@mock.patch.object(sys, "argv", ["xfel-calibrate", "Tutorial", "TEST", "--help"])
def test_help_nb(self, capsys):
with pytest.raises(SystemExit):
calibrate.run()
calibrate.run(["xfel-calibrate", "Tutorial", "TEST", "--help"])
out, err = capsys.readouterr()
......@@ -165,6 +158,7 @@ class TestTutorialNotebook:
def test_expected_processes_called(
self,
calibrate_call: CalibrateCall,
fake_process_calibrate: FakeProcessCalibrate,
):
process_calls = [
......
......@@ -126,6 +126,7 @@ class TestUserVenv:
def test_expected_processes_called(
self,
calibrate_call: CalibrateCall,
mock_proposal: MockProposal,
fake_process_calibrate: FakeProcessCalibrate,
):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment