Skip to content

Commit

Permalink
Merge branch 'master' into asphalt5
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 30, 2024
2 parents 6f69a63 + 1cfcf5a commit 033bdde
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions tests/test_component.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
from __future__ import annotations

import logging
import os
from typing import Any
from typing import Any, ClassVar

import pytest
from asphalt.core import Context, get_resource_nowait, start_component
from py4j.java_gateway import CallbackServerParameters, GatewayParameters, JavaGateway
from pytest import LogCaptureFixture

import asphalt.py4j
from asphalt.py4j import Py4JComponent

pytestmark = pytest.mark.anyio

@pytest.mark.anyio
@pytest.mark.parametrize(
"kwargs, resource_name",
[
pytest.param({}, "default", id="default"),
pytest.param({"resource_name": "alt"}, "alt", id="alternate"),
],
)
async def test_default_gateway(
kwargs: dict[str, Any], resource_name: str, caplog: LogCaptureFixture
) -> None:

async def test_default_gateway() -> None:
"""Test that the default gateway is started and is available on the context."""
caplog.set_level(logging.INFO, logger="asphalt.py4j")
async with Context():
await start_component(Py4JComponent, kwargs)
get_resource_nowait(JavaGateway, resource_name)

assert len(caplog.messages) == 2
assert caplog.messages[0].startswith(
f"Configured Py4J gateway ({resource_name}; address=127.0.0.1, port="
)
assert caplog.messages[1] == f"Py4J gateway ({resource_name}) shut down"
await start_component(Py4JComponent)
get_resource_nowait(JavaGateway)


def test_bad_classpath_entry() -> None:
Expand Down Expand Up @@ -85,7 +68,6 @@ def test_classpath_pkgname_substitution() -> None:
assert component.classpath.endswith(os.path.join("asphalt", "py4j", "javadir", "*"))


@pytest.mark.anyio
async def test_callback_server() -> None:
"""
Test that the gateway's callback server works when enabled in the configuration.
Expand All @@ -96,7 +78,7 @@ def call(self) -> int:
return 7

class Java:
implements = ["java.util.concurrent.Callable"]
implements: ClassVar[list[str]] = ["java.util.concurrent.Callable"]

async with Context():
await start_component(Py4JComponent, {"callback_server": True})
Expand All @@ -109,7 +91,6 @@ class Java:
executor.shutdown()


@pytest.mark.anyio
async def test_gateway_close() -> None:
"""
Test that shutting down the context does not shut down the Java side gateway if
Expand Down

0 comments on commit 033bdde

Please sign in to comment.