Skip to content

tests/core/test_reloading.py

Source from this local checkout, regenerated when the reader rebuilds. Line links use #L<number>; a GitHub line range opens its first line.

1 # Copyright 2025 Softwell S.r.l.2 #3 # Licensed under the Apache License, Version 2.0 (the "License");4 # you may not use this file except in compliance with the License.5 # You may obtain a copy of the License at6 #7 #     https://www.apache.org/licenses/LICENSE-2.08 #9 # Unless required by applicable law or agreed to in writing, software10 # distributed under the License is distributed on an "AS IS" BASIS,11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 # See the License for the specific language governing permissions and13 # limitations under the License.14 15 """The public reload launch (#39): any launcher names the roots, the payload16 travels to ``factory()`` through the environment, and the CLI is one caller."""17 18 from __future__ import annotations19 20 import json21 import os22 23 import pytest24 25 from genro_asgi.reloading import FACTORY_TARGET, LAUNCHER_ENV, serve_reloading26 27 28 def test_the_caller_names_the_roots_and_the_payload_reaches_the_environment(monkeypatch):29     launched: dict = {}30     monkeypatch.setattr(31         "genro_asgi.reloading.uvicorn.run",32         lambda target, **kwargs: launched.update(target=target, **kwargs),33     )34     monkeypatch.setenv(LAUNCHER_ENV, "")35 36     serve_reloading(37         host="127.0.0.1",38         port=9000,39         reload_dirs=["/srv/site", "/srv/packages"],40         reload_excludes=["/srv/site/data/*"],41         config="/srv/site/config.py",42         debug="sql",43     )44 45     assert launched["target"] == FACTORY_TARGET46     assert launched["reload_dirs"] == ["/srv/site", "/srv/packages"]47     assert launched["reload_excludes"] == ["/srv/site/data/*"]48     assert json.loads(os.environ[LAUNCHER_ENV]) == {49         "host": "127.0.0.1",50         "port": 9000,51         "config": "/srv/site/config.py",52         "debug": "sql",53     }54 55 56 def test_exactly_one_source_neither_or_both_is_an_error():57     with pytest.raises(ValueError, match="exactly one"):58         serve_reloading(host="h", port=1, reload_dirs=["/x"])59     with pytest.raises(ValueError, match="exactly one"):60         serve_reloading(61             host="h", port=1, reload_dirs=["/x"], config="/c.py", application="m:App"62         )