Skip to content

Commit

Permalink
Bump version 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjhenry committed May 27, 2024
1 parent 3b7e1bf commit a022534
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/expr_access/case_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
# the selector is a local variable, dump the name
output('switch: %s\n' % ex.switch.path.name)
# the parameters are local variables, dump the pairs
output('cases: {%s}\n' % ','.join(['%s: %s' % (v, f.path.name) for v, f in ex.cases]))
output('cases: {%s}\n' % ','.join(['%s: %s' % (v.value, f.path.name) for v, f in ex.cases]))
# the default is a local variable, dump the name
output('default: %s\n' % ex.default.path.name)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name="ansys-scade-apitools"
version="0.4.0"
version="0.4.1"
description ="An extension library for SCADE Python APIs."
readme="README.rst"

Expand Down
1 change: 0 additions & 1 deletion src/ansys/scade/apitools/expr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

"""Provides a collection of functions for the accessing the expressions."""


# ignore F401: functions made available for modules, not used here
from .access import ( # noqa: F401
ActivateNoInitOp,
Expand Down
13 changes: 7 additions & 6 deletions src/ansys/scade/apitools/expr/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from __future__ import annotations

from collections import namedtuple
from typing import Optional

import scade.model.suite as suite

Expand Down Expand Up @@ -887,7 +888,7 @@ def __init__(self, expression: suite.ExprCall):
super().__init__(expression)
self._switch = accessor(expression.parameters[0])
flows = [accessor(_) for _ in expression.parameters[1].parameters]
patterns = [_.value for _ in expression.parameters[2].parameters]
patterns = [accessor(_) for _ in expression.parameters[2].parameters]
self._default = flows.pop() if len(flows) > len(patterns) else None
self._cases: list = [(pattern, flow) for pattern, flow in zip(patterns, flows)]

Expand All @@ -897,12 +898,12 @@ def switch(self) -> Expression:
return self._switch

@property
def cases(self) -> list[tuple[str, Expression]]:
"""Pairs (``str``, :class:`~Expression`) to build the structure."""
def cases(self) -> list[tuple[Expression, Expression]]:
"""Pairs (:class:`~Expression`, :class:`~Expression`) to build the case."""
return self._cases

@property
def default(self) -> Expression:
def default(self) -> Optional[Expression]:
"""Value to use as default when not ``None``."""
return self._default

Expand Down Expand Up @@ -1224,7 +1225,7 @@ def size(self) -> Expression:

# TODO CREATE: mapfold with N accumulators...
@property
def accumulator_count(self) -> Expression:
def accumulator_count(self) -> Optional[Expression]:
"""Number of accumulators when suitable, otherwise ``None``."""
return self._accumulator_count

Expand Down Expand Up @@ -1264,7 +1265,7 @@ def if_(self) -> Expression:
return self._if

@property
def defaults(self) -> list[Expression]:
def defaults(self) -> Optional[list[Expression]]:
"""Default values when suitable, otherwise ``None``."""
return self._defaults

Expand Down
27 changes: 24 additions & 3 deletions tests/resources/ExprAccess/ExprAccess.xscade
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@
<ed:Type oid="!ed/3d0/1885/35A4/643d1bde52bf"/>
</pragmas>
</Type>
<Type name="Enumeration">
<definition>
<Enum>
<values>
<Value name="VALUE1">
<pragmas>
<ed:Value oid="!ed/620/6F59/84B4/665431f83006"/>
</pragmas>
</Value>
<Value name="VALUE2">
<pragmas>
<ed:Value oid="!ed/627/6F59/84B4/6654320049ea"/>
</pragmas>
</Value>
</values>
</Enum>
</definition>
<pragmas>
<ed:Type oid="!ed/61f/6F59/84B4/665431ec6dd9"/>
</pragmas>
</Type>
<Operator kind="node" name="ExprId">
<inputs>
<Variable name="variable">
Expand Down Expand Up @@ -4879,13 +4900,13 @@
<ed:Equation oid="!ed/7a2/6922/880C/6439340b7765"/>
</pragmas>
</Equation>
<!-- caseOp = ( case flowSwitch of | 1 : flowCase1 | 2 : flowCase2 | _ : flowDe... -->
<!-- caseOp = ( case flowSwitch of | 1 : flowCase1 | VALUE1 : flowCase2 | _ : f... -->
<Equation>
<lefts>
<VariableRef name="caseOp"/>
</lefts>
<right>
<!-- ( case flowSwitch of | 1 : flowCase1 | 2 : flowCase2 | _ : flowDefault) -->
<!-- ( case flowSwitch of | 1 : flowCase1 | VALUE1 : flowCase2 | _ : flowDefaul... -->
<CaseOp name="1">
<switch>
<IdExpression>
Expand All @@ -4904,7 +4925,7 @@
</IdExpression>
</flow>
</Case>
<Case pattern="2">
<Case pattern="VALUE1">
<flow>
<IdExpression>
<path>
Expand Down
10 changes: 8 additions & 2 deletions tests/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,14 @@ def test_case_op(model):
assert expression.expression == equation.right
assert isinstance(expression, expr.CaseOp)
assert expression.switch.path.name == 'flowSwitch'
cases = [(pattern, flow.path.name) for pattern, flow in expression.cases]
assert cases == [('1', 'flowCase1'), ('2', 'flowCase2')]
cases = [
(
(pattern.value if isinstance(pattern, expr.ConstValue) else pattern.path.name),
flow.path.name,
)
for pattern, flow in expression.cases
]
assert cases == [('1', 'flowCase1'), ('VALUE1', 'flowCase2')]
assert expression.default.path.name == 'flowDefault'


Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@


def test_pkg_version():
assert __version__ == "0.4.0"
assert __version__ == "0.4.1"

0 comments on commit a022534

Please sign in to comment.