Exemple #1
0
def test_entity_constructor():
    r = Tokens(entity_constructor.parseString("test()"))
    assert str(r) == "test ( )"
    r = Tokens(entity_constructor.parseString("ABS(100)"))
    assert str(r) == "ABS ( 100 )"
    r = Tokens(entity_constructor.parseString("ABS(SELF)"))
    assert str(r) == "ABS ( SELF )"
Exemple #2
0
def test_simple_factor():
    r = Tokens(simple_factor.parseString("test()"))
    assert str(r) == "test ( )"
    r = Tokens(simple_factor.parseString("ABS(100)"))
    assert str(r) == "ABS ( 100 )"
    r = Tokens(simple_factor.parseString("ABS(SELF)"))
    assert str(r) == "ABS ( SELF )"
    r = Tokens(simple_factor.parseString("ABS(SELF[2])"))
    assert str(r) == "ABS ( SELF [ 2 ] )"
Exemple #3
0
def test_comments():
    assert str(Tokens(
        comments.parseString("(* comment  *)"))) == '(* comment  *)'
    assert str(Tokens(
        comments.parseString("(* comment * *)"))) == '(* comment * *)'
    assert str(Tokens(
        comments.parseString("(** comment **)"))) == '(** comment **)'
    assert str(Tokens(
        comments.parseString("(** (* comment **)"))) == '(** (* comment **)'
Exemple #4
0
def test_aggregate_init():
    assert Tokens(aggregate_initializer.parseString("[]")) == ['[', ']']
    r = Tokens(aggregate_initializer.parseString("['test', 100]"))
    assert r[0] == '['
    assert type(r[1]) is ast.StringLiteral
    assert r[1].value == 'test'
    assert r[2] == ','
    assert r[3] == 100
    assert type(r[3]) is int
    assert r[4] == ']'
Exemple #5
0
def test_ignore_tail_remark():
    expr_test = simple_expression('TEST')
    expr_test.ignore(tail_remark)
    assert str(Tokens(
        expr_test.parseString(" 1 + 1 -- approved_item \n xxx"))) == '1 + 1'
    assert str(
        Tokens(
            expr_test.parseString(
                " 1 + 1 -- approved_item simple.name \n END_TYPE;"))
    ) == '1 + 1'
Exemple #6
0
def test_aggregate_source():
    r = Tokens(aggregate_source_.parseString("AAA"))
    assert str(r) == "AAA"
    r = Tokens(aggregate_source_.parseString("AAA.bbb"))
    assert str(r) == "AAA . bbb"
    r = Tokens(aggregate_source_.parseString("AAA.bbb.ccc"))
    assert str(r) == "AAA . bbb . ccc"
    r = Tokens(aggregate_source_.parseString(r"SELF\AAA.bbb"))
    assert str(r) == r"SELF \ AAA . bbb"
    r = Tokens(aggregate_source_.parseString(r"SELF\AAA.bbb.ccc"))
    assert str(r) == r"SELF \ AAA . bbb . ccc"
Exemple #7
0
def test_where_clause_7():
    r = Tokens(
        where_clause.parseString(
            r"WHERE HasAdvancedFaces : SIZEOF(QUERY(Afs <* SELF\IfcManifoldSolidBrep.Outer.CfsFaces | "
            r"(NOT ('IFC4X2.IFCADVANCEDFACE' IN TYPEOF(Afs))))) = 0;"))
    assert str(r) == r"WHERE HasAdvancedFaces : SIZEOF ( QUERY ( Afs <* SELF \ IfcManifoldSolidBrep . Outer . CfsFaces | " \
                     "( NOT ( IFC4X2.IFCADVANCEDFACE IN TYPEOF ( Afs ) ) ) ) ) = 0 ;"
Exemple #8
0
def test_typedef_list():
    r = Tokens(
        type_decl.parseString(
            'TYPE IfcArcIndex = LIST [3:3] OF IfcPositiveInteger;END_TYPE;'))
    assert str(
        r
    ) == 'TYPE IfcArcIndex = LIST [ 3 : 3 ] OF IfcPositiveInteger ; END_TYPE ;'
Exemple #9
0
def test_query_expr_3():
    r = Tokens(
        query_expression.parseString(
            "QUERY (Vsh <* Voids | SIZEOF (QUERY (Afs <* Vsh.CfsFaces | "
            "(NOT ('IFC4X2.IFCADVANCEDFACE' IN TYPEOF(Afs)))  )) = 0))"))
    assert str(r) == "QUERY ( Vsh <* Voids | SIZEOF ( QUERY ( Afs <* Vsh . CfsFaces | ( NOT ( IFC4X2.IFCADVANCEDFACE IN " \
                     "TYPEOF ( Afs ) ) ) ) ) = 0 )"
Exemple #10
0
def test_complex_expr_2():
    r = Tokens(
        expression.parseString(
            r"SIZEOF(QUERY(Afs <* SELF\IfcManifoldSolidBrep.Outer.CfsFaces | "
            r"(NOT ('IFC4X2.IFCADVANCEDFACE' IN TYPEOF(Afs))))) = 0"))
    assert str(r) == r"SIZEOF ( QUERY ( Afs <* SELF \ IfcManifoldSolidBrep . Outer . CfsFaces | " \
                     r"( NOT ( IFC4X2.IFCADVANCEDFACE IN TYPEOF ( Afs ) ) ) ) ) = 0"
