Exemplo n.º 1
0
def test_cache():
    from pykern.pkcollections import PKDict
    from pykern.pkunit import pkeq
    from sirepo.template.code_variable import CodeVar, PurePythonEval
    code_var = CodeVar(
        [
            PKDict(
                name='x',
                value='123',
            ),
            PKDict(
                name='y',
                value='x + x',
            ),
            PKDict(
                name='z',
                value='y * -20',
            ),
        ],
        PurePythonEval(),
    )
    pkeq(
        code_var.compute_cache(
            # data
            PKDict(models=PKDict(
                beamlines=[],
                elements=[
                    PKDict(
                        _id=1,
                        type='point',
                        p1='x + y',
                        p2=234,
                    ),
                ],
                commands=[],
            )),
            # schema
            PKDict(model=PKDict(point=PKDict(
                p1=["P1", "RPNValue", 0],
                p2=["P2", "RPNValue", 0],
            )), ),
        ),
        PKDict({
            'x + x': 246,
            'x + y': 369,
            'x': 123,
            'y * -20': -4920,
            'y': 246,
            'z': -4920,
        }))
    pkeq(
        code_var.get_expr_dependencies('x x * x +'),
        ['x'],
    )
    pkeq(
        code_var.get_expr_dependencies('y 2 pow'),
        ['x', 'y'],
    )
Exemplo n.º 2
0
def test_cache():
    from pykern.pkcollections import PKDict
    from pykern.pkunit import pkeq
    from sirepo.template.code_variable import CodeVar, PurePythonEval
    code_var = CodeVar(
        [
            PKDict(
                name='x',
                value='123',
            ),
            PKDict(
                name='y',
                value='x + x',
            ),
            PKDict(
                name='z',
                value='y * -20',
            ),
        ],
        PurePythonEval(),
    )
    pkeq(
        code_var.compute_cache(
            PKDict(
                models=PKDict(
                    beamlines=[],
                    elements=[],
                    commands=[],
                )
            ),
            PKDict(),
        ),
        PKDict({
            'x': 123,
            'y': 246,
            'x + x': 246,
            'y * -20': -4920,
            'z': -4920,
        })
    )
    pkeq(
        code_var.get_expr_dependencies('x x * x +'),
        ['x'],
    )
    pkeq(
        code_var.get_expr_dependencies('y 2 pow'),
        ['x', 'y'],
    )
Exemplo n.º 3
0
def test_case_insensitive():
    # tests case insensitive and attribute like variables
    from pykern.pkcollections import PKDict
    from pykern.pkunit import pkeq
    from sirepo.template.code_variable import CodeVar, PurePythonEval
    code_var = CodeVar(
        [
            PKDict(
                name='x.x7.x',
                value='123',
            ),
            PKDict(
                name='Y',
                value='x.X7.x + x.x7.x',
            ),
        ],
        PurePythonEval(),
        case_insensitive=True,
    )
    pkeq(
        code_var.compute_cache(
            PKDict(
                models=PKDict(
                    beamlines=[],
                    elements=[],
                    commands=[],
                )
            ),
            PKDict(),
        ),
        PKDict({
            'x.x7.x': 123,
            'y': 246,
            'x.x7.x + x.x7.x': 246,
        })
    )
    pkeq(
        code_var.get_expr_dependencies('Y y +'),
        ['x.x7.x', 'y'],
    )
Exemplo n.º 4
0
def test_case_insensitive():
    # tests case insensitive and attribute like variables
    from pykern.pkcollections import PKDict
    from pykern.pkunit import pkeq
    from sirepo.template.code_variable import CodeVar, PurePythonEval
    code_var = CodeVar(
        [
            PKDict(
                name='x.x7.x',
                value='123',
            ),
            PKDict(
                name='Y',
                value='x.X7.x + x.x7.x',
            ),
        ],
        PurePythonEval(),
        case_insensitive=True,
    )
    pkeq(code_var.compute_cache(
        _empty_data(),
        PKDict(),
    ), PKDict({
        'x.x7.x': 123,
        'y': 246,
        'x.x7.x + x.x7.x': 246,
    }))
    pkeq(
        code_var.get_expr_dependencies('Y y +'),
        ['x.x7.x', 'y'],
    )
    pkeq(
        code_var.validate_var_delete(
            'X.X7.X',
            _empty_data(),
            PKDict(),
        ),
        '"X.X7.X" is in use in variable(s): y',
    )