Skip to content

Commit 61d166e

Browse files
removed create_scope
1 parent 85c7754 commit 61d166e

File tree

2 files changed

+12
-38
lines changed

2 files changed

+12
-38
lines changed

src/pathsim_utils.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ def make_labels_for_scope(node: dict, edges: list, nodes: list) -> list[str]:
109109
return labels, connections_order
110110

111111

112-
def create_scope(node: dict, edges, nodes) -> Scope:
113-
block = auto_block_construction(node, eval_namespace=globals())
114-
115-
# override labels + add connections order
116-
# TODO this should be done in "make connections"
117-
labels, connections_order = make_labels_for_scope(node, edges, nodes)
118-
block._connections_order = connections_order
119-
block.labels = labels
120-
121-
return block
122-
123-
124112
def make_global_variables(global_vars):
125113
# Validate and exec global variables so that they are usable later in this script.
126114
# Return a namespace dictionary containing the global variables
@@ -259,15 +247,15 @@ def make_blocks(
259247
blocks, events = [], []
260248

261249
for node in nodes:
262-
block_type = node["type"]
263-
264-
# TODO scope should be handled in the same way as other blocks
265-
if block_type == "scope":
266-
block = create_scope(node, edges, nodes)
267-
else:
268-
block = auto_block_construction(node, eval_namespace)
269-
if hasattr(block, "create_reset_events"):
270-
events.extend(block.create_reset_events())
250+
block = auto_block_construction(node, eval_namespace)
251+
if hasattr(block, "create_reset_events"):
252+
events.extend(block.create_reset_events())
253+
254+
if isinstance(block, Scope):
255+
if block.labels == []:
256+
block.labels, block._connections_order = make_labels_for_scope(
257+
node, edges, nodes
258+
)
271259

272260
block.id = node["id"]
273261
block.label = node["data"]["label"]

test/test_backend.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from src.pathsim_utils import (
2-
auto_block_construction,
3-
create_scope,
4-
)
1+
from src.pathsim_utils import auto_block_construction
52
from src.custom_pathsim_blocks import Process, Splitter2, Splitter3, Bubbler, Integrator
63

74
import pathsim.blocks
@@ -64,7 +61,7 @@
6461
},
6562
"scope": {
6663
"type": "scope",
67-
"data": {"label": "Scope", "sampling_rate": "", "labels": ""},
64+
"data": {"label": "scope 7", "sampling_rate": "", "labels": "", "t_wait": ""},
6865
},
6966
"white_noise": {
7067
"type": "white_noise",
@@ -136,6 +133,7 @@ def _create_node(block_type: str, id: str = "1", data_overrides: dict = None):
136133
("pink_noise", pathsim.blocks.noise.PinkNoise),
137134
("bubbler", Bubbler),
138135
("integrator", Integrator),
136+
("scope", pathsim.blocks.Scope),
139137
],
140138
)
141139
def test_auto_block_construction(node_factory, block_type, expected_class):
@@ -175,15 +173,3 @@ def test_auto_block_construction_with_var(node_factory, block_type, expected_cla
175173
break
176174
block = auto_block_construction(node, eval_namespace={"var1": 5.5})
177175
assert isinstance(block, expected_class)
178-
179-
180-
def test_make_scope():
181-
node = {
182-
"id": "7",
183-
"type": "scope",
184-
"data": {"label": "scope 7", "sampling_rate": "", "labels": "", "t_wait": ""},
185-
}
186-
block = create_scope(node, edges=[], nodes=[node])
187-
assert isinstance(block, pathsim.blocks.Scope)
188-
assert block.labels == []
189-
assert block.sampling_rate is None

0 commit comments

Comments
 (0)