Skip to content

Commit

Permalink
refactor(tests): ruff formatting fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Jan 8, 2024
1 parent 896af4b commit 00776d6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
5 changes: 1 addition & 4 deletions tests/test_client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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 = [
Expand All @@ -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"] == "":
Expand All @@ -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}
Expand Down
7 changes: 5 additions & 2 deletions tests/test_errors_abap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand All @@ -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"
Expand All @@ -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."""

Expand All @@ -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
Expand Down Expand Up @@ -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()
10 changes: 9 additions & 1 deletion tests/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"

0 comments on commit 00776d6

Please sign in to comment.