Skip to content

Commit bcaed0f

Browse files
committed
tests for in out procedures
found breaking issue, can not call SYS subprograms
1 parent 6532415 commit bcaed0f

6 files changed

Lines changed: 489 additions & 6 deletions

File tree

‎python_plsql/client.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ def _in_converter(value):
358358
var.setelement(key, convert(object_type.elementType, val))
359359
else:
360360
for attribute, val in zip(object_type.attributes, value):
361-
# todo: self made change to ObjectAttr.c (cx_Oracle should implement this)
362-
# type is not accessible by default..
361+
# todo: self made change to ObjectAttr.c (best case implemented in cx_Oracle)
362+
# attribute.type is not accessible by default..
363363
setattr(var, attribute.name, convert(attribute.type, val))
364364

365365
return var
@@ -368,7 +368,7 @@ def _in_converter(value):
368368

369369

370370
def is_list(object_type: oracle.ObjectType) -> bool:
371-
# todo: should ask cx_Oracle if there is a better way
371+
# todo: find better way
372372
obj = object_type.newobject()
373373
try:
374374
obj.trim(1)
@@ -564,7 +564,7 @@ def _call_procedure(self, match: Overload, cursor, positional, named):
564564
cursor.callproc(self.resolved.name, positional, named)
565565

566566
def __call__(self, *args, **kwargs):
567-
if self.overloaded and self.is_function and self.is_procedure:
567+
if self.is_overloaded and self.is_function and self.is_procedure:
568568
raise NotImplementedError(
569569
"Subprogram is overloaded as a function and procedure, use _call_procedure or _call_function methods"
570570
)
@@ -575,7 +575,7 @@ def __call__(self, *args, **kwargs):
575575
return self._call_procedure(*args, **kwargs)
576576

577577
@property
578-
def overloaded(self) -> bool:
578+
def is_overloaded(self) -> bool:
579579
return len(self.overloads) > 1
580580

581581
@property

‎tests/func/test_in_out_param.py‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import pytest
2+
import datetime
3+
4+
IN_RECORD = (42, 84, 126)
5+
IN_VARRAY = list(range(10, 0, -1))
6+
IN_NESTED = [i * 2 for i in range(1, 11)]
7+
IN_PLSQL_TABLE = {i: i for i in range(1, 11)}
8+
9+
OUT_RECORD = (42, 84, 126)
10+
OUT_VARRAY = list(range(10, 0, -1))
11+
OUT_NESTED = [i * 2 for i in range(1, 11)]
12+
OUT_PLSQL_TABLE = {i: i for i in range(1, 11)}
13+
14+
15+
@pytest.mark.parametrize(
16+
"func, in_value, out_value",
17+
[
18+
("io_varchar2", "42", "42"),
19+
("io_varchar", "42", "42"),
20+
("io_string", "42", "42"),
21+
("io_number", 42.42, 42.42),
22+
("io_integer", 42.0, 42.0),
23+
("io_smallint", 42.0, 42.0),
24+
("io_real", 42.42, 42.42),
25+
("io_float", 42.42, 42.42),
26+
("io_numeric", 42.0, 42.0),
27+
("io_decimal", 42.0, 42.0),
28+
("io_binary_integer", 42, 42),
29+
("io_pls_integer", 42, 42),
30+
("io_positive", 42, 42),
31+
("io_natural", 42, 42),
32+
("io_clob", "42", "42"),
33+
("io_long", "42", "42"),
34+
("io_rowid", "AAAACPAABAAAAShAAA", "AAAACPAABAAAAShAAA"),
35+
(
36+
"io_date",
37+
datetime.datetime(year=2019, month=12, day=20),
38+
datetime.datetime(year=2019, month=12, day=20),
39+
),
40+
(
41+
"io_timestamp",
42+
datetime.datetime(year=2019, month=12, day=20),
43+
datetime.datetime(year=2019, month=12, day=20),
44+
),
45+
("io_raw", b"42", b"42"),
46+
("io_long_raw", b"42", b"42"),
47+
("io_char", "42".ljust(12000, " "), "42".ljust(12000, " ")),
48+
("io_character", "42".ljust(12000, " "), "42".ljust(12000, " ")),
49+
("io_bool", True, True),
50+
("io_record", IN_RECORD, IN_RECORD),
51+
pytest.param(
52+
"io_record_of_records",
53+
(42, IN_RECORD, IN_RECORD),
54+
(42, IN_RECORD, IN_RECORD),
55+
marks=pytest.mark.skip(
56+
reason="OCI-21602: operation does not support the specified typecode"
57+
),
58+
),
59+
("io_record_of_nested", (42, IN_NESTED, IN_NESTED), (42, IN_NESTED, IN_NESTED)),
60+
(
61+
"io_record_of_plsql_table",
62+
(42, IN_PLSQL_TABLE, IN_PLSQL_TABLE),
63+
(42, IN_PLSQL_TABLE, IN_PLSQL_TABLE),
64+
),
65+
("io_nested", IN_NESTED, IN_NESTED),
66+
("io_nested_of_records", [IN_RECORD] * 10, [IN_RECORD] * 10),
67+
(
68+
"io_nested_of_record_of_nested",
69+
[(42, IN_NESTED, IN_NESTED)] * 10,
70+
[(42, IN_NESTED, IN_NESTED)] * 10,
71+
),
72+
("io_varray", IN_VARRAY, IN_VARRAY),
73+
("io_plsql_table", IN_PLSQL_TABLE, IN_PLSQL_TABLE),
74+
(
75+
"io_plsql_table_of_records",
76+
{i: IN_RECORD for i in range(1, 11)},
77+
{i: IN_RECORD for i in range(1, 11)},
78+
),
79+
pytest.param(
80+
"io_varray_of_plsql_table",
81+
[IN_PLSQL_TABLE] * 10,
82+
[IN_PLSQL_TABLE] * 10,
83+
marks=pytest.mark.skip("Memory access violation"),
84+
),
85+
pytest.param(
86+
"io_varray_of_nested",
87+
[IN_NESTED] * 10,
88+
[IN_NESTED] * 10,
89+
marks=pytest.mark.skip("Memory access violation"),
90+
),
91+
pytest.param(
92+
"io_plsql_table_of_nested",
93+
{i: IN_NESTED for i in range(1, 11)},
94+
{i: IN_NESTED for i in range(1, 11)},
95+
marks=pytest.mark.skip("Memory access violation"),
96+
),
97+
pytest.param(
98+
"io_nested_of_nested",
99+
[IN_NESTED] * 10,
100+
[IN_NESTED] * 10,
101+
marks=pytest.mark.skip("Memory access violation"),
102+
),
103+
pytest.param(
104+
"io_nested_of_plsql_table",
105+
[IN_PLSQL_TABLE] * 10,
106+
[IN_PLSQL_TABLE] * 10,
107+
marks=pytest.mark.skip("Memory access violation"),
108+
),
109+
pytest.param(
110+
"io_plsql_table_of_plsql_table",
111+
{i: IN_PLSQL_TABLE for i in range(1, 11)},
112+
{i: IN_PLSQL_TABLE for i in range(1, 11)},
113+
marks=pytest.mark.skip("Memory access violation"),
114+
),
115+
],
116+
)
117+
def test_return_values(plsql, func, in_value, out_value):
118+
assert getattr(plsql.test_in_out_params, func)(in_value).p_param == out_value

‎tests/func/test_sys_subprograms.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_database_name(plsql):
2+
assert plsql.sys.database_name() == "orcl"

0 commit comments

Comments
 (0)