From cc9066473e306ffb70a0c35ec20c4e9128e607da Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Wed, 19 Jun 2019 12:17:08 +0100 Subject: [PATCH] fix alternative loops (#238) * fix alternative loops * remove codecov from appveyor --- .appveyor.yml | 9 --------- aiohttp_devtools/runserver/config.py | 3 +-- aiohttp_devtools/runserver/serve.py | 7 ++++--- tests/test_runserver_config.py | 4 ++-- tests/test_runserver_main.py | 4 ++-- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 902027a5..cea05a58 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -28,14 +28,5 @@ test_script: - "%PYTHON%\\python.exe -m setup check -rms" - "%PYTHON%\\python.exe -m pytest --cov=aiohttp_devtools --cov-report term-missing:skip-covered --cov-report xml --junitxml junit-test-results.xml --duration 5 -m \"not isort\" -vv --fulltrace" -after_test: -- ps: | - $wc = New-Object 'System.Net.WebClient' - $wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\junit-test-results.xml)) -- ps: | - $env:PATH = 'C:\msys64\usr\bin;' + $env:PATH - Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh - bash codecov.sh -f "coverage.xml" - artifacts: - path: dist\* diff --git a/aiohttp_devtools/runserver/config.py b/aiohttp_devtools/runserver/config.py index 14d3cc82..c2a27d4f 100644 --- a/aiohttp_devtools/runserver/config.py +++ b/aiohttp_devtools/runserver/config.py @@ -157,8 +157,7 @@ def import_app_factory(self): self.watch_path = self.watch_path or Path(module.__file__).parent return attr - async def load_app(self): - app_factory = self.import_app_factory() + async def load_app(self, app_factory): if isinstance(app_factory, web.Application): app = app_factory else: diff --git a/aiohttp_devtools/runserver/serve.py b/aiohttp_devtools/runserver/serve.py index b74cb181..e0f532e5 100644 --- a/aiohttp_devtools/runserver/serve.py +++ b/aiohttp_devtools/runserver/serve.py @@ -115,8 +115,9 @@ def set_tty(tty_path): # pragma: no cover def serve_main_app(config: Config, tty_path: Optional[str]): with set_tty(tty_path): setup_logging(config.verbose) + app_factory = config.import_app_factory() loop = asyncio.get_event_loop() - runner = loop.run_until_complete(start_main_app(config, loop)) + runner = loop.run_until_complete(start_main_app(config, app_factory, loop)) try: loop.run_forever() except KeyboardInterrupt: # pragma: no cover @@ -126,8 +127,8 @@ def serve_main_app(config: Config, tty_path: Optional[str]): loop.run_until_complete(runner.cleanup()) -async def start_main_app(config: Config, loop): - app = await config.load_app() +async def start_main_app(config: Config, app_factory, loop): + app = await config.load_app(app_factory) modify_main_app(app, config) diff --git a/tests/test_runserver_config.py b/tests/test_runserver_config.py index 2e526ef9..ae679bbb 100644 --- a/tests/test_runserver_config.py +++ b/tests/test_runserver_config.py @@ -37,7 +37,7 @@ async def app_factory(): """ }) config = Config(app_path='app.py') - app = await config.load_app() + app = await config.load_app(config.import_app_factory()) assert isinstance(app, web.Application) @@ -51,4 +51,4 @@ def app_factory(): }) config = Config(app_path='app.py') with pytest.raises(AiohttpDevConfigError): - await config.load_app() + await config.load_app(config.import_app_factory()) diff --git a/tests/test_runserver_main.py b/tests/test_runserver_main.py index 58509db9..c0c893ae 100644 --- a/tests/test_runserver_main.py +++ b/tests/test_runserver_main.py @@ -155,7 +155,7 @@ async def test_serve_main_app(tmpworkdir, loop, mocker): loop.call_later(0.5, loop.stop) config = Config(app_path='app.py') - await start_main_app(config, loop) + await start_main_app(config, config.import_app_factory(), loop) mock_modify_main_app.assert_called_with(mock.ANY, config) @@ -176,7 +176,7 @@ async def hello(request): mock_modify_main_app = mocker.patch('aiohttp_devtools.runserver.serve.modify_main_app') config = Config(app_path='app.py') - await start_main_app(config, loop) + await start_main_app(config, config.import_app_factory(), loop) mock_modify_main_app.assert_called_with(mock.ANY, config)