Skip to content

Commit 9c901fc

Browse files
Mike ProsserMike Prosser
authored andcommitted
add basic tests
1 parent 4634cbc commit 9c901fc

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

src/nipanel/__init__.py

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

src/nipanel/nipanel.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
import ni.pythonpanel.v1.python_panel_service_pb2 as python_panel_service_pb2
55
import ni.pythonpanel.v1.python_panel_service_pb2_grpc as python_panel_service_pb2_grpc
66

7+
78
class NiPanel:
89
"""
910
This class allows you to access controls on the panel
1011
"""
12+
1113
def __init__(self):
12-
self._stub = None # will be a PythonPanelServiceStub
14+
self._stub = None # will be a PythonPanelServiceStub
1315
self.panel_uri = None
1416
self.panel_id = None
1517

1618
def __enter__(self):
1719
self.connect()
20+
return self
1821

19-
def __exit__(self):
22+
def __exit__(self, exc_type, exc_value, exc_traceback):
2023
self.disconnect()
2124

2225
@classmethod
@@ -35,10 +38,10 @@ def streamlit_panel(cls, streamlit_script_path: str):
3538
panel.panel_id = str(uuid.uuid4())
3639
return panel
3740

38-
def connect(self):
41+
def connect(self):
3942
"""
4043
Connect to the panel and open it.
41-
"""
44+
"""
4245
# TODO: AB#3095680 - Use gRPC pool management from the Measurement Plugin SDK, create the _stub, and call _stub.Connect
4346
pass
4447

@@ -71,4 +74,4 @@ def set_value(self, value_id: str, value):
7174
value: The value
7275
"""
7376
# TODO: AB#3095681 - Convert the value to an Any and pass it to _stub.SetValue
74-
pass
77+
pass

tests/__init__.py

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

tests/unit/test_nipanel.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from nipanel import NiPanel
2+
3+
def test_streamlit_panel() -> None:
4+
panel = NiPanel.streamlit_panel("path/to/script")
5+
assert panel.panel_uri == "path/to/script"
6+
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
11+
12+
def test_with_streamlit_panel() -> None:
13+
with NiPanel.streamlit_panel("path/to/script") as panel:
14+
assert panel.panel_uri == "path/to/script"
15+
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

tests/unit/test_placeholder.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)