Ejemplo n.º 1
0
def test_compiled_python_cache():
    formula = ExcelFormula('=1 + 2')
    # first call does the calc, the second uses cached
    compiled_python = formula.compiled_python
    assert compiled_python == formula.compiled_python

    # rebuild from marshalled
    formula._compiled_python = None
    assert compiled_python == formula.compiled_python

    # invalidate the marshalled code, rebuild from source
    formula._compiled_python = None
    formula._marshalled_python = 'junk'
    assert compiled_python == formula.compiled_python
Ejemplo n.º 2
0
def test_compiled_python_cache():
    formula = ExcelFormula('=1 + 2')
    # first call does the calc, the second uses cached
    compiled_python = formula.compiled_python
    assert compiled_python == formula.compiled_python

    # rebuild from marshalled
    formula._compiled_python = None
    assert compiled_python == formula.compiled_python

    # invalidate the marshalled code, rebuild from source
    formula._compiled_python = None
    formula._marshalled_python = 'junk'
    assert compiled_python == formula.compiled_python
Ejemplo n.º 3
0
def test_lineno_on_error_reporting(empty_eval_context):
    excel_formula = ExcelFormula('')
    excel_formula._python_code = 'X'
    excel_formula.lineno = 6
    excel_formula.filename = 'a_file'

    msg = 'File "a_file", line 6,'
    with pytest.raises(UnknownFunction, match=msg):
        empty_eval_context(excel_formula)

    excel_formula._python_code = '(x)'
    excel_formula._compiled_python = None
    excel_formula._marshalled_python = None
    excel_formula.compiled_lambda = None
    excel_formula.lineno = 60

    with pytest.raises(UnknownFunction, match='File "a_file", line 60,'):
        empty_eval_context(excel_formula)
Ejemplo n.º 4
0
def test_lineno_on_error_reporting(empty_eval_context):
    excel_formula = ExcelFormula('')
    excel_formula._python_code = 'X'
    excel_formula.lineno = 6
    excel_formula.filename = 'a_file'

    msg = 'File "a_file", line 6,'
    with pytest.raises(UnknownFunction, match=msg):
        empty_eval_context(excel_formula)

    excel_formula._python_code = '(x)'
    excel_formula._compiled_python = None
    excel_formula._marshalled_python = None
    excel_formula.compiled_lambda = None
    excel_formula.lineno = 60

    with pytest.raises(UnknownFunction, match='File "a_file", line 60,'):
        empty_eval_context(excel_formula)
Ejemplo n.º 5
0
def test_lineno_on_error_reporting():
    eval_ctx = ExcelFormula.build_eval_context(None, None)

    excel_formula = ExcelFormula('')
    excel_formula._python_code = 'X'
    excel_formula.lineno = 6
    excel_formula.filename = 'a_file'

    with pytest.raises(FormulaEvalError, match='File "a_file", line 6'):
        eval_ctx(excel_formula)

    excel_formula._python_code = '(x)'
    excel_formula._compiled_python = None
    excel_formula._marshalled_python = None
    excel_formula.compiled_lambda = None
    excel_formula.lineno = 60

    with pytest.raises(FormulaEvalError, match=', line 60,'):
        eval_ctx(excel_formula)