Skip to content

Commit

Permalink
Merge pull request #445 from jamesmartini/develop
Browse files Browse the repository at this point in the history
support custom variables in user_function
  • Loading branch information
GavinHuttley committed Dec 18, 2019
2 parents 69a5e10 + c916351 commit aa9a90a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cogent3/app/composable.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,14 @@ def __init__(self, func, input_types, output_types, data_types=None):
)
self.func = func

def func(self, *args, **kwargs):
self._func(self, *args, **kwargs)

def __str__(self):
name = self.func.__name__
module = self.func.__module__
return f"user_function(name='{name}', module='{module}')"

def __repr__(self):
return str(self)

13 changes: 13 additions & 0 deletions tests/test_app/test_composable.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ def foo(self, val, *args, **kwargs):
def bar(self, val, *args, **kwargs):
return val.distance_matrix(calc="hamming", show_progress=False)

def _demo(self, ctx, expect):
self.assertEqual(ctx.frame_start, expect)
return expect

def test_user_function_custom_variables(self):
demo = user_function(
self._demo, ("aligned", "serialisable"), ("aligned", "serialisable")
)
foo = demo
frame_start = 2
foo.frame_start = frame_start
foo(frame_start)

def test_user_function(self):
"""composable functions should be user definable"""
from cogent3 import make_aligned_seqs
Expand Down

0 comments on commit aa9a90a

Please sign in to comment.