Skip to content

Commit 0211ab0

Browse files
committed
Add back docstrings
1 parent 4113e8a commit 0211ab0

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

tests/launcher/integration/simple_test_launcher.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Simple launcher for testing module."""
2223

2324
import dataclasses
2425
import pathlib
@@ -40,6 +41,8 @@
4041

4142
@dataclasses.dataclass
4243
class SimpleLauncherConfig:
44+
"""Configuration for the SimpleLauncher."""
45+
4346
script_path: str = dataclasses.field(
4447
default=str(SCRIPT_PATH),
4548
metadata={METADATA_KEY_DOC: "Location of the server Python script."},
@@ -50,10 +53,13 @@ class SimpleLauncherConfig:
5053

5154

5255
class SimpleLauncher(LauncherProtocol[SimpleLauncherConfig]):
56+
"""Simple launcher for testing."""
57+
5358
CONFIG_MODEL = SimpleLauncherConfig
5459
SERVER_SPEC = {SERVER_KEY: ServerType.GRPC}
5560

5661
def __init__(self, *, config: SimpleLauncherConfig):
62+
"""Initialize the SimpleLauncher with the given configuration."""
5763
self._script_path = config.script_path
5864
self._transport_options = config.transport_options
5965
if self._transport_options.mode != "uds":
@@ -69,6 +75,7 @@ def __init__(self, *, config: SimpleLauncherConfig):
6975
self._url = f"unix:{self._uds_file}"
7076

7177
def start(self):
78+
"""Start the service."""
7279
self._process = subprocess.Popen(
7380
[
7481
sys.executable,
@@ -81,6 +88,7 @@ def start(self):
8188
)
8289

8390
def stop(self, *, timeout=None):
91+
"""Stop the service."""
8492
self._process.terminate()
8593
try:
8694
self._process.wait(timeout=timeout)
@@ -92,9 +100,11 @@ def stop(self, *, timeout=None):
92100
self._uds_file.unlink(missing_ok=True)
93101

94102
def check(self, *, timeout: float | None = None) -> bool:
95-
channel = self._transport_options.create_channel()
103+
"""Check if the server is responding to requests."""
104+
channel = grpc.insecure_channel(self.urls[SERVER_KEY])
96105
return check_grpc_health(channel, timeout=timeout)
97106

98107
@property
99-
def transport_options(self):
100-
return {SERVER_KEY: self._transport_options}
108+
def urls(self):
109+
"""Return the URLs of the server."""
110+
return {SERVER_KEY: self._url}

tests/launcher/integration/simple_test_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
def main(uds_dir: str):
32+
"""Run the simple test server."""
3233
uds_file = pathlib.Path(uds_dir) / "simple_test_service.sock"
3334
if uds_file.exists():
3435
print(f"UDS file {uds_file} already exists.")

tests/launcher/integration/test_simple_launcher.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ class OtherConfig:
4040

4141
@pytest.fixture(autouse=True)
4242
def monkeypatch_entrypoints(monkeypatch_entrypoints_from_plugins):
43+
"""Mock the entry points for the launcher plugins."""
4344
monkeypatch_entrypoints_from_plugins({PRODUCT_NAME: {"direct": SimpleLauncher}})
4445

4546

4647
def check_uds_file_removed(server):
48+
"""Check that the UDS file has been removed after stopping the server."""
4749
uds_file = pathlib.Path(server._launcher.transport_options["main"].uds_dir) / "simple_test_service.sock"
4850
assert not pathlib.Path(uds_file).exists()
4951

5052

5153
def test_default_config():
54+
"""Test the default configuration."""
5255
config.set_config_for(product_name=PRODUCT_NAME, launch_mode=LAUNCH_MODE, config=SimpleLauncherConfig())
5356
server = launch_product(PRODUCT_NAME)
5457
server.wait(timeout=10)
@@ -58,6 +61,7 @@ def test_default_config():
5861

5962

6063
def test_explicit_config():
64+
"""Test that the server can be launched with an explicit configuration."""
6165
server = launch_product(PRODUCT_NAME, launch_mode=LAUNCH_MODE, config=SimpleLauncherConfig())
6266
server.wait(timeout=10)
6367
server.stop()
@@ -66,6 +70,7 @@ def test_explicit_config():
6670

6771

6872
def test_stop_with_timeout():
73+
"""Test that the server can be stopped with a timeout and that it stops correctly."""
6974
server = launch_product(PRODUCT_NAME, launch_mode=LAUNCH_MODE, config=SimpleLauncherConfig())
7075
server.wait(timeout=10)
7176
server.stop(timeout=1.0)
@@ -74,16 +79,19 @@ def test_stop_with_timeout():
7479

7580

7681
def test_invalid_launch_mode_raises():
82+
"""Test that passing an invalid launch mode raises a KeyError."""
7783
with pytest.raises(KeyError):
7884
launch_product(PRODUCT_NAME, launch_mode="invalid_launch_mode", config=SimpleLauncherConfig())
7985

8086

8187
def test_invalid_config_raises():
88+
"""Test that passing an invalid configuration type raises a TypeError."""
8289
with pytest.raises(TypeError):
8390
launch_product(PRODUCT_NAME, launch_mode=LAUNCH_MODE, config=OtherConfig(int_attr=3))
8491

8592

8693
def test_contextmanager():
94+
"""Test that the context manager works correctly, starting and stopping the server."""
8795
with launch_product(PRODUCT_NAME, launch_mode=LAUNCH_MODE, config=SimpleLauncherConfig()) as server:
8896
server.wait(timeout=10)
8997
assert server.check()

0 commit comments

Comments
 (0)