Commit 177972b9 authored by Lucas Bourneuf's avatar Lucas Bourneuf

test more export features

parent df0a008c
......@@ -103,7 +103,7 @@ def _standalone_export_pipeline(scripts:[Script], options:dict={}, default_conte
runon_args = ', '.join(f"{name}={name}" for name, *_ in script.options)
new_context = f"''.join(run_on(context, {runon_args}))"
elif script.language == 'asp':
new_context = '"""\\n' + script.source_code + '"""'
new_context = '"""' + script.source_code + '"""'
elif script.language == 'asp file':
yield f' def run_on(context):'
yield f' with open("{script.source_code}") as fd:'
......@@ -112,7 +112,7 @@ def _standalone_export_pipeline(scripts:[Script], options:dict={}, default_conte
else:
raise ValueError(f"unhandled export of language '{script.language}'")
if not script.erase_context:
new_context = 'context + ' + new_context
new_context = r'context + ("\n" if context else "") + ' + new_context
yield f' return {new_context}'
yield 'def run_on(context:str, args):'
for runon, script in runons:
......
import tempfile
import biseau
from biseau import standalone_export_pipeline
from biseau.module_loader import build_scripts_from_asp_code
......@@ -20,15 +21,22 @@ def test_standalone_export_pipeline():
assert biseau.__version__ in env['__doc__']
def test_standalone_export_pipeline_with_more_script_format():
def test_standalone_export_pipeline_with_different_script_format():
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.py') as fd:
fd.write('def run_on(context):\n return "node(a)."\n')
pyfile = fd.name
scripts = tuple((
biseau.module_loader.build_script_from_json({
'name': 'test-python-1',
'python': 'def run_on(context):\n return "node(a)."\n',
'python': 'def run_on(context, *, nodename:str="b"):\n return f"node({nodename})."\n',
}),
biseau.module_loader.build_script_from_json({
'name': 'test-python-2',
'ASP': 'node(b).',
'python file': pyfile,
}),
biseau.module_loader.build_script_from_json({
'name': 'test-python-3',
'ASP': 'node(c).',
}),
*build_scripts_from_asp_code('link(X,Y) :- node(X) ; node(Y) ; X<Y.'),
))
......@@ -42,4 +50,6 @@ def test_standalone_export_pipeline_with_more_script_format():
assert callable(env['run_on'])
assert callable(env['cli'])
assert biseau.__version__ in env['__doc__']
assert env['run_on']('', args=None) == final_context
found_context = env['run_on']('', args=None)
print('FOUND CONTEXT:', found_context)
assert found_context == final_context
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment