Skip to content

Commit ae0e67d

Browse files
authored
FIX: Misc. fixes for pyedb unit tests. (#539)
1 parent b8a667d commit ae0e67d

File tree

16 files changed

+113
-30
lines changed

16 files changed

+113
-30
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
77
name = "ansys-edb-core"
8-
version = "0.2.0.dev3"
8+
version = "0.2.0.dev4"
99
description = "A python wrapper for Ansys Edb service"
1010
readme = "README.rst"
1111
requires-python = ">=3.8"
@@ -25,7 +25,7 @@ classifiers = [
2525

2626

2727
dependencies = [
28-
"ansys-api-edb==0.2.dev5",
28+
"ansys-api-edb==0.2.dev6",
2929
"protobuf>=3.19.3,<5",
3030
"grpcio>=1.44.0",
3131
"Django>=4.2.16"

src/ansys/edb/core/definition/component_def.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def component_models(self):
101101
This property is read-only.
102102
"""
103103
objs = self.__stub.GetComponentModels(self.msg).items
104-
return map_list(objs, component_model.ComponentModel)
104+
return map_list(objs, lambda msg: component_model.ComponentModel(msg).cast())
105105

106106
@property
107107
def component_pins(self):

src/ansys/edb/core/definition/component_model.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""Component model definition."""
2+
from enum import Enum
3+
4+
from ansys.api.edb.v1.component_model_pb2 import ComponentModelType as pb_comp_model_Type
25
from ansys.api.edb.v1.component_model_pb2_grpc import (
36
ComponentModelServiceStub,
47
DynamicLinkComponentModelServiceStub,
@@ -10,6 +13,14 @@
1013
from ansys.edb.core.session import StubAccessor, StubType
1114

1215

16+
class ComponentModelType(Enum):
17+
"""Enum representing component model types."""
18+
19+
N_PORT = pb_comp_model_Type.N_PORT
20+
DYNAMIC_LINK = pb_comp_model_Type.DYNAMIC_LINK
21+
UNKNOWN_COMPONENT_MODEL_TYPE = pb_comp_model_Type.UNKNOWN_MODEL_TYPE
22+
23+
1324
class ComponentModel(ObjBase):
1425
"""Represents a component model."""
1526

@@ -42,7 +53,7 @@ def find_by_name(cls, comp_def, value):
4253
"""
4354
return ComponentModel(
4455
cls.__stub.FindByName(messages.string_property_message(comp_def, value))
45-
)
56+
).cast()
4657

4758
@classmethod
4859
def find_by_id(cls, comp_def, value):
@@ -60,7 +71,51 @@ def find_by_id(cls, comp_def, value):
6071
ComponentModel
6172
Component model that is found, ``None`` otherwise.
6273
"""
63-
return ComponentModel(cls.__stub.FindById(messages.int_proprty_message(comp_def, value)))
74+
return ComponentModel(
75+
cls.__stub.FindById(messages.int_property_message(comp_def, value))
76+
).cast()
77+
78+
@property
79+
def name(self) -> str:
80+
""":obj:`str`: The name of the component model.
81+
82+
This property is read-only.
83+
"""
84+
return self.__stub.GetName(self.msg).value
85+
86+
@property
87+
def component_model_type(self) -> ComponentModelType:
88+
""":class:`.ComponentModelType`: The type of the component model.
89+
90+
This property is read-only.
91+
"""
92+
return ComponentModelType(self.__stub.GetType(self.msg).type)
93+
94+
@property
95+
def component_model_id(self) -> int:
96+
""":obj:`int`: The id of the component model.
97+
98+
This property is read-only.
99+
"""
100+
return self.__stub.GetId(self.msg).value
101+
102+
def cast(self) -> "ComponentModel":
103+
"""Cast the component model object to the correct concrete type.
104+
105+
Returns
106+
-------
107+
.ComponentModel
108+
"""
109+
comp_model_type = (
110+
ComponentModelType.UNKNOWN_COMPONENT_MODEL_TYPE
111+
if self.is_null
112+
else self.component_model_type
113+
)
114+
if comp_model_type == ComponentModelType.N_PORT:
115+
return NPortComponentModel(self.msg)
116+
elif comp_model_type == ComponentModelType.DYNAMIC_LINK:
117+
return DynamicLinkComponentModel(self.msg)
118+
return ComponentModel(self.msg)
64119

65120

66121
class NPortComponentModel(ComponentModel):

src/ansys/edb/core/definition/padstack_def_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,15 @@ def get_pad_parameters(self, layer, pad_type):
189189
Value(message.generic.offset_y),
190190
Value(message.generic.rotation),
191191
)
192-
else:
192+
elif message.HasField("polygon"):
193193
return (
194194
parser.to_polygon_data(message.polygon.fp),
195195
Value(message.polygon.offset_x),
196196
Value(message.polygon.offset_y),
197197
Value(message.polygon.rotation),
198198
)
199+
else:
200+
return ()
199201

200202
def set_pad_parameters(
201203
self, layer, pad_type, offset_x, offset_y, rotation, type_geom=None, sizes=None, fp=None

src/ansys/edb/core/hierarchy/group.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ansys.edb.core.edb_defs import LayoutObjType
77
from ansys.edb.core.hierarchy.hierarchy_obj import HierarchyObj
88
from ansys.edb.core.inner import messages
9+
from ansys.edb.core.inner.utils import query_lyt_object_collection
910
from ansys.edb.core.session import StubAccessor, StubType
1011

1112

@@ -113,7 +114,10 @@ def members(self):
113114
114115
This property is read-only.
115116
"""
116-
from ansys.edb.core.inner import factory
117-
118-
objs = self.__stub.GetMembers(self.msg).items
119-
return [factory.create_conn_obj(co) for co in objs]
117+
return query_lyt_object_collection(
118+
self,
119+
LayoutObjType.INVALID_LAYOUT_OBJ,
120+
self.__stub.GetMembers,
121+
self.__stub.StreamMembers,
122+
False,
123+
)

src/ansys/edb/core/inner/conn_obj.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from ansys.edb.core.edb_defs import LayoutObjType
55
from ansys.edb.core.inner import layout_obj, messages
6+
from ansys.edb.core.inner.factory import create_lyt_obj
67
from ansys.edb.core.layout import mcad_model as mm
78
from ansys.edb.core.session import ConnectableServiceStub, StubAccessor, StubType
89

@@ -48,6 +49,15 @@ def get_client_prim_type_from_class():
4849
return client_obj
4950
return cls(None)
5051

52+
def cast(self):
53+
"""Cast the ConnObj object to the correct concrete type.
54+
55+
Returns
56+
-------
57+
.ConnObj
58+
"""
59+
return create_lyt_obj(self.msg, self.obj_type)
60+
5161
@property
5262
def obj_type(self):
5363
""":class:`LayoutObjType <ansys.edb.core.edb_defs.LayoutObjType>`: Layout object type.

src/ansys/edb/core/inner/factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _initialize_type_creator_params_dict():
4343
LayoutObjType.EXTENDED_NET: _CreatorParams(ExtendedNet),
4444
LayoutObjType.DIFFERENTIAL_PAIR: _CreatorParams(DifferentialPair),
4545
LayoutObjType.NET: _CreatorParams(Net),
46-
LayoutObjType.INVALID_LAYOUT_OBJ: _CreatorParams(ConnObj),
46+
LayoutObjType.INVALID_LAYOUT_OBJ: _CreatorParams(ConnObj, True),
4747
}
4848
return _type_creator_params_dict
4949

@@ -158,4 +158,4 @@ def create_conn_obj(msg):
158158
-------
159159
ansys.edb.core.inner.ConnObj
160160
"""
161-
return create_lyt_obj(msg, create_lyt_obj(msg, LayoutObjType.INVALID_LAYOUT_OBJ).obj_type)
161+
return create_lyt_obj(msg, LayoutObjType.INVALID_LAYOUT_OBJ)

src/ansys/edb/core/inner/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,4 @@ def _to_mesh_op(message):
507507

508508
def _to_string_dict(message):
509509
"""Convert a message to a dictionary of strings."""
510-
return {key: value for (key, value) in message.string_map}
510+
return {key: value for (key, value) in message.string_map.items()}

src/ansys/edb/core/inner/rpc_info.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ def invalidates_cache(self):
197197
"GetReferenceFile": _RpcInfo(cache=True),
198198
"FindByName": _RpcInfo(cache=True),
199199
"FindById": _RpcInfo(cache=True),
200+
"GetName": _RpcInfo(cache=True),
201+
"GetType": _RpcInfo(cache=True),
202+
"GetId": _RpcInfo(cache=True),
200203
},
201204
"ansys.api.edb.v1.NPortComponentModelService": {
202205
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True)
@@ -1045,6 +1048,7 @@ def invalidates_cache(self):
10451048
"GetParameters": _RpcInfo(cache=True),
10461049
"SetParameters": _RpcInfo(buffer=True),
10471050
"Render": _RpcInfo(cache=True),
1051+
"GetPolygonData": _RpcInfo(cache=True),
10481052
},
10491053
"ansys.api.edb.v1.RLCComponentPropertyService": {
10501054
"Create": _RpcInfo(buffer=True, returns_future=True, write_no_cache_invalidation=True),

src/ansys/edb/core/primitive/padstack_instance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def set_layer_range(self, top_layer, bottom_layer):
200200
@property
201201
def solderball_layer(self):
202202
""":class:`.Layer`: Solderball layer of the padstack instance."""
203-
return Layer(self.__stub.GetSolderBallLayer(self.msg)).cast()
203+
sb_layer = Layer(self.__stub.GetSolderBallLayer(self.msg))
204+
return sb_layer if sb_layer.is_null() else sb_layer.cast()
204205

205206
@solderball_layer.setter
206207
def solderball_layer(self, solderball_layer):

src/ansys/edb/core/primitive/rectangle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ def can_be_zone_primitive(self):
162162
return True
163163

164164
@property
165+
@parser.to_polygon_data
165166
def polygon_data(self):
166167
""":class:`.PolygonData`: \
167168
Polygon data object of the rectangle.
168169
169170
This property is read-only.
170171
"""
171-
return Rectangle.render(*self.get_parameters())
172+
return self.__stub.GetPolygonData(self.msg)
172173

173174
@classmethod
174175
@parser.to_polygon_data

src/ansys/edb/core/simulation_setup/simulation_setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ def _msg_to_sweep_data(msg):
370370
"""Create a ``SweepData`` from a ``SweepDataMessage``."""
371371
freq_str_params = msg.frequency_string.split()
372372
sweep_data = SweepData(
373-
msg.name, freq_str_params[0], freq_str_params[1], freq_str_params[2], freq_str_params[3]
373+
msg.name,
374+
FrequencyData(
375+
Distribution[freq_str_params[0]],
376+
freq_str_params[1],
377+
freq_str_params[2],
378+
freq_str_params[3],
379+
),
374380
)
375381
sweep_data.enabled = msg.enabled
376382
sweep_data.type = FreqSweepType(msg.type)

src/ansys/edb/core/simulation_setup/siwave_simulation_settings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def si_slider_pos(self):
114114

115115
@si_slider_pos.setter
116116
def si_slider_pos(self, si_slider_pos):
117-
self.__stub.SetSISliderPos(messages.int_property_message(self, si_slider_pos))
117+
self.__stub.SetSISliderPos(messages.uint64_property_message(self, si_slider_pos))
118118

119119
@property
120120
def pi_slider_pos(self):
@@ -123,7 +123,7 @@ def pi_slider_pos(self):
123123

124124
@pi_slider_pos.setter
125125
def pi_slider_pos(self, pi_slider_pos):
126-
self.__stub.SetPISliderPos(messages.int_property_message(self, pi_slider_pos))
126+
self.__stub.SetPISliderPos(messages.uint64_property_message(self, pi_slider_pos))
127127

128128

129129
class SIWaveAdvancedSettings(SimulationSettingsBase):
@@ -388,7 +388,7 @@ def dc_slider_pos(self):
388388

389389
@dc_slider_pos.setter
390390
def dc_slider_pos(self, dc_slider_pos):
391-
self.__stub.SetDCSliderPos(messages.int_property_message(self, dc_slider_pos))
391+
self.__stub.SetDCSliderPos(messages.uint64_property_message(self, dc_slider_pos))
392392

393393

394394
class SIWaveDCAdvancedSettings(SimulationSettingsBase):
@@ -449,7 +449,7 @@ def max_num_passes(self):
449449

450450
@max_num_passes.setter
451451
def max_num_passes(self, max_num_passes):
452-
self.__stub.SetMaxNumPasses(messages.int_property_message(self, max_num_passes))
452+
self.__stub.SetMaxNumPasses(messages.uint64_property_message(self, max_num_passes))
453453

454454
@property
455455
def min_num_passes(self):
@@ -458,7 +458,7 @@ def min_num_passes(self):
458458

459459
@min_num_passes.setter
460460
def min_num_passes(self, min_num_passes):
461-
self.__stub.SetMinNumPasses(messages.int_property_message(self, min_num_passes))
461+
self.__stub.SetMinNumPasses(messages.uint64_property_message(self, min_num_passes))
462462

463463
@property
464464
def percent_local_refinement(self):
@@ -468,7 +468,7 @@ def percent_local_refinement(self):
468468
@percent_local_refinement.setter
469469
def percent_local_refinement(self, percent_local_refinement):
470470
self.__stub.SetPercentLocalRefinement(
471-
messages.int_property_message(self, percent_local_refinement)
471+
messages.uint64_property_message(self, percent_local_refinement)
472472
)
473473

474474
@property
@@ -523,7 +523,7 @@ def num_bw_sides(self):
523523

524524
@num_bw_sides.setter
525525
def num_bw_sides(self, num_bw_sides):
526-
self.__stub.SetNumBwSides(messages.int_property_message(self, num_bw_sides))
526+
self.__stub.SetNumBwSides(messages.uint64_property_message(self, num_bw_sides))
527527

528528
@property
529529
def num_via_sides(self):
@@ -532,7 +532,7 @@ def num_via_sides(self):
532532

533533
@num_via_sides.setter
534534
def num_via_sides(self, num_via_sides):
535-
self.__stub.SetNumViaSides(messages.int_property_message(self, num_via_sides))
535+
self.__stub.SetNumViaSides(messages.uint64_property_message(self, num_via_sides))
536536

537537

538538
class SIWaveSParameterSettings(SimulationSettingsBase):

src/ansys/edb/core/terminal/bundle_terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create(cls, terminals):
2828
@property
2929
def terminals(self):
3030
""":obj:`list` of Terminal: All terminals grouped in the terminal."""
31-
return [Terminal(msg).cast() for msg in self.__stub.GetTerminals(self.msg)]
31+
return [Terminal(msg).cast() for msg in self.__stub.GetTerminals(self.msg).items]
3232

3333
def ungroup(self):
3434
"""Delete the grouping."""

src/ansys/edb/core/terminal/edge_terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _create(cls, **params):
4646

4747
@property
4848
def _type(self):
49-
return EdgeType(self.__stub.GetType(self.msg))
49+
return EdgeType(self.__stub.GetEdgeType(self.msg).t)
5050

5151
@property
5252
def _params(self):
@@ -163,7 +163,7 @@ def create(cls, layout, name, edges, net=None, is_ref=False):
163163
@property
164164
def edges(self):
165165
""":obj:`list` of :class:`.Edge`: All edges on the terminal."""
166-
return [Edge(msg).cast() for msg in self.__stub.GetEdges(self.msg)]
166+
return [Edge(msg).cast() for msg in self.__stub.GetEdges(self.msg).items]
167167

168168
@edges.setter
169169
def edges(self, edges):

tests/mock/test_terminals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ansys.api.edb.v1.layer_pb2 as layer_pb2
22
import ansys.api.edb.v1.term_pb2 as term_pb2
33
from utils.fixtures import * # noqa
4-
from utils.test_utils import create_edb_obj_msgs, equals
4+
from utils.test_utils import create_edb_obj_collection_msg, equals
55

66
from ansys.edb.core.geometry.point_data import PointData
77
from ansys.edb.core.inner import messages
@@ -68,7 +68,7 @@ def test_bundle_terminal_get_terminals(mocked_stub, bundle_terminal, term_type,
6868
get_terminals = mocked_stub(
6969
bundle_terminal_mod, bundle_terminal_mod.BundleTerminal
7070
).GetTerminals
71-
get_terminals.return_value = expected = create_edb_obj_msgs(2)
71+
get_terminals.return_value = expected = create_edb_obj_collection_msg(2)
7272
get_params = mocked_stub(terminal_mod, terminal_mod.Terminal).GetParams
7373
get_params.return_value = term_pb2.TermParamsMessage(term_type=term_type)
7474

@@ -79,7 +79,7 @@ def test_bundle_terminal_get_terminals(mocked_stub, bundle_terminal, term_type,
7979
assert len(terms) == 2
8080
for t in terms:
8181
assert isinstance(t, term_cls)
82-
assert sorted([t.id for t in terms]) == sorted([msg.id for msg in expected])
82+
assert sorted([t.id for t in terms]) == sorted([msg.id for msg in expected.items])
8383

8484

8585
def test_bundle_terminal_ungroup(mocked_stub, bundle_terminal):

0 commit comments

Comments
 (0)