How to use the pycel.excelformula.ExcelFormula function in pycel

To help you get started, we’ve selected a few pycel 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 dgorissen / pycel / tests / test_excelformula.py View on Github external
def dump_parse(to_dump, ATestCell):
    cell = ATestCell('A', 1)

    print('[')
    for formula in to_dump:
        excel_formula = ExcelFormula(formula, cell=cell)
        parsed = excel_formula.rpn
        ast_root = excel_formula.ast
        result_rpn = "|".join(str(x) for x in parsed)
        try:
            result_python_code = ast_root.emit
        except:  # noqa: E722
            result_python_code = ''
        dump_test_case(formula, result_python_code, result_rpn)
    print(']')
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_bool_funcs(formula, result):
    eval_ctx = ExcelFormula.build_eval_context(lambda x: None, None)
    assert eval_ctx(ExcelFormula(formula)) == result
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_get_linest_degree_with_cell(ATestCell):
    with mock.patch('pycel.excelformula.get_linest_degree') as get:
        get.return_value = -1, -1

        cell = ATestCell('A', 1, 'Phony Sheet')
        formula = ExcelFormula('=linest(C1)', cell=cell)

        expected = 'linest(_C_("Phony Sheet!C1"), degree=-1)[-2]'
        assert expected == formula.python_code
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_str():
    excel_formula = ExcelFormula('=E54-E48')
    assert '=E54-E48' == str(excel_formula)

    assert '_C_("E54") - _C_("E48")' == excel_formula.python_code
    excel_formula.base_formula = None
    assert '_C_("E54") - _C_("E48")' == str(excel_formula)

    excel_formula._ast = None
    excel_formula._rpn = None
    excel_formula._python_code = None
    assert '' == str(excel_formula)
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_column(formula, result, cell, empty_eval_context, ATestCell):
    if cell is not None:
        cell = eval(cell)
    assert empty_eval_context(ExcelFormula(formula, cell=cell)) == result
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_string_number_compare(formula, result, empty_eval_context):
    assert empty_eval_context(ExcelFormula(formula)) == result
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_parser_error(formula):
    with pytest.raises(FormulaParserError):
        ExcelFormula(formula).ast
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_empty_cell_logic_op(formula, result):
    eval_ctx = ExcelFormula.build_eval_context(lambda x: None, None)
    assert eval_ctx(ExcelFormula(formula)) == result
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_bool_ops(formula, result):
    eval_ctx = ExcelFormula.build_eval_context(lambda x: None, None)
    assert eval_ctx(ExcelFormula(formula)) == result
github dgorissen / pycel / tests / test_excelformula.py View on Github external
def test_subtotal(formula, result):
    assert ExcelFormula(formula).ast.emit == result
    assert ExcelFormula(formula.replace('tal(', 'tal(1')).ast.emit == result