Skip to content

Commit 00776d6

Browse files
committed
refactor(tests): ruff formatting fixed
1 parent 896af4b commit 00776d6

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

tests/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def python_to_ABAP_time(py_time):
8888
"darwin": "/Applications/Secure Login Client.app/Contents/MacOS/lib/libsapcrypto.dylib",
8989
"linux": "/usr/local/sap/cryptolib/libsapcrypto.so",
9090
"win32": "C:\\Tools\\cryptolib\\sapcrypto.dll",
91-
"windows": "C:\\Tools\\cryptolib\\sapcrypto.dll"
91+
"windows": "C:\\Tools\\cryptolib\\sapcrypto.dll",
9292
# "C:\\Program Files\\SAP\\FrontEnd\\SecureLogin\\libsapcrypto.dll"
9393
}[PLATFORM]
9494

tests/test_client_config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ def test_config_not_supported(self):
116116
**config_sections["coevi51"],
117117
)
118118
error = ex.value
119-
assert (
120-
error.args[0] == "Connection configuration option 'xtimeout'"
121-
" is not supported"
122-
)
119+
assert error.args[0] == "Connection configuration option 'xtimeout' is not supported"
123120

124121
def test_config_parameter(self):
125122
conn = Connection(

tests/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_connection_info(self):
7979
"progName",
8080
"partnerBytesPerChar",
8181
"partnerIP",
82-
"partnerIPv6"
82+
"partnerIPv6",
8383
# 'reserved'
8484
)
8585
assert all(attr in connection_info for attr in info_keys)

tests/test_datatypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
1+
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

@@ -469,6 +469,7 @@ def test_date_time():
469469
assert error.args[4] == "RFCTIME"
470470
assert error.args[5] == "IMPORTSTRUCT"
471471

472+
472473
def test_date_time_no_check():
473474
conn = Connection(config={"check_date": False, "check_time": False}, **CONNECTION_INFO)
474475
DATETIME_TEST = [
@@ -492,8 +493,8 @@ def test_date_time_no_check():
492493
{"RFCDATE": "20161231", "RFCTIME": 123456}, # wrong time type
493494
]
494495
for index, dt in enumerate(DATETIME_TEST):
495-
print(index, dt)
496-
if index not in (11,17):
496+
# print(index, dt)
497+
if index not in (11, 17):
497498
res = conn.call("STFC_STRUCTURE", IMPORTSTRUCT=dt)["ECHOSTRUCT"]
498499
assert dt["RFCDATE"][:8] in res["RFCDATE"]
499500
if dt["RFCTIME"] == "":
@@ -517,7 +518,6 @@ def test_date_time_no_check():
517518
assert error.args[5] == "IMPORTSTRUCT"
518519

519520

520-
521521
def test_date_accepts_string():
522522
TEST_DATE = "20180625"
523523
IMPORTSTRUCT = {"RFCDATE": TEST_DATE}

tests/test_errors_abap.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pyrfc import ABAPApplicationError, ABAPRuntimeError, Connection, RFCError
77

88
from tests.config import PARAMS as params
9+
10+
911
class TestErrorsABAP:
1012
def setup_method(self):
1113
self.conn = Connection(**params)
@@ -35,6 +37,7 @@ def test_RFC_RAISE_ERROR(self):
3537
assert error.msg_class == "SR"
3638
assert error.msg_type == "A"
3739
assert error.msg_number == "006"
40+
3841
def test_STFC_SAPGUI(self):
3942
# STFC_SAPGUI RFC-TEST: RFC with SAPGUI
4043
with pytest.raises(ABAPRuntimeError) as ex:
@@ -119,7 +122,7 @@ def test_AbapRuntimeError_A(self):
119122
assert error.msg_class == "SR"
120123
assert error.msg_type == "A"
121124
assert error.msg_number == "006"
122-
assert error.msg_v1 == "STRING"
125+
# assert error.msg_v1 == "STRING"
123126
assert error.message == "Function not supported"
124127

125128
def test_AbapRuntimeError_X(self):
@@ -136,7 +139,7 @@ def test_AbapRuntimeError_X(self):
136139
assert error.msg_class == "SR"
137140
assert error.msg_type == "X"
138141
assert error.msg_number == "006"
139-
assert error.msg_v1 == "STRING"
142+
# assert error.msg_v1 == "STRING"
140143
assert error.message == "The current application has triggered a termination with a short dump."
141144

142145
def test_AbapRuntimeError_E36(self):

tests/test_package.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717

1818
@pytest.mark.skipif(
19-
"tomllib" not in sys.modules
20-
or "linux" not in sys.platform
21-
or sys.version_info < latest_python_version,
19+
"tomllib" not in sys.modules or "linux" not in sys.platform or sys.version_info < latest_python_version,
2220
reason="package check on latest python only",
2321
)
2422
class TestPackageContent:
@@ -35,9 +33,7 @@ def setup_class(self):
3533

3634
def test_wheel_package(self):
3735
package_path = join(self.temp_dir, self.package_name)
38-
package_files = [
39-
fn for fn in listdir(package_path) if isfile(join(package_path, fn))
40-
]
36+
package_files = [fn for fn in listdir(package_path) if isfile(join(package_path, fn))]
4137
exts = set()
4238
# no cython and c sources, only python and 'so'
4339
for fn in package_files:

tests/test_server.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def my_stfc_connection(request_context=None, REQUTEXT=""):
4343

4444
client = Connection(dest="MME")
4545

46+
4647
@pytest.mark.skipif(not sys.platform.startswith("darwin"), reason="Manual server test on Darwin only")
4748
class TestServer:
4849
def test_add_wrong_function(self):
@@ -84,7 +85,6 @@ def test_function_description_BS01_SALESORDER_GETDETAIL(self):
8485
FUNC_DESC_BS01_SALESORDER_GETDETAIL,
8586
)
8687

87-
8888
def test_stfc_structure(self):
8989
def my_stfc_structure(request_context=None, IMPORTSTRUCT=None, RFCTABLE=None):
9090
"""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):
9696
if RFCTABLE is None:
9797
RFCTABLE = []
9898
ECHOSTRUCT = IMPORTSTRUCT.copy()
99-
ECHOSTRUCT['RFCINT1'] += 1
100-
ECHOSTRUCT['RFCINT2'] += 1
101-
ECHOSTRUCT['RFCINT4'] += 1
99+
ECHOSTRUCT["RFCINT1"] += 1
100+
ECHOSTRUCT["RFCINT2"] += 1
101+
ECHOSTRUCT["RFCINT4"] += 1
102102
if len(RFCTABLE) == 0:
103103
RFCTABLE = [ECHOSTRUCT]
104104
RESPTEXT = f"Python server sends {len(RFCTABLE)} table rows"
@@ -108,7 +108,6 @@ def my_stfc_structure(request_context=None, IMPORTSTRUCT=None, RFCTABLE=None):
108108

109109
return {"ECHOSTRUCT": ECHOSTRUCT, "RFCTABLE": RFCTABLE, "RESPTEXT": RESPTEXT}
110110

111-
112111
def my_auth_check(func_name=False, request_context=None):
113112
"""Server authorization check."""
114113

@@ -122,9 +121,7 @@ def my_auth_check(func_name=False, request_context=None):
122121

123122
# create server
124123
server = Server(
125-
{"dest": "MME_GATEWAY"},
126-
{"dest": "MME"},
127-
{"check_date": False, "check_time": False, "server_log": True}
124+
{"dest": "MME_GATEWAY"}, {"dest": "MME"}, {"check_date": False, "check_time": False, "server_log": True}
128125
)
129126

130127
# 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):
152149
# shutdown server
153150
server.close()
154151

152+
155153
# get server attributes
156154
print(server.get_server_attributes())
157155

156+
158157
def teardown():
159158
server.close()

tests/test_timeout.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import pytest
6-
from pyrfc import Connection, RFCError
6+
from pyrfc import Connection, RFCError, ExternalRuntimeError
77

88
from tests.config import CONNECTION_INFO
99

@@ -61,3 +61,11 @@ def test_timeout_connection_override(self):
6161
assert "Connection was canceled" in error.args[0]
6262
# ensure new connection replaced the canceled one
6363
assert client.alive is True
64+
65+
def test_timeout_with_rfc_error(self):
66+
with pytest.raises(ExternalRuntimeError) as ex:
67+
client.call("STFC_CONNECTION", options={"timeout": 60}, undefined=0)
68+
error = ex.value
69+
assert error.code == 20
70+
assert error.key == "RFC_INVALID_PARAMETER"
71+
assert error.message == "field 'undefined' not found"

0 commit comments

Comments
 (0)