Skip to content

Commit a7e4914

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup
1 parent bb5ea94 commit a7e4914

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/nipanel/_panel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __exit__(
6060
def connect(self) -> None:
6161
"""Connect to the panel and open it."""
6262
# TODO: use the channel pool
63-
channel = insecure_channel(self._get_channel_url())
63+
channel = insecure_channel(self._resolve_service_address())
6464
self._stub = PythonPanelServiceStub(channel)
6565
connect_request = ConnectRequest(panel_id=self._panel_id, panel_uri=self._panel_uri)
6666

@@ -113,6 +113,6 @@ def set_value(self, value_id: str, value: object) -> None:
113113
pass
114114

115115
@abstractmethod
116-
def _get_channel_url(self) -> str:
116+
def _resolve_service_address(self) -> str:
117117
"""Resolve the service location for the panel."""
118118
raise NotImplementedError

src/nipanel/_streamlit_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, panel_id: str, streamlit_script_uri: str) -> None:
2121
"""
2222
super().__init__(panel_id, streamlit_script_uri)
2323

24-
def _get_channel_url(self) -> str:
24+
def _resolve_service_address(self) -> str:
2525
with GrpcChannelPool() as grpc_channel_pool:
2626
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
2727
service_location = discovery_client.resolve_service(

tests/unit/test_fake_python_panel_servicer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
def test___connect___gets_response(fake_python_panel_service_stub: PythonPanelServiceStub) -> None:
1212
request = ConnectRequest(panel_id="test_panel", panel_uri="path/to/panel")
1313
response = fake_python_panel_service_stub.Connect(request)
14+
1415
assert response is not None # Ensure response is returned
1516

1617

@@ -19,6 +20,7 @@ def test___disconnect___gets_response(
1920
) -> None:
2021
request = DisconnectRequest(panel_id="test_panel")
2122
response = fake_python_panel_service_stub.Disconnect(request)
23+
2224
assert response is not None # Ensure response is returned
2325

2426

@@ -27,15 +29,16 @@ def test___get_value___gets_response(
2729
) -> None:
2830
request = GetValueRequest(panel_id="test_panel", value_id="test_value")
2931
response = fake_python_panel_service_stub.GetValue(request)
32+
3033
assert response is not None # Ensure response is returned
3134
assert isinstance(response.value, Any) # Ensure the value is of type `Any`
3235

3336

3437
def test___set_value___gets_response(
3538
fake_python_panel_service_stub: PythonPanelServiceStub,
3639
) -> None:
37-
value = Any()
38-
value.value = b"test_data"
39-
request = SetValueRequest(panel_id="test_panel", value_id="test_value", value=value)
40+
test_value = Any(value=b"test_data")
41+
request = SetValueRequest(panel_id="test_panel", value_id="test_value", value=test_value)
4042
response = fake_python_panel_service_stub.SetValue(request)
43+
4144
assert response is not None # Ensure response is returned

tests/unit/test_panel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import grpc
22

3-
from tests.utils._fake_panel import FakePanel
3+
from tests.utils._port_panel import PortPanel
44

55

66
def test___panel___has_panel_id_and_panel_uri() -> None:
7-
panel = FakePanel(0, "my_panel", "path/to/script")
7+
panel = PortPanel(0, "my_panel", "path/to/script")
88
assert panel.panel_id == "my_panel"
99
assert panel.panel_uri == "path/to/script"
1010

@@ -13,7 +13,7 @@ def test___connected_panel___set_value___gets_same_value(
1313
fake_python_panel_service: tuple[grpc.Server, int],
1414
) -> None:
1515
_, port = fake_python_panel_service
16-
panel = FakePanel(port, "my_panel", "path/to/script")
16+
panel = PortPanel(port, "my_panel", "path/to/script")
1717
panel.connect()
1818

1919
panel.set_value("test_id", "test_value")
@@ -27,7 +27,7 @@ def test___with_panel___set_value___gets_same_value(
2727
fake_python_panel_service: tuple[grpc.Server, int],
2828
) -> None:
2929
_, port = fake_python_panel_service
30-
with FakePanel(port, "my_panel", "path/to/script") as panel:
30+
with PortPanel(port, "my_panel", "path/to/script") as panel:
3131
panel.set_value("test_id", "test_value")
3232

3333
# TODO: AB#3095681 - change asserted value to test_value
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from nipanel._panel import Panel
22

33

4-
class FakePanel(Panel):
5-
"""This class allows you to connect to the FakePythonPanelService, for testing."""
4+
class PortPanel(Panel):
5+
"""This class allows you to connect to the PythonPanelService with a specified port, for testing."""
66

77
def __init__(self, port: int, panel_id: str, panel_uri: str) -> None:
8-
"""Create a fake panel, for testing.
8+
"""Create a panel and connect to a specified port, for testing.
99
1010
Args:
1111
port: The port number for the gRPC server.
@@ -18,5 +18,5 @@ def __init__(self, port: int, panel_id: str, panel_uri: str) -> None:
1818
super().__init__(panel_id, panel_uri)
1919
self.port = port
2020

21-
def _get_channel_url(self) -> str:
21+
def _resolve_service_address(self) -> str:
2222
return f"localhost:{self.port}"

0 commit comments

Comments
 (0)