コード例 #1
0
ファイル: test_text.py プロジェクト: stephenrauch/pycel
    find,
    left,
    len_,
    lower,
    mid,
    replace,
    right,
    substitute,
    text as text_func,
    trim,
    upper,
    value,
)

# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.text, __name__)


def test_text_ws(fixture_xls_copy):
    compiler = ExcelCompiler(fixture_xls_copy('text.xlsx'))
    result = compiler.validate_serialized()
    assert result == {}


@pytest.mark.parametrize('args, expected', (
    ('a 1 abc'.split(), 'a1abc'),
    ('a Jan-00 abc'.split(), 'aJan-00abc'),
    ('a	#DIV/0! abc'.split(), DIV0),
    ('a	1 #DIV/0!'.split(), DIV0),
    ('a #NAME? abc'.split(), NAME_ERROR),
    (('a', True, 'abc'), 'aTRUEabc'),
コード例 #2
0
import pytest

import pycel.lib.engineering
from pycel.excelutil import coerce_to_number, DIV0, ERROR_CODES, NUM_ERROR, VALUE_ERROR
from pycel.lib import engineering
from pycel.lib.engineering import (
    bitand,
    bitlshift,
    bitor,
    bitrshift,
    bitxor,
)
from pycel.lib.function_helpers import load_to_test_module

# dynamic load the lib functions from engineering and apply metadata
load_to_test_module(pycel.lib.engineering, __name__)

MAX_BASE_2 = engineering._SIZE_MASK[2]
MAX_BASE_8 = engineering._SIZE_MASK[8]
MAX_BASE_16 = engineering._SIZE_MASK[16]


def compare_result(expected, result):
    expected = coerce_to_number(expected)
    result = coerce_to_number(result)
    if isinstance(expected, (int, float)) and isinstance(result, (int, float)):
        return pytest.approx(expected) == result
    else:
        return expected == result

コード例 #3
0
    _match,
    choose,
    column,
    hlookup,
    index,
    indirect,
    lookup,
    match,
    offset,
    row,
    vlookup,
)


# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.lookup, __name__)


def test_lookup_ws(fixture_xls_copy):
    INDIRECT_FORMULA_ADDRESS = AddressCell('Offset!B53')
    compiler = ExcelCompiler(fixture_xls_copy('lookup.xlsx'))

    # do an INDIRECT() before other cells are loaded to verify it can load what it needs
    result = compiler.validate_calcs([INDIRECT_FORMULA_ADDRESS])
    assert result == {}

    # now load and check everything
    result = compiler.validate_serialized()
    assert result == {}

    # use indirect to an existing range
コード例 #4
0
ファイル: test_logical.py プロジェクト: dgorissen/pycel
import pycel.lib.logical
from pycel.lib.logical import (
    _clean_logicals,
    iferror,
    x_and,
    x_if,
    x_not,
    x_or,
    x_xor,
)

from pycel.lib.function_helpers import load_to_test_module

# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.logical, __name__)


@pytest.mark.parametrize(
    'test_value, result', (
        ((1, '3', 2.0, 3.1, ('x', True, None)),
         (1, 2, 3.1, True)),
        ((1, '3', 2.0, 3.1, ('x', VALUE_ERROR)),
         VALUE_ERROR),
        ((1, NA_ERROR, 2.0, 3.1, ('x', VALUE_ERROR)),
         NA_ERROR),
        (('1', ('x', 'y')),
         VALUE_ERROR),
        ((),
         VALUE_ERROR),
    )
コード例 #5
0
    xmin,
    xsum,
)
from pycel.excelutil import (
    DIV0,
    EMPTY,
    NA_ERROR,
    NAME_ERROR,
    NUM_ERROR,
    REF_ERROR,
    VALUE_ERROR,
)
from pycel.lib.function_helpers import load_to_test_module

# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.excellib, __name__)


def test_numerics():
    assert (1, 2, 3.1) == _numerics(1, '3', 2.0, pytest, 3.1, 'x')
    assert (1, 2, 3.1) == _numerics((1, '3', (2.0, pytest, 3.1), 'x'))


def test_average():
    assert 2 == average(1, '3', 2.0, pytest, 3, 'x')
    assert 2 == average((1, '3', (2.0, pytest, 3), 'x'))

    assert -0.1 == average((-0.1, None, 'x', True))

    assert DIV0 == average(['x'])
コード例 #6
0
ファイル: test_excellib.py プロジェクト: dgorissen/pycel
    AddressRange,
    DIV0,
    ExcelCmp,
    NA_ERROR,
    NAME_ERROR,
    NUM_ERROR,
    PyCelException,
    REF_ERROR,
    VALUE_ERROR,
)

from pycel.lib.function_helpers import error_string_wrapper, load_to_test_module


# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.excellib, __name__)


def test_numerics():
    assert (1, 2, 3.1) == _numerics(1, '3', 2.0, pytest, 3.1, 'x')
    assert (1, 2, 3.1) == _numerics((1, '3', (2.0, pytest, 3.1), 'x'))


def test_average():
    assert 2 == average(1, '3', 2.0, pytest, 3, 'x')
    assert 2 == average((1, '3', (2.0, pytest, 3), 'x'))

    assert -0.1 == average((-0.1, None, 'x', True))

    assert DIV0 == average(['x'])
コード例 #7
0
)
from pycel.lib.function_helpers import load_to_test_module
from pycel.lib.logical import (
    _clean_logicals,
    iferror,
    ifs,
    x_and,
    x_if,
    x_not,
    x_or,
    x_xor,
)


# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.logical, __name__)


@pytest.mark.parametrize(
    'test_value, result', (
        ((1, '3', 2.0, 3.1, ('x', True, None)),
         (1, 2, 3.1, True)),
        ((1, '3', 2.0, 3.1, ('x', VALUE_ERROR)),
         VALUE_ERROR),
        ((1, NA_ERROR, 2.0, 3.1, ('x', VALUE_ERROR)),
         NA_ERROR),
        (('1', ('x', 'y')),
         VALUE_ERROR),
        ((),
         VALUE_ERROR),
    )
コード例 #8
0
    isblank,
    iserr,
    iserror,
    iseven,
    islogical,
    isna,
    isnontext,
    isnumber,
    isodd,
    istext,
    n,
    na,
)

# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.information, __name__)


def test_information_ws(fixture_xls_copy):
    compiler = ExcelCompiler(fixture_xls_copy('information.xlsx'))
    result = compiler.validate_serialized()
    assert result == {}


@pytest.mark.parametrize('value, expected', (
    (None, True),
    (0, False),
    (1, False),
    (1.0, False),
    (-1, False),
    ('a', False),
コード例 #9
0
    yearfrac,
)

from pycel.excelutil import (
    DATE_ZERO,
    DIV0,
    NUM_ERROR,
    SECOND,
    VALUE_ERROR,
)
from pycel.excelcompiler import ExcelCompiler

from pycel.lib.function_helpers import load_to_test_module

# dynamic load the lib functions from excellib and apply metadata
load_to_test_module(pycel.lib.date_time, __name__)


class TestDate:
    def test_values_can_str(self):
        assert date('2016', 1, 1) == date(2016, '1', 1) == date(2016, 1, '1')

    def test_year_must_be_positive(self):
        assert NUM_ERROR == date(-1, 1, 1)

    def test_year_must_have_less_than_10000(self):
        assert NUM_ERROR == date(10000, 1, 1)

    def test_result_must_be_positive(self):
        assert NUM_ERROR == date(1900, 1, -1)