Fix Windows scheduled startup failures
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from docutranslate import app
|
||||
|
||||
|
||||
class ServiceStartupTest(unittest.TestCase):
|
||||
@patch.dict(os.environ, {"DOCUTRANSLATE_STRICT_PORT": "1"}, clear=False)
|
||||
@patch.object(app, "find_free_port", return_value=8011)
|
||||
def test_strict_port_rejects_occupied_configured_port(self, _find_free_port):
|
||||
with self.assertRaisesRegex(RuntimeError, "端口 8010 已被占用"):
|
||||
app.run_app(host="127.0.0.1", port=8010)
|
||||
|
||||
@patch.dict(os.environ, {"DOCUTRANSLATE_STRICT_PORT": ""}, clear=False)
|
||||
@patch.object(app.uvicorn, "run")
|
||||
@patch.object(app, "find_free_port", return_value=8011)
|
||||
def test_interactive_mode_can_still_fall_back_to_free_port(
|
||||
self, _find_free_port, uvicorn_run
|
||||
):
|
||||
app.run_app(host="127.0.0.1", port=8010)
|
||||
uvicorn_run.assert_called_once_with(
|
||||
app.app, host="127.0.0.1", port=8011, workers=1
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user