Here are the examples of the python api bokeh.models.CustomJSTransform.from_py_func taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
0
Source : test_transforms.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_customjstransform_from_py_func_no_args():
def cosine():
from pscript import window
return window.Math.cos(x) # noqa
def v_cosine():
from pscript import window
return [window.Math.cos(x) for x in xs] # noqa
transform = CustomJSTransform.from_py_func(cosine, v_cosine)
js_code = pscript.py2js(cosine, 'transformer')
function_wrapper = transform.func.replace(js_code, '')
assert function_wrapper == "return transformer();\n"
v_js_code = pscript.py2js(v_cosine, 'transformer')
v_function_wrapper = transform.v_func.replace(v_js_code, '')
assert v_function_wrapper == "return transformer();\n"
def test_customjstransform_from_py_func_with_args():
0
Source : test_transforms.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_customjstransform_from_py_func_with_args():
slider = Slider()
def cosine(foo=slider):
from pscript import window
return window.Math.cos(x) # noqa
def v_cosine(foo=slider):
from pscript import window
return [window.Math.cos(x) for x in xs] # noqa
transform = CustomJSTransform.from_py_func(cosine, v_cosine)
assert transform.args['foo'] is slider
js_code = pscript.py2js(cosine, 'transformer')
function_wrapper = transform.func.replace(js_code, '')
assert function_wrapper == "return transformer(foo);\n"
v_js_code = pscript.py2js(v_cosine, 'transformer')
v_function_wrapper = transform.v_func.replace(v_js_code, '')
assert v_function_wrapper == "return transformer(foo);\n"
def test_customjstransform_bad_pyfunc_formats():
0
Source : test_transforms.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_customjstransform_bad_pyfunc_formats():
def foo():
pass
def has_positional_arg(x):
return None
with pytest.raises(ValueError):
CustomJSTransform.from_py_func(has_positional_arg, foo)
def has_positional_arg_with_kwargs(y, x=5):
return None
with pytest.raises(ValueError):
CustomJSTransform.from_py_func(has_positional_arg_with_kwargs, foo)
def has_non_Model_keyword_argument(x=10):
return None
with pytest.raises(ValueError):
CustomJSTransform.from_py_func(has_non_Model_keyword_argument, foo)
def test_customjstransform_from_coffeescript_no_arg():