From ebdd519399029eec99d6cf4401d28076a43d017b Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 24 May 2022 15:24:17 +0200 Subject: Added mock socket, initial SDS1000XE tests --- lab_control/sds1000xe.py | 6 ++++++ lab_control/test/mocksocket.py | 11 +++++++++++ lab_control/test/sds1000xe_test.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lab_control/sds1000xe.py create mode 100644 lab_control/test/mocksocket.py create mode 100644 lab_control/test/sds1000xe_test.py 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 + + -- cgit v1.2.3