Skip to content

Commit 5511c58

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup
1 parent 9c901fc commit 5511c58

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

src/nipanel/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""The NI Panel."""
2+
23
from nipanel.nipanel import NiPanel
3-
__all__ = ["NiPanel"]
4+
5+
__all__ = ["NiPanel"]

src/nipanel/nipanel.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1+
"""NI Panel."""
2+
13
import uuid
2-
import grpc
3-
from google.protobuf import any_pb2
4-
import ni.pythonpanel.v1.python_panel_service_pb2 as python_panel_service_pb2
5-
import ni.pythonpanel.v1.python_panel_service_pb2_grpc as python_panel_service_pb2_grpc
4+
from types import TracebackType
5+
from typing import Optional, Type
66

77

88
class NiPanel:
9-
"""
10-
This class allows you to access controls on the panel
11-
"""
9+
"""This class allows you to access controls on the panel."""
1210

13-
def __init__(self):
11+
def __init__(self) -> None:
12+
"""Initialize the NiPanel instance."""
1413
self._stub = None # will be a PythonPanelServiceStub
15-
self.panel_uri = None
16-
self.panel_id = None
14+
self.panel_uri = ""
15+
self.panel_id = ""
1716

18-
def __enter__(self):
17+
def __enter__(self) -> "NiPanel":
18+
"""Enter the runtime context related to this object."""
1919
self.connect()
2020
return self
2121

22-
def __exit__(self, exc_type, exc_value, exc_traceback):
22+
def __exit__(
23+
self,
24+
exctype: Optional[Type[BaseException]],
25+
excinst: Optional[BaseException],
26+
exctb: Optional[TracebackType],
27+
) -> Optional[bool]:
28+
"""Exit the runtime context related to this object."""
2329
self.disconnect()
30+
return None
2431

2532
@classmethod
26-
def streamlit_panel(cls, streamlit_script_path: str):
27-
"""
28-
Create a panel using a streamlit script for the user interface
33+
def streamlit_panel(cls, streamlit_script_path: str) -> "NiPanel":
34+
"""Create a panel using a streamlit script for the user interface.
2935
3036
Args:
3137
streamlit_script_path: The file path of the streamlit script
@@ -38,36 +44,30 @@ def streamlit_panel(cls, streamlit_script_path: str):
3844
panel.panel_id = str(uuid.uuid4())
3945
return panel
4046

41-
def connect(self):
42-
"""
43-
Connect to the panel and open it.
44-
"""
45-
# TODO: AB#3095680 - Use gRPC pool management from the Measurement Plugin SDK, create the _stub, and call _stub.Connect
47+
def connect(self) -> None:
48+
"""Connect to the panel and open it."""
49+
# TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect
4650
pass
4751

48-
def disconnect(self):
49-
"""
50-
Disconnect from the panel (does not close the panel).
51-
"""
52-
# TODO: AB#3095680 - Use gRPC pool management from the Measurement Plugin SDK, call _stub.Disconnect
52+
def disconnect(self) -> None:
53+
"""Disconnect from the panel (does not close the panel)."""
54+
# TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect
5355
pass
5456

55-
def get_value(self, value_id: str):
56-
"""
57-
Get the value for a control on the panel
57+
def get_value(self, value_id: str) -> object:
58+
"""Get the value for a control on the panel.
5859
5960
Args:
6061
value_id: The id of the value
6162
6263
Returns:
6364
object: The value
6465
"""
65-
# TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type to return it
66+
# TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
6667
return "placeholder value"
6768

68-
def set_value(self, value_id: str, value):
69-
"""
70-
Set the value for a control on the panel
69+
def set_value(self, value_id: str, value: object) -> None:
70+
"""Set the value for a control on the panel.
7171
7272
Args:
7373
value_id: The id of the value

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Tests for the `nipanel` package."""
1+
"""Tests for the `nipanel` package."""

tests/unit/test_nipanel.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from nipanel import NiPanel
22

3+
34
def test_streamlit_panel() -> None:
45
panel = NiPanel.streamlit_panel("path/to/script")
56
assert panel.panel_uri == "path/to/script"
67
assert panel.panel_id is not None
7-
panel.connect() # not implemented, but should not raise an error
8-
panel.set_value("test_id", "test_value") # not implemented, but should not raise an error
9-
assert panel.get_value("test_id") == "placeholder value" # not implemented, but should not raise an error
10-
panel.disconnect() # not implemented, but should not raise an error
8+
panel.connect()
9+
panel.set_value("test_id", "test_value")
10+
assert panel.get_value("test_id") == "placeholder value"
11+
panel.disconnect()
12+
1113

1214
def test_with_streamlit_panel() -> None:
1315
with NiPanel.streamlit_panel("path/to/script") as panel:
1416
assert panel.panel_uri == "path/to/script"
1517
assert panel.panel_id is not None
16-
panel.set_value("test_id", "test_value") # not implemented, but should not raise an error
17-
assert panel.get_value("test_id") == "placeholder value" # not implemented, but should not raise an error
18+
panel.set_value("test_id", "test_value")
19+
assert panel.get_value("test_id") == "placeholder value"

0 commit comments

Comments
 (0)