Exemplo n.º 1
0
 def test_run_pre_start_script_none(self, mocker: MockerFixture) -> None:
     """Test `start.run_pre_start_script` with `PRE_START_PATH` set to `None`."""
     logger = mocker.patch.object(start.logging, "root", autospec=True)
     start.run_pre_start_script(logger=logger)
     logger.debug.assert_has_calls(
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call("No pre-start script specified."),
         ]
     )
Exemplo n.º 2
0
 def test_run_pre_start_script_no_file(
     self,
     mock_logger: logging.Logger,
     mocker: MockerFixture,
     monkeypatch: MonkeyPatch,
 ) -> None:
     """Test `start.run_pre_start_script` with an incorrect file path."""
     monkeypatch.setenv("PRE_START_PATH", "/no/file/here")
     start.run_pre_start_script(logger=mock_logger)
     mock_logger.debug.assert_has_calls(  # type: ignore[attr-defined]
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call("No pre-start script found."),
         ])
Exemplo n.º 3
0
 def test_run_pre_start_script_no_file(
     self,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
 ) -> None:
     """Test `start.run_pre_start_script` with an incorrect file path."""
     logger = mocker.patch.object(start.logging, "root", autospec=True)
     monkeypatch.setenv("PRE_START_PATH", "/no/file/here")
     start.run_pre_start_script(logger=logger)
     logger.debug.assert_has_calls(
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call("No pre-start script found."),
         ]
     )
Exemplo n.º 4
0
 def test_run_pre_start_script_sh(
     self,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
     pre_start_script_tmp_sh: Path,
 ) -> None:
     """Test `start.run_pre_start_script` using temporary pre-start shell script."""
     logger = mocker.patch.object(start.logging, "root", autospec=True)
     monkeypatch.setenv("PRE_START_PATH", str(pre_start_script_tmp_sh))
     pre_start_path = os.getenv("PRE_START_PATH")
     start.run_pre_start_script(logger=logger)
     logger.debug.assert_has_calls(
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call(f"Running pre-start script with sh {pre_start_path}."),
             mocker.call(f"Ran pre-start script with sh {pre_start_path}."),
         ]
     )
Exemplo n.º 5
0
 def test_run_pre_start_script_sh(
     self,
     mock_logger: logging.Logger,
     mocker: MockerFixture,
     monkeypatch: MonkeyPatch,
     pre_start_script_tmp_sh: Path,
 ) -> None:
     """Test `start.run_pre_start_script` using temporary pre-start shell script."""
     monkeypatch.setenv("PRE_START_PATH", str(pre_start_script_tmp_sh))
     start.run_pre_start_script(logger=mock_logger)
     mock_logger.debug.assert_has_calls(  # type: ignore[attr-defined]
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call(
                 f"Running pre-start script with sh {os.getenv('PRE_START_PATH')}."
             ),
             mocker.call(
                 f"Ran pre-start script with sh {os.getenv('PRE_START_PATH')}."
             ),
         ])
Exemplo n.º 6
0
 def test_run_pre_start_script_error(
     self,
     mocker: MockerFixture,
     monkeypatch: pytest.MonkeyPatch,
     pre_start_script_error: Path,
 ) -> None:
     """Test `start.run_pre_start_script` with an error exit code."""
     logger = mocker.patch.object(start.logging, "root", autospec=True)
     monkeypatch.setenv("PRE_START_PATH", str(pre_start_script_error))
     pre_start_path = os.getenv("PRE_START_PATH")
     process = "python" if pre_start_script_error.suffix == ".py" else "sh"
     with pytest.raises(start.subprocess.CalledProcessError):
         start.run_pre_start_script(logger=logger)
     assert logger.debug.call_count == 2
     logger.debug.assert_has_calls(
         calls=[
             mocker.call("Checking for pre-start script."),
             mocker.call(
                 f"Running pre-start script with {process} {pre_start_path}."
             ),
         ]
     )