Skip to content

Commit

Permalink
tests revision
Browse files Browse the repository at this point in the history
  • Loading branch information
zrvku2000 committed Jan 22, 2025
1 parent 1eb12ed commit cfd5241
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion aiohttp_devtools/runserver/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def _src_reload_when_live(self, checks: int) -> None:
assert self._app is not None and self._session is not None

if self._app[WS]:
url = "{0.protocol}}://{0.host}:{0.main_port}/?_checking_alive=1".format(self._config)
url = "{0.protocol}://{0.host}:{0.main_port}/?_checking_alive=1".format(self._config)
logger.debug('checking app at "%s" is running before prompting reload...', url)
for i in range(checks):
await asyncio.sleep(0.1)
Expand Down
22 changes: 0 additions & 22 deletions main.py

This file was deleted.

12 changes: 8 additions & 4 deletions tests/test_runserver_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async def test_create_app_wrong_name(tmpworkdir):
mktree(tmpworkdir, SIMPLE_APP)
config = Config(app_path='app.py', app_factory_name='missing')
with pytest.raises(AiohttpDevConfigError) as excinfo:
config.get_app_factory()
module = config.import_module
config.get_app_factory(module)
assert excinfo.value.args[0] == "Module 'app.py' does not define a 'missing' attribute/class"


Expand All @@ -56,7 +57,8 @@ async def app_factory():
"""
})
config = Config(app_path='app.py')
app = await config.load_app(config.get_app_factory())
module = config.import_module()
app = await config.load_app(config.get_app_factory(module))
assert isinstance(app, web.Application)


Expand All @@ -69,9 +71,10 @@ def app_factory():
"""
})
config = Config(app_path='app.py')
module = config.import_module()
with pytest.raises(AiohttpDevConfigError,
match=r"'app_factory' returned 'int' not an aiohttp\.web\.Application"):
await config.load_app(config.get_app_factory())
await config.load_app(config.get_app_factory(module))


@forked
Expand All @@ -83,6 +86,7 @@ def app_factory(foo):
"""
})
config = Config(app_path='app.py')
module = config.import_module()
with pytest.raises(AiohttpDevConfigError,
match=r"'app\.py\.app_factory' should not have required arguments"):
await config.load_app(config.get_app_factory())
await config.load_app(config.get_app_factory(module))
19 changes: 12 additions & 7 deletions tests/test_runserver_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ async def create_app():

set_start_method("spawn")
config = Config(app_path="app.py", root_path=tmpworkdir, main_port=0, app_factory_name="create_app")
config.get_app_factory()
module = config.import_module()
config.get_app_factory(module)
app_task = AppTask(config)

app_task._start_dev_server()
Expand All @@ -162,7 +163,8 @@ async def create_app():
async def test_run_app_aiohttp_client(tmpworkdir, aiohttp_client):
mktree(tmpworkdir, SIMPLE_APP)
config = Config(app_path='app.py')
app_factory = config.get_app_factory()
module = config.import_module()
app_factory = config.get_app_factory(module)
app = await config.load_app(app_factory)
modify_main_app(app, config)
assert isinstance(app, aiohttp.web.Application)
Expand All @@ -178,7 +180,8 @@ async def test_run_app_aiohttp_client(tmpworkdir, aiohttp_client):
async def test_run_app_browser_cache(tmpworkdir, aiohttp_client):
mktree(tmpworkdir, SIMPLE_APP)
config = Config(app_path="app.py", browser_cache=True)
app_factory = config.get_app_factory()
module = config.import_module()
app_factory = config.get_app_factory(module)
app = await config.load_app(app_factory)
modify_main_app(app, config)
cli = await aiohttp_client(app)
Expand Down Expand Up @@ -208,8 +211,9 @@ async def test_serve_main_app(tmpworkdir, mocker):
loop.call_later(0.5, loop.stop)

config = Config(app_path="app.py", main_port=0)
runner = await create_main_app(config, config.get_app_factory())
await start_main_app(runner, config.bind_address, config.main_port)
module = config.import_module()
runner = await create_main_app(config, config.get_app_factory(module))
await start_main_app(runner, config.bind_address, config.main_port, None)

mock_modify_main_app.assert_called_with(mock.ANY, config)

Expand All @@ -232,8 +236,9 @@ async def hello(request):
mock_modify_main_app = mocker.patch('aiohttp_devtools.runserver.serve.modify_main_app')

config = Config(app_path="app.py", main_port=0)
runner = await create_main_app(config, config.get_app_factory())
await start_main_app(runner, config.bind_address, config.main_port)
module = config.import_module()
runner = await create_main_app(config, config.get_app_factory(module))
await start_main_app(runner, config.bind_address, config.main_port, None)

mock_modify_main_app.assert_called_with(mock.ANY, config)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_runserver_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async def test_python_no_server(mocker):

config = MagicMock()
config.main_port = 8000
config.protocol = 'http'
app_task = AppTask(config)
start_mock = mocker.patch.object(app_task, "_start_dev_server", autospec=True)
stop_mock = mocker.patch.object(app_task, "_stop_dev_server", autospec=True)
Expand Down Expand Up @@ -109,6 +110,7 @@ async def test_reload_server_running(aiohttp_client, mocker):
config = MagicMock()
config.host = "localhost"
config.main_port = cli.server.port
config.protocol = 'http'

app_task = AppTask(config)
app_task._app = app
Expand Down

0 comments on commit cfd5241

Please sign in to comment.