Пример #1
0
def condition(function=None,
              on=ConditionOperator.START,
              cache=False,
              vectorized=False):
    from remake.schematic.cache import SchematicCache

    if function is None:
        return partial(condition, on=on, cache=cache, vectorized=vectorized)

    transformer, name, sources = get_info(function)
    function = function if not cache else lru_cache(function)

    valid_locations = [
        ConditionOperator.START, ConditionOperator.END,
        ConditionOperator.GROUPS
    ]
    if on not in valid_locations:
        msg = f"{name}(..., at={on}) is not a valid condition error. Please use one of {valid_locations}"
        raise InvalidConditionLocationError(msg)

    spec = ConditionOperator(name=name,
                             on=on,
                             sources=sources,
                             transform=function,
                             vectorized=vectorized)
    SchematicCache.add_condition(transformer, spec)

    return function
Пример #2
0
def test_core_generation():
    name = "TEST"
    SchematicCache.add_column(name, ColumnSpec("test", [], False, lambda: True, False))
    SchematicCache.add_condition(name, ConditionSpec("test", [], lambda: True, ""))
    SchematicCache.add_copy(name, CopySpec("test", "test"))
    SchematicCache.add_group(name, GroupSpec(name="test", sources=[], transform=None, sort_by=None))
    SchematicCache.add_index(name, IndexSpec("test", []))
    SchematicCache.add_parameter(name, ParameterSpec("Test", "Test", None, None, None, None, None))
    SchematicCache.add_sorts(name, SortBySpec([]))
    SchematicCache.add_explode(name, ExplodeSpec([], None))
    SchematicCache.add_expand(name, ExpandSpec([], None))
    SchematicCache.add_join(name, JoinSpec([], None))

    core = SchematicCache.get(name)
    assert len(core.columns) == 1
    assert len(core.copies) == 1
    assert len(core.groups) == 1
    assert len(core.indexes) == 1
    assert len(core.parameters) == 1
    assert len(core.sorts) == 1
    assert len(core.explodes) == 1
    assert len(core.expands) == 1
    assert len(core.joins) == 1