Esempio n. 1
0
 def convert_type(mytype: Entity) -> model.Entity:
     return model.Entity(
         [x.get_full_name() for x in mytype.parent_entities],
         {
             n: convert_attribute(attr)
             for n, attr in mytype.get_attributes().items()
             if not isinstance(attr, RelationAttribute)
         },
         {
             n: convert_relation(attr)
             for n, attr in mytype.get_attributes().items()
             if isinstance(attr, RelationAttribute)
         },
         location(mytype),
     )
Esempio n. 2
0
def test_slots_rt():
    ns = Namespace("root", None)
    rs = Resolver(ns)
    e = Entity("xx", ns)
    qs = QueueScheduler(None, [], [], None, set())
    r = RelationAttribute(e, None, "xx", Location("", 1))
    i = Instance(e, rs, qs)

    assert_slotted(ResultVariable())
    assert_slotted(AttributeVariable(None, None))
    assert_slotted(Promise(None, None))
    assert_slotted(ListVariable(r, i, qs))
    assert_slotted(OptionVariable(r, i, qs))

    assert_slotted(qs)
    assert_slotted(DelegateQueueScheduler(qs, None))

    assert_slotted(Waiter(qs))

    assert_slotted(
        ExecutionUnit(qs, r, ResultVariable(), {}, Literal(""), None))
    assert_slotted(HangUnit(qs, r, {}, None, Resumer()))
    assert_slotted(RawUnit(qs, r, {}, Resumer()))

    assert_slotted(FunctionUnit(qs, rs, ResultVariable(), {}, None))

    assert_slotted(i)
Esempio n. 3
0
    def __init__(
        self,
        namespace: Namespace,
        lname: LocatableString,
        comment: Optional[LocatableString],
        parents: List[LocatableString],
        attributes: List[DefineAttribute],
    ) -> None:
        name = str(lname)
        TypeDefinitionStatement.__init__(self, namespace, name)
        if "-" in name:
            inmanta_warnings.warn(HyphenDeprecationWarning(lname))

        self.anchors = [TypeReferenceAnchor(namespace, x) for x in parents]

        self.name = name
        self.attributes = attributes
        if comment is not None:
            self.comment = str(comment)
        else:
            self.comment = None

        self.parents = parents

        if len(self.parents) == 0 and not (self.name == "Entity" and self.namespace.name == "std"):
            dummy_location: Range = Range("__internal__", 1, 1, 1, 1)
            self.parents.append(LocatableString("std::Entity", dummy_location, -1, namespace))

        self.type = Entity(self.name, namespace, self.comment)
        self.type.location = lname.location
Esempio n. 4
0
def create_instance(graph: Optional[DataflowGraph] = None,
                    entity: Optional[Entity] = None,
                    statement: Optional[Statement] = None) -> InstanceNode:
    responsible: Statement = statement if statement is not None else Statement(
    )
    instance: InstanceNode = InstanceNode([])
    if graph is None:
        return instance
    return graph.own_instance_node_for_responsible(
        entity if entity is not None else Entity("DummyEntity",
                                                 Namespace("dummy_namespace")),
        responsible,
        lambda: instance,
    )
Esempio n. 5
0
def test_attribute_validate(multi: bool, nullable: bool) -> None:
    entity: Entity = Entity("DummyEntity", Namespace("dummy_namespace"))
    attribute: Attribute = Attribute(entity, Integer(), "my_attribute",
                                     Location("dummy.cf", 1), multi, nullable)

    def validate(value: object, success: bool) -> None:
        if success:
            attribute.validate(value)
        else:
            with pytest.raises(RuntimeException):
                attribute.validate(value)

    validate(42, not multi)
    validate(NoneValue(), nullable)
    validate([0, 1, 2], multi)
    validate([0, 1, NoneValue()], False)
Esempio n. 6
0
    def __init__(self,
                 namespace: Namespace,
                 name: str,
                 comment: str,
                 parents: List[str],
                 attributes: List[DefineAttribute]) -> None:
        TypeDefinitionStatement.__init__(self, namespace, name)
        self.name = name
        self.attributes = attributes
        self.comment = comment

        self.parents = parents

        if len(self.parents) == 0 and not (self.name == "Entity" and self.namespace.name == "std"):
            self.parents.append("std::Entity")

        self.type = Entity(self.name, namespace)
        self.type.location = self.location
def test_dataflow_index(graph: DataflowGraph, reverse: bool) -> None:
    entity: Entity = Entity("DummyEntity", Namespace("dummy_namespace"))
    i1: InstanceNode = create_instance(graph, entity)
    i2: InstanceNode = create_instance(graph, entity)

    assert i1.get_self() is i1
    assert i2.get_self() is i2
    assert i1 is not i2

    graph.add_index_match([i.reference() for i in [i1, i2]])
    if reverse:
        # make sure adding them again in another order does not cause issues
        graph.add_index_match([i.reference() for i in [i2, i1]])

    assert i1.get_self() is i1
    assert i2.get_self() is i1
    assert i2.reference().node() is i1
    assert i2.reference().top_node() is i2
    assert i1.get_all_index_nodes() == {i1, i2}
def test_dataflow_index_nodes(graph: DataflowGraph) -> None:
    entity: Entity = Entity("DummyEntity", Namespace("dummy_namespace"))
    i1: InstanceNode = create_instance(graph, entity)
    i2: InstanceNode = create_instance(graph, entity)

    i1.register_attribute("n").assign(
        ValueNode(0).reference(), Statement(), graph)
    i1.register_attribute("n").assign(
        ValueNode(0).reference(), Statement(), graph)

    x: AssignableNodeReference = get_dataflow_node(graph, "x")
    y: AssignableNodeReference = get_dataflow_node(graph, "y")

    x.assign(i1.reference(), Statement(), graph)
    y.assign(i2.reference(), Statement(), graph)

    graph.add_index_match([i.reference() for i in [i1, i2]])

    x_n: AssignableNodeReference = get_dataflow_node(graph, "x.n")
    y_n: AssignableNodeReference = get_dataflow_node(graph, "y.n")

    assert set(x_n.nodes()) == set(y_n.nodes())
Esempio n. 9
0
def relation_name(type: Entity, rel: RelationAttribute) -> str:
    if rel is None:
        return ""
    return type.get_full_name() + "." + rel.name
Esempio n. 10
0
def entity_instance(entity: str) -> InstanceNode:
    node: InstanceNode = InstanceNode([])
    node.entity = Entity(entity, Namespace("__config__", Namespace("__root_ns__")))
    return node