From 7b71576ec4190f2a6dab024adc06b72964ccdc4f Mon Sep 17 00:00:00 2001 From: sparklelcm333 Date: Tue, 18 Aug 2026 23:57:27 +0800 Subject: [PATCH] refactor(test): remove unnecessary sys.path setup --- test/test_TCP_client.py | 5 ----- test/test_TCP_server.py | 5 ----- test/test_command_handlers.py | 5 ----- test/test_crypto_rsa.py | 5 +---- test/test_crypto_tcp.py | 8 ++------ test/test_extension_TCP_setup.py | 5 ----- test/test_flow_setup.py | 3 --- test/test_rsa_crypto_errors.py | 8 +++----- test/test_tcp_broadcast_alloc.py | 6 +----- test/test_tcp_file_transfer.py | 6 +----- test/test_udp.py | 5 ----- 11 files changed, 8 insertions(+), 53 deletions(-) diff --git a/test/test_TCP_client.py b/test/test_TCP_client.py index ac71291..8dd7647 100644 --- a/test/test_TCP_client.py +++ b/test/test_TCP_client.py @@ -1,9 +1,4 @@ -import os -import sys -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in os.sys.path: - sys.path.insert(0, package_dictionary) from PyFlow.network_api.connect_tcp import TCP_Client_Base diff --git a/test/test_TCP_server.py b/test/test_TCP_server.py index 977fdf4..b926159 100644 --- a/test/test_TCP_server.py +++ b/test/test_TCP_server.py @@ -1,9 +1,4 @@ -import os -import sys -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in os.sys.path: - sys.path.insert(0, package_dictionary) from PyFlow.network_api.connect_tcp import TCP_Server_Base diff --git a/test/test_command_handlers.py b/test/test_command_handlers.py index 5d41ee0..60fe035 100644 --- a/test/test_command_handlers.py +++ b/test/test_command_handlers.py @@ -1,13 +1,8 @@ -import os -import sys import builtins import io import json from types import SimpleNamespace -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in os.sys.path: - sys.path.insert(0, package_dictionary) import PyFlow.command_control_extension_tcp as ctl diff --git a/test/test_crypto_rsa.py b/test/test_crypto_rsa.py index 54b6ee4..84b9dbc 100644 --- a/test/test_crypto_rsa.py +++ b/test/test_crypto_rsa.py @@ -9,11 +9,8 @@ import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) -from PyFlow.network_api import rsa_crypto # noqa: E402 +from PyFlow.network_api import rsa_crypto try: rsa_crypto.load_library() diff --git a/test/test_crypto_tcp.py b/test/test_crypto_tcp.py index a8aa650..eca7267 100644 --- a/test/test_crypto_tcp.py +++ b/test/test_crypto_tcp.py @@ -9,19 +9,15 @@ import io import os import socket -import sys import threading import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) from test_util import server_ready, wait_until -from PyFlow.network_api import rsa_crypto # noqa: E402 -from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base # noqa: E402 +from PyFlow.network_api import rsa_crypto +from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base try: rsa_crypto.load_library() diff --git a/test/test_extension_TCP_setup.py b/test/test_extension_TCP_setup.py index 432e81d..1fffa29 100644 --- a/test/test_extension_TCP_setup.py +++ b/test/test_extension_TCP_setup.py @@ -1,9 +1,4 @@ -import os -import sys -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in os.sys.path: - sys.path.insert(0, package_dictionary) import PyFlow.command_control_extension_tcp as ctl diff --git a/test/test_flow_setup.py b/test/test_flow_setup.py index 8ff84ee..3e66968 100644 --- a/test/test_flow_setup.py +++ b/test/test_flow_setup.py @@ -8,9 +8,6 @@ import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) import PyFlow.flow_setup as fs diff --git a/test/test_rsa_crypto_errors.py b/test/test_rsa_crypto_errors.py index 59fcb16..9dee6da 100644 --- a/test/test_rsa_crypto_errors.py +++ b/test/test_rsa_crypto_errors.py @@ -7,11 +7,9 @@ import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) +import PyFlow.network_api.rsa_crypto as rc -import PyFlow.network_api.rsa_crypto as rc # noqa: E402 +PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) try: rc.load_library() @@ -55,7 +53,7 @@ def test_load_library_falls_back_to_build_dir(tmp_path, monkeypatch): # find the actual built .so and simulate only it existing import glob - real = glob.glob(os.path.join(package_dictionary, "build", "libcrypto_api.so")) + real = glob.glob(os.path.join(PROJECT_ROOT, "build", "libcrypto_api.so")) if not real: pytest.skip("no built library in repo build/") monkeypatch.setattr( diff --git a/test/test_tcp_broadcast_alloc.py b/test/test_tcp_broadcast_alloc.py index 60e2ab2..632a10e 100644 --- a/test/test_tcp_broadcast_alloc.py +++ b/test/test_tcp_broadcast_alloc.py @@ -2,18 +2,14 @@ client-side manual port-allocation machinery.""" import os -import sys import threading import time from unittest.mock import MagicMock import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) -from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base # noqa: E402 +from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base _PORT = 65410 diff --git a/test/test_tcp_file_transfer.py b/test/test_tcp_file_transfer.py index cfc4b75..420e898 100644 --- a/test/test_tcp_file_transfer.py +++ b/test/test_tcp_file_transfer.py @@ -1,19 +1,15 @@ """End-to-end file-transfer tests (plain channel, no crypto).""" import os -import sys import threading import time import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in sys.path: - sys.path.insert(0, package_dictionary) from test_util import server_ready, wait_until -from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base # noqa: E402 +from PyFlow.network_api.connect_tcp import TCP_Client_Base, TCP_Server_Base _PORT_COUNTER = 65420 diff --git a/test/test_udp.py b/test/test_udp.py index 41c0268..b1277be 100644 --- a/test/test_udp.py +++ b/test/test_udp.py @@ -1,13 +1,8 @@ -import os -import sys import socket import threading import pytest -package_dictionary = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -if package_dictionary not in os.sys.path: - sys.path.insert(0, package_dictionary) from PyFlow.network_api.connect_udp import UDP