Пример #1
0
def schematic(cls):
    if not inspect.isclass(cls):
        raise ValueError(
            f"@schematic can only be used as a class decorator, it cannot decorate {cls}"
        )

    cls_name = cls.__name__

    inherited_core = SchematicCore()
    for parent in cls.__bases__:
        inherited_core = merge_schematics(inherited_core,
                                          recursive_merge(parent))

    schematic = SchematicCache.get(cls_name)

    final_schematic = merge_schematics(inherited_core, schematic)

    # Copy all functionality of the original class
    cls_attributes = {}
    for attr_name, attr in vars(cls).items():
        if not attr_name.startswith("_") and not attr_name.endswith("_"):
            cls_attributes[attr_name] = attr

    Transform = type(f"{cls_name}Schematic", (SchematicTransformation, ), {})

    transformer_cls = assemble_schematic(Transform, final_schematic,
                                         cls_attributes)

    return transformer_cls
Пример #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