From 8ebe7305853548d6126853ba537e4ff0ddeff519 Mon Sep 17 00:00:00 2001 From: Oli Jones Date: Tue, 21 Jul 2026 12:56:54 +0000 Subject: [PATCH 1/3] Remove python 3.14 compatibility --- .github/workflows/ci.yml | 7 +++---- pyproject.toml | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34568d7..4684ed6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,11 +5,10 @@ on: branches: - main tags: - - '*' + - "*" pull_request: jobs: - lint: uses: ./.github/workflows/_tox.yml with: @@ -19,7 +18,7 @@ jobs: strategy: matrix: runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest - python-version: ["3.11", "3.12", "3.13", "3.14"] + python-version: ["3.11", "3.12", "3.13"] fail-fast: false uses: ./.github/workflows/_test.yml with: @@ -47,7 +46,7 @@ jobs: dist: uses: ./.github/workflows/_dist.yml - + release: needs: [dist, test] if: github.ref_type == 'tag' diff --git a/pyproject.toml b/pyproject.toml index 7a43209..ae232f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,6 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "Programming Language :: Python :: 3.14", ] description = "EPICS driver for the OceanOptics flame mini spectrometer" dependencies = [ From b7e4655aa1b35e89374ee6c23e991344769a2fbc Mon Sep 17 00:00:00 2001 From: Oli Jones Date: Tue, 21 Jul 2026 12:57:34 +0000 Subject: [PATCH 2/3] Add other possible exceptions to bad socket --- tests/spectrometer_telecommunicator_test.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/spectrometer_telecommunicator_test.py b/tests/spectrometer_telecommunicator_test.py index 6490fb3..bcfc62b 100644 --- a/tests/spectrometer_telecommunicator_test.py +++ b/tests/spectrometer_telecommunicator_test.py @@ -66,11 +66,14 @@ async def test_bad_socket(): spec_tel_object = SpecTel("127.0.0.1", 7016) - with pytest.raises(ConnectionRefusedError): - await spec_tel_object.connect() - - if spec_tel_object.socket_obj is not None: - spec_tel_object.socket_obj.close() + try: + # Can raise either of these exceptions?? + # Doesnt seem to act deterministically + with pytest.raises((ConnectionRefusedError, ConnectionResetError)): + await spec_tel_object.connect() + finally: + if spec_tel_object.socket_obj is not None: + spec_tel_object.socket_obj.close() @pytest.mark.asyncio From 7e38e16bd26cb42f8ed94b99e88913aaf6aab5b6 Mon Sep 17 00:00:00 2001 From: Oli Jones Date: Tue, 21 Jul 2026 13:20:56 +0000 Subject: [PATCH 3/3] Add method to close non blocking sockets --- tests/spectrometer_telecommunicator_test.py | 61 ++++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/tests/spectrometer_telecommunicator_test.py b/tests/spectrometer_telecommunicator_test.py index bcfc62b..fa8f2fe 100644 --- a/tests/spectrometer_telecommunicator_test.py +++ b/tests/spectrometer_telecommunicator_test.py @@ -51,8 +51,25 @@ async def spec_tel_coroutine(): try: yield spec_tel_object finally: - if spec_tel_object.socket_obj is not None: - spec_tel_object.socket_obj.close() + await close_non_blocking_socket(spec_tel_object.socket_obj) + + +async def close_non_blocking_socket(socket_obj: socket | None): + """ + Makes sure non blocking sockets close properly + + Improperly closed sockets can lead to future tests failing as the port they tried + to bind to is already in use (by the previous, finished test) + """ + if socket_obj is None: + return + socket_obj.close() + # This method is quite crude but it seems to have a high success rate + # Ideally you would run recv from the socket until a b'' is recieved + # This would also require a timeout incase nothing is ever recieved + # And im not sure what you would even do in this case when you already + # tried to close it?? + await asyncio.sleep(0.5) @pytest.mark.asyncio @@ -72,8 +89,7 @@ async def test_bad_socket(): with pytest.raises((ConnectionRefusedError, ConnectionResetError)): await spec_tel_object.connect() finally: - if spec_tel_object.socket_obj is not None: - spec_tel_object.socket_obj.close() + await close_non_blocking_socket(spec_tel_object.socket_obj) @pytest.mark.asyncio @@ -91,25 +107,28 @@ async def test_bad_initial_connection_message(): await asyncio.sleep(1) spec_tel_object = SpecTel("127.0.0.1", 7016) - with pytest.raises(UnexpectedResponseError): - await spec_tel_object.connect() - if spec_tel_object.socket_obj is not None: - spec_tel_object.socket_obj.close() + try: + with pytest.raises(UnexpectedResponseError): + await spec_tel_object.connect() + finally: + await close_non_blocking_socket(spec_tel_object.socket_obj) @pytest.mark.asyncio async def test_device_already_connected(): async with spec_tel_coroutine() as spec_tel_object: socket_obj = socket() - socket_obj.connect(("127.0.0.1", 7016)) - socket_obj.setblocking(False) + try: + socket_obj.connect(("127.0.0.1", 7016)) + socket_obj.setblocking(False) - loop = asyncio.get_event_loop() - await loop.sock_recv(socket_obj, 1024) + loop = asyncio.get_event_loop() + await loop.sock_recv(socket_obj, 1024) - with pytest.raises(TimeoutError): - await spec_tel_object.connect() - socket_obj.close() + with pytest.raises(TimeoutError): + await spec_tel_object.connect() + finally: + await close_non_blocking_socket(socket_obj) @pytest.mark.asyncio @@ -134,13 +153,13 @@ async def test_invalid_response(): await asyncio.sleep(1) spec_tel_object = SpecTel("127.0.0.1", 7016) - await spec_tel_object.connect() - - with pytest.raises(UnexpectedResponseError): - await spec_tel_object.get_version() + try: + await spec_tel_object.connect() - if spec_tel_object.socket_obj is not None: - spec_tel_object.socket_obj.close() + with pytest.raises(UnexpectedResponseError): + await spec_tel_object.get_version() + finally: + await close_non_blocking_socket(spec_tel_object.socket_obj) @pytest.mark.asyncio