Skip to content

Commit 465cf09

Browse files
committed
attribute walker prototype
1 parent a93bd3b commit 465cf09

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎plsql/client.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class Subprogram:
6464
def __init__(self, name, plsql):
6565
self.name, self.plsql = name, plsql
6666

67+
if '.' in name:
68+
schema, name = name.split('.')
69+
6770
binds = {'owner': TEST_SCHEMA, 'name': name}
6871
self.definition = self.SubprogramRecord(*next(plsql.query(sql_query=self.subprogram_sql, bind_variables=binds)))
6972

@@ -123,6 +126,19 @@ def __call__(self, **kwargs):
123126
raise NotImplementedError(f'Unrecognized object_type "{self.definition.object_type}"!')
124127

125128

129+
class AttributeWalker:
130+
def __init__(self, plsql, attr):
131+
self.plsql, self.attr = plsql, [attr]
132+
133+
def __getattr__(self, item):
134+
self.attr.append(item)
135+
return self
136+
137+
def __call__(self, **kwargs):
138+
subprogram = Subprogram('.'.join(self.attr), self.plsql)
139+
return subprogram(**kwargs)
140+
141+
126142
class Database:
127143

128144
def __init__(self, user, password, host, port, service_name, encoding):
@@ -140,4 +156,4 @@ def query(self, sql_query, bind_variables):
140156
yield rec
141157

142158
def __getattr__(self, item):
143-
return Subprogram(item, self)
159+
return AttributeWalker(self, item)

‎tests/conftest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def managed_object(plsql, object_type, object_name):
2020

2121
plsql.execute_immediate(sql_text)
2222
yield
23-
# plsql.execute_immediate(f'DROP {object_type} {object_name}')
23+
plsql.execute_immediate(f'DROP {object_type} {object_name}')
2424

2525

2626
@pytest.fixture(scope='module')

‎tests/test_functions.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ def test_simple_function(plsql, simple_function):
33
assert plsql.simple_function(p_int=None) is None
44

55

6+
def test_simple_function_indirection(plsql, simple_function):
7+
assert plsql.test_user.simple_function(p_int=5) == 5 + 5
8+
assert plsql.test_user.simple_function(p_int=None) is None
9+
10+
611
def test_function_with_defaults(plsql, function_with_defaults):
712
assert plsql.function_with_defaults() == 5
813
assert plsql.function_with_defaults(p_int_a=0) == 4

0 commit comments

Comments
 (0)