Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix alternative loops #238

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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\*
3 changes: 1 addition & 2 deletions aiohttp_devtools/runserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions aiohttp_devtools/runserver/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_runserver_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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())
4 changes: 2 additions & 2 deletions tests/test_runserver_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down