How to use the ipycanvas.py2js.py2js function in ipycanvas

To help you get started, we’ve selected a few ipycanvas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_subscript():
    code = "data['test'] = 36"
    assert py2js(code) == "data['test'] = 36"

    code = "data[0] = 35"
    assert py2js(code) == "data[0] = 35"
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_binary():
    code = 'value or 3'
    assert py2js(code) == '(value || 3)'

    code = 'value and 3'
    assert py2js(code) == '(value && 3)'

    code = 'value + 3'
    assert py2js(code) == '(value + 3)'

    code = 'value**3'
    assert py2js(code) == '(Math.pow(value, 3))'

    # Unsupported operator
    code = 'value & x'
    with pytest.raises(Py2JSSyntaxError):
        py2js(code)
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_unary():
    code = 'not value'
    assert py2js(code) == '!(value)'

    code = '-value'
    assert py2js(code) == '-value'

    code = '+value'
    assert py2js(code) == '+value'
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_list():
    code = '[True, 3, \'hello\']'
    assert py2js(code) == '[true, 3, \'hello\']'
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_subscript():
    code = "data['test'] = 36"
    assert py2js(code) == "data['test'] = 36"

    code = "data[0] = 35"
    assert py2js(code) == "data[0] = 35"
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_ternary():
    code = '3 if value else 4'
    assert py2js(code) == '(value ? 3 : 4)'
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_unary():
    code = 'not value'
    assert py2js(code) == '!(value)'

    code = '-value'
    assert py2js(code) == '-value'

    code = '+value'
    assert py2js(code) == '+value'
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
code = 'value or 3'
    assert py2js(code) == '(value || 3)'

    code = 'value and 3'
    assert py2js(code) == '(value && 3)'

    code = 'value + 3'
    assert py2js(code) == '(value + 3)'

    code = 'value**3'
    assert py2js(code) == '(Math.pow(value, 3))'

    # Unsupported operator
    code = 'value & x'
    with pytest.raises(Py2JSSyntaxError):
        py2js(code)
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_num():
    code = '36'
    assert py2js(code) == '36'
github martinRenou / ipycanvas / tests / test_py2js.py View on Github external
def test_compare():
    code = '3 < value <= 4'
    assert py2js(code) == '(3 < value <= 4)'