Exemple #11
0
def test_where_clause_6():
    r = Tokens(
        where_clause.parseString(
            "WHERE WR1 : (Role <> IfcRoleEnum.USERDEFINED) OR "
            " ((Role = IfcRoleEnum.USERDEFINED) AND EXISTS(SELF.UserDefinedRole));"
        ))
    assert str(r) == "WHERE WR1 : ( Role <> IfcRoleEnum . USERDEFINED ) OR ( ( Role = IfcRoleEnum . USERDEFINED ) AND " \
                     "EXISTS ( SELF . UserDefinedRole ) ) ;"
Exemple #12
0
def test_underlying_type_enum():
    e = Tokens(
        underlying_type.parseString(
            "ENUMERATION OF (EMAIL, FAX ,PHONE ,POST,VERBAL,USERDEFINED,NOTDEFINED);"
        ))
    assert str(
        e
    ) == "ENUMERATION OF ( EMAIL , FAX , PHONE , POST , VERBAL , USERDEFINED , NOTDEFINED )"
Exemple #13
0
def test_select():
    t = Tokens(
        select_type.parseString(
            "SELECT (IfcDerivedMeasureValue, IfcMeasureValue, IfcSimpleValue)")
    )
    assert str(
        t
    ) == "SELECT ( IfcDerivedMeasureValue , IfcMeasureValue , IfcSimpleValue )"
Exemple #14
0
def test_enumeration():
    e = Tokens(
        enumeration_type.parseString(
            "ENUMERATION OF (EMAIL, FAX ,PHONE ,POST,VERBAL,USERDEFINED,NOTDEFINED);"
        ))
    assert str(
        e
    ) == "ENUMERATION OF ( EMAIL , FAX , PHONE , POST , VERBAL , USERDEFINED , NOTDEFINED )"
Exemple #15
0
def test_simple_entity_decl():
    e = Tokens(entity_decl.parseString("""  
    ENTITY action;
        name          : label;
        description   : text;
        chosen_method : action_method;
    END_ENTITY; -- action
    """))
    assert str(e) == "ENTITY action ; name : label ; description : text ; chosen_method : action_method ; END_ENTITY ;"
Exemple #16
0
def test_typedef_select():
    t = Tokens(
        type_decl.parseString("""
    TYPE IfcValue = SELECT (
        IfcDerivedMeasureValue,
        IfcMeasureValue,
        IfcSimpleValue);
    END_TYPE;
    """))
    assert str(
        t
    ) == "TYPE IfcValue = SELECT ( IfcDerivedMeasureValue , IfcMeasureValue , IfcSimpleValue ) ; END_TYPE ;"
Exemple #17
0
def test_where_rule_1():
    r = Tokens(
        type_decl.parseString("""
    TYPE IfcCardinalPointReference = INTEGER;
    WHERE
        GreaterThanZero : SELF > 0;
    END_TYPE;
    """))

    assert str(
        r
    ) == "TYPE IfcCardinalPointReference = INTEGER ; WHERE GreaterThanZero : SELF > 0 ; END_TYPE ;"
Exemple #18
0
def test_simple_entity_decl_3():
    e = Tokens(entity_decl.parseString("""
    ENTITY IfcActorRole;
        Role : IfcRoleEnum;
        UserDefinedRole : OPTIONAL IfcLabel;
        Description : OPTIONAL IfcText;
        INVERSE
            HasExternalReference : SET [0:?] OF IfcExternalReferenceRelationship FOR RelatedResourceObjects;
        WHERE SELF > 0;
    END_ENTITY;
    """))
    assert len(e) == 38
Exemple #19
0
def test_simple_entity_decl_5():
    e = Tokens(entity_decl.parseString(r"""
    ENTITY IfcAdvancedBrep
        SUPERTYPE OF (ONEOF
            (IfcAdvancedBrepWithVoids))
        SUBTYPE OF (IfcManifoldSolidBrep);
        WHERE
            HasAdvancedFaces : SIZEOF(QUERY(Afs <* SELF\IfcManifoldSolidBrep.Outer.CfsFaces |
                (NOT ('IFC4X2.IFCADVANCEDFACE' IN TYPEOF(Afs)))
            )) = 0;
    END_ENTITY;
    """))
    assert len(e) == 51
Exemple #20
0
def test_simple_entity_decl_6():
    e = Tokens(entity_decl.parseString(r"""
    ENTITY IfcAdvancedBrepWithVoids
        SUBTYPE OF (IfcAdvancedBrep);
        Voids : SET [1:?] OF IfcClosedShell;
        WHERE
            VoidsHaveAdvancedFaces : SIZEOF (QUERY (Vsh <* Voids |
                SIZEOF (QUERY (Afs <* Vsh.CfsFaces |
                (NOT ('IFC4X2.IFCADVANCEDFACE' IN TYPEOF(Afs)))
                )) = 0
                )) = 0;
    END_ENTITY;
    """))
    assert len(e) == 62
Exemple #21
0
def test_where_rule_2():
    r = Tokens(
        type_decl.parseString("""
    TYPE IfcCompoundPlaneAngleMeasure = LIST [3:4] OF INTEGER;
        WHERE
        MinutesInRange : ABS(SELF[2]) < 60;
        SecondsInRange : ABS(SELF[3]) < 60;
        MicrosecondsInRange : (SIZEOF(SELF) = 3) OR (ABS(SELF[4]) < 1000000);
        ConsistentSign : ((SELF[1] >= 0) AND (SELF[2] >= 0) AND (SELF[3] >= 0) AND ((SIZEOF(SELF) = 3) OR (SELF[4] >= 0)))
        OR
        ((SELF[1] <= 0) AND (SELF[2] <= 0) AND (SELF[3] <= 0) AND ((SIZEOF(SELF) = 3) OR (SELF[4] <= 0)));
    END_TYPE;
    """))
    assert len(r) == 162
Exemple #22
0
def test_simple_entity_decl_2():
    e = Tokens(entity_decl.parseString("""
    ENTITY IfcActor
        SUPERTYPE OF (ONEOF(IfcOccupant))
        SUBTYPE OF (IfcObject);
            TheActor : IfcActorSelect;
            INVERSE IsActingUpon : SET [0:?] OF IfcRelAssignsToActor FOR RelatingActor;
        END_ENTITY;
    """))
    assert str(e) == "ENTITY IfcActor SUPERTYPE OF ( ONEOF ( IfcOccupant ) ) " \
                     "SUBTYPE OF ( IfcObject ) ; " \
                     "TheActor : IfcActorSelect ; " \
                     "INVERSE IsActingUpon : SET [ 0 : ? ] OF IfcRelAssignsToActor FOR RelatingActor ; " \
                     "END_ENTITY ;"
Exemple #23
0
def test_typedef_real():
    c = Tokens(
        constant_decl.parseString("""
    CONSTANT
    dummy_gri : geometric_representation_item := representation_item('') ||
                geometric_representation_item();
    dummy_tri : topological_representation_item := representation_item('')
                || topological_representation_item();
    END_CONSTANT;
    """))

    assert str(c) == "CONSTANT dummy_gri : geometric_representation_item := representation_item (  ) || " \
                     "geometric_representation_item ( ) ; " \
                     "dummy_tri : topological_representation_item := representation_item (  ) || " \
                     "topological_representation_item ( ) ; " \
                     "END_CONSTANT ;"
Exemple #24
0
def test_typedef_enum():
    t = Tokens(
        type_decl.parseString("""
    TYPE IfcActionRequestTypeEnum = ENUMERATION OF
        (EMAIL,
        FAX,
        PHONE,
        POST,
        VERBAL,
        USERDEFINED,
        NOTDEFINED);
    END_TYPE;
    """))
    assert str(t) == "TYPE IfcActionRequestTypeEnum = ENUMERATION OF " \
                     "( EMAIL , FAX , PHONE , POST , VERBAL , USERDEFINED , NOTDEFINED ) ; " \
                     "END_TYPE ;"
Exemple #25
0
def test_simple_entity_decl_4():
    e = Tokens(entity_decl.parseString("""
    ENTITY IfcAddress
        ABSTRACT SUPERTYPE OF (ONEOF
            (IfcPostalAddress
            ,IfcTelecomAddress));
        Purpose : OPTIONAL IfcAddressTypeEnum;
        Description : OPTIONAL IfcText;
        UserDefinedPurpose : OPTIONAL IfcLabel;
        INVERSE
            OfPerson : SET [0:?] OF IfcPerson FOR Addresses;
            OfOrganization : SET [0:?] OF IfcOrganization FOR Addresses;
        WHERE
            WR1 : (NOT(EXISTS(Purpose))) OR
                ((Purpose <> IfcAddressTypeEnum.USERDEFINED) OR
                ((Purpose = IfcAddressTypeEnum.USERDEFINED) AND
                EXISTS(SELF.UserDefinedPurpose)));
    END_ENTITY;
    """))
    assert len(e) == 98
Exemple #26
0
def test_simple_expression():
    r = Tokens(simple_expression.parseString('SELF'))
    assert str(r) == 'SELF'

    r = Tokens(simple_expression.parseString('1'))
    assert r[0] == 1
Exemple #27
0
def test_expression_as_function_call():
    r = Tokens(expression.parseString("ABS(SELF[2])"))
    assert str(r) == "ABS ( SELF [ 2 ] )"
Exemple #28
0
def test_primary():
    r = Tokens(primary.parseString('SELF[1]'))
    assert str(r) == 'SELF [ 1 ]'
Exemple #29
0
def test_primary_as_function_call():
    r = Tokens(primary.parseString("ABS(SELF[2])"))
    assert str(r) == "ABS ( SELF [ 2 ] )"
Exemple #30
0
def test_simple_factor_as_function_call():
    r = Tokens(simple_factor.parseString("ABS(SELF[2])"))
    assert str(r) == "ABS ( SELF [ 2 ] )"