summaryrefslogtreecommitdiffstats
path: root/lab_control
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-05-24 15:24:17 +0200
committerEddy Pedroni <eddy@0xf7.com>2022-05-24 15:24:17 +0200
commitebdd519399029eec99d6cf4401d28076a43d017b (patch)
tree728c5a574ef270c3a6501b9798dafe3db40edf0a /lab_control
parent47873fc9a211f0f74e7f3f312abdf6f21c7b2f91 (diff)
Added mock socket, initial SDS1000XE tests
Diffstat (limited to 'lab_control')
-rw-r--r--lab_control/sds1000xe.py6
-rw-r--r--lab_control/test/mocksocket.py11
-rw-r--r--lab_control/test/sds1000xe_test.py34
3 files changed, 51 insertions, 0 deletions
diff --git a/lab_control/sds1000xe.py b/lab_control/sds1000xe.py
new file mode 100644
index 0000000..0ad996f
--- /dev/null
+++ b/lab_control/sds1000xe.py
@@ -0,0 +1,6 @@
+import socket
+
+class SDS1000XE:
+ def __init__(self, ip, port=5025, socket=socket.socket()):
+ self.socket = socket
+ self.socket.connect((ip, port))
diff --git a/lab_control/test/mocksocket.py b/lab_control/test/mocksocket.py
new file mode 100644
index 0000000..7352846
--- /dev/null
+++ b/lab_control/test/mocksocket.py
@@ -0,0 +1,11 @@
+class MockSocket:
+ def __init__(self):
+ self.connected = False
+ self.ip = None
+ self.port = None
+
+ def connect(self, address: tuple[str, int]) -> None:
+ self.connected = True
+ self.ip = address[0]
+ self.port = address[1]
+
diff --git a/lab_control/test/sds1000xe_test.py b/lab_control/test/sds1000xe_test.py
new file mode 100644
index 0000000..1bc1888
--- /dev/null
+++ b/lab_control/test/sds1000xe_test.py
@@ -0,0 +1,34 @@
+import pytest
+
+from lab_control.sds1000xe import SDS1000XE
+from lab_control.test.mocksocket import MockSocket
+
+testIP = "127.0.0.1"
+testPort = 4000
+defaultPort = 5025
+
+@pytest.fixture
+def mockSocket():
+ return MockSocket()
+
+@pytest.fixture
+def uut(mockSocket):
+ return SDS1000XE(testIP, port=testPort, socket=mockSocket)
+
+def test_defaults():
+ mockSocket = MockSocket()
+ assert not mockSocket.connected
+ assert mockSocket.ip == None
+ assert mockSocket.port == None
+
+ uut = SDS1000XE(testIP, socket=mockSocket)
+ assert mockSocket.connected
+ assert mockSocket.ip == testIP
+ assert mockSocket.port == defaultPort
+
+def test_differentPort(uut, mockSocket):
+ assert mockSocket.connected
+ assert mockSocket.ip == testIP
+ assert mockSocket.port == testPort
+
+