From 00776d6c28d184a59ee0a5ac8b292bf1e97074ca Mon Sep 17 00:00:00 2001 From: bsrdjan Date: Mon, 8 Jan 2024 15:30:08 +0100 Subject: [PATCH] refactor(tests): ruff formatting fixed --- tests/config.py | 2 +- tests/test_client_config.py | 5 +---- tests/test_connection.py | 2 +- tests/test_datatypes.py | 8 ++++---- tests/test_errors_abap.py | 7 +++++-- tests/test_package.py | 8 ++------ tests/test_server.py | 15 +++++++-------- tests/test_timeout.py | 10 +++++++++- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/tests/config.py b/tests/config.py index 3788880..776edda 100755 --- a/tests/config.py +++ b/tests/config.py @@ -88,7 +88,7 @@ def python_to_ABAP_time(py_time): "darwin": "/Applications/Secure Login Client.app/Contents/MacOS/lib/libsapcrypto.dylib", "linux": "/usr/local/sap/cryptolib/libsapcrypto.so", "win32": "C:\\Tools\\cryptolib\\sapcrypto.dll", - "windows": "C:\\Tools\\cryptolib\\sapcrypto.dll" + "windows": "C:\\Tools\\cryptolib\\sapcrypto.dll", # "C:\\Program Files\\SAP\\FrontEnd\\SecureLogin\\libsapcrypto.dll" }[PLATFORM] diff --git a/tests/test_client_config.py b/tests/test_client_config.py index 1e7a0f5..a092410 100755 --- a/tests/test_client_config.py +++ b/tests/test_client_config.py @@ -116,10 +116,7 @@ def test_config_not_supported(self): **config_sections["coevi51"], ) error = ex.value - assert ( - error.args[0] == "Connection configuration option 'xtimeout'" - " is not supported" - ) + assert error.args[0] == "Connection configuration option 'xtimeout' is not supported" def test_config_parameter(self): conn = Connection( diff --git a/tests/test_connection.py b/tests/test_connection.py index e8b1ff6..10b1a03 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -79,7 +79,7 @@ def test_connection_info(self): "progName", "partnerBytesPerChar", "partnerIP", - "partnerIPv6" + "partnerIPv6", # 'reserved' ) assert all(attr in connection_info for attr in info_keys) diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index b5f89c3..d2ab226 100755 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic +# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic # # SPDX-License-Identifier: Apache-2.0 @@ -469,6 +469,7 @@ def test_date_time(): assert error.args[4] == "RFCTIME" assert error.args[5] == "IMPORTSTRUCT" + def test_date_time_no_check(): conn = Connection(config={"check_date": False, "check_time": False}, **CONNECTION_INFO) DATETIME_TEST = [ @@ -492,8 +493,8 @@ def test_date_time_no_check(): {"RFCDATE": "20161231", "RFCTIME": 123456}, # wrong time type ] for index, dt in enumerate(DATETIME_TEST): - print(index, dt) - if index not in (11,17): + # print(index, dt) + if index not in (11, 17): res = conn.call("STFC_STRUCTURE", IMPORTSTRUCT=dt)["ECHOSTRUCT"] assert dt["RFCDATE"][:8] in res["RFCDATE"] if dt["RFCTIME"] == "": @@ -517,7 +518,6 @@ def test_date_time_no_check(): assert error.args[5] == "IMPORTSTRUCT" - def test_date_accepts_string(): TEST_DATE = "20180625" IMPORTSTRUCT = {"RFCDATE": TEST_DATE} diff --git a/tests/test_errors_abap.py b/tests/test_errors_abap.py index 1985bc3..788a184 100755 --- a/tests/test_errors_abap.py +++ b/tests/test_errors_abap.py @@ -6,6 +6,8 @@ from pyrfc import ABAPApplicationError, ABAPRuntimeError, Connection, RFCError from tests.config import PARAMS as params + + class TestErrorsABAP: def setup_method(self): self.conn = Connection(**params) @@ -35,6 +37,7 @@ def test_RFC_RAISE_ERROR(self): assert error.msg_class == "SR" assert error.msg_type == "A" assert error.msg_number == "006" + def test_STFC_SAPGUI(self): # STFC_SAPGUI RFC-TEST: RFC with SAPGUI with pytest.raises(ABAPRuntimeError) as ex: @@ -119,7 +122,7 @@ def test_AbapRuntimeError_A(self): assert error.msg_class == "SR" assert error.msg_type == "A" assert error.msg_number == "006" - assert error.msg_v1 == "STRING" + # assert error.msg_v1 == "STRING" assert error.message == "Function not supported" def test_AbapRuntimeError_X(self): @@ -136,7 +139,7 @@ def test_AbapRuntimeError_X(self): assert error.msg_class == "SR" assert error.msg_type == "X" assert error.msg_number == "006" - assert error.msg_v1 == "STRING" + # assert error.msg_v1 == "STRING" assert error.message == "The current application has triggered a termination with a short dump." def test_AbapRuntimeError_E36(self): diff --git a/tests/test_package.py b/tests/test_package.py index 77ca594..e54b0d5 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -16,9 +16,7 @@ @pytest.mark.skipif( - "tomllib" not in sys.modules - or "linux" not in sys.platform - or sys.version_info < latest_python_version, + "tomllib" not in sys.modules or "linux" not in sys.platform or sys.version_info < latest_python_version, reason="package check on latest python only", ) class TestPackageContent: @@ -35,9 +33,7 @@ def setup_class(self): def test_wheel_package(self): package_path = join(self.temp_dir, self.package_name) - package_files = [ - fn for fn in listdir(package_path) if isfile(join(package_path, fn)) - ] + package_files = [fn for fn in listdir(package_path) if isfile(join(package_path, fn))] exts = set() # no cython and c sources, only python and 'so' for fn in package_files: diff --git a/tests/test_server.py b/tests/test_server.py index 9419013..73e1bab 100755 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -43,6 +43,7 @@ def my_stfc_connection(request_context=None, REQUTEXT=""): client = Connection(dest="MME") + @pytest.mark.skipif(not sys.platform.startswith("darwin"), reason="Manual server test on Darwin only") class TestServer: def test_add_wrong_function(self): @@ -84,7 +85,6 @@ def test_function_description_BS01_SALESORDER_GETDETAIL(self): FUNC_DESC_BS01_SALESORDER_GETDETAIL, ) - def test_stfc_structure(self): def my_stfc_structure(request_context=None, IMPORTSTRUCT=None, RFCTABLE=None): """Server function my_stfc_structure with the signature of ABAP function module STFC_STRUCTURE.""" @@ -96,9 +96,9 @@ def my_stfc_structure(request_context=None, IMPORTSTRUCT=None, RFCTABLE=None): if RFCTABLE is None: RFCTABLE = [] ECHOSTRUCT = IMPORTSTRUCT.copy() - ECHOSTRUCT['RFCINT1'] += 1 - ECHOSTRUCT['RFCINT2'] += 1 - ECHOSTRUCT['RFCINT4'] += 1 + ECHOSTRUCT["RFCINT1"] += 1 + ECHOSTRUCT["RFCINT2"] += 1 + ECHOSTRUCT["RFCINT4"] += 1 if len(RFCTABLE) == 0: RFCTABLE = [ECHOSTRUCT] RESPTEXT = f"Python server sends {len(RFCTABLE)} table rows" @@ -108,7 +108,6 @@ def my_stfc_structure(request_context=None, IMPORTSTRUCT=None, RFCTABLE=None): return {"ECHOSTRUCT": ECHOSTRUCT, "RFCTABLE": RFCTABLE, "RESPTEXT": RESPTEXT} - def my_auth_check(func_name=False, request_context=None): """Server authorization check.""" @@ -122,9 +121,7 @@ def my_auth_check(func_name=False, request_context=None): # create server server = Server( - {"dest": "MME_GATEWAY"}, - {"dest": "MME"}, - {"check_date": False, "check_time": False, "server_log": True} + {"dest": "MME_GATEWAY"}, {"dest": "MME"}, {"check_date": False, "check_time": False, "server_log": True} ) # expose python function my_stfc_structure as ABAP function STFC_STRUCTURE, to be called by ABAP system @@ -152,8 +149,10 @@ def my_auth_check(func_name=False, request_context=None): # shutdown server server.close() + # get server attributes print(server.get_server_attributes()) + def teardown(): server.close() diff --git a/tests/test_timeout.py b/tests/test_timeout.py index c2a2e6d..a310105 100755 --- a/tests/test_timeout.py +++ b/tests/test_timeout.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import pytest -from pyrfc import Connection, RFCError +from pyrfc import Connection, RFCError, ExternalRuntimeError from tests.config import CONNECTION_INFO @@ -61,3 +61,11 @@ def test_timeout_connection_override(self): assert "Connection was canceled" in error.args[0] # ensure new connection replaced the canceled one assert client.alive is True + + def test_timeout_with_rfc_error(self): + with pytest.raises(ExternalRuntimeError) as ex: + client.call("STFC_CONNECTION", options={"timeout": 60}, undefined=0) + error = ex.value + assert error.code == 20 + assert error.key == "RFC_INVALID_PARAMETER" + assert error.message == "field 'undefined' not found"