xstack 2.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1314 @@
1
+ import os
2
+ import json
3
+ import tempfile
4
+ import unittest
5
+ import xstack
6
+
7
+ COMPONENT_PATH = os.path.join(
8
+ os.path.dirname(__file__),
9
+ )
10
+
11
+ class TestUnitStack(unittest.TestCase):
12
+ counter = 0
13
+ def setUp(self):
14
+ pass
15
+
16
+ def tearDown(self):
17
+ pass
18
+
19
+ def test_can_instance_stack(self):
20
+
21
+ stack = xstack.Stack()
22
+
23
+ self.assertIsNotNone(stack)
24
+
25
+ def test_can_find_components(self):
26
+
27
+ stack = xstack.Stack(
28
+ component_paths=[COMPONENT_PATH],
29
+ )
30
+
31
+ self.assertGreater(
32
+ len(stack.component_library.plugins()),
33
+ 0,
34
+ )
35
+
36
+ def test_can_add_component(self):
37
+
38
+ stack = xstack.Stack(
39
+ component_paths=[COMPONENT_PATH],
40
+ )
41
+
42
+ component = stack.add_component(
43
+ label="test",
44
+ component_type="MinimalComponent",
45
+ )
46
+
47
+ self.assertIsNotNone(component)
48
+
49
+ self.assertIn(
50
+ component,
51
+ stack.components(),
52
+ )
53
+
54
+ def test_can_remove_component(self):
55
+
56
+ stack = xstack.Stack(
57
+ component_paths=[COMPONENT_PATH],
58
+ )
59
+
60
+ component = stack.add_component(
61
+ label="test",
62
+ component_type="MinimalComponent",
63
+ )
64
+
65
+ stack.remove_component(component)
66
+
67
+ self.assertNotIn(
68
+ component,
69
+ stack.components(),
70
+ )
71
+
72
+ def test_can_build_stack(self):
73
+
74
+ stack = xstack.Stack(
75
+ component_paths=[COMPONENT_PATH],
76
+ )
77
+
78
+ test_component = stack.component_library.request("RunTestComponent")
79
+ test_component.RUN_ORDER = []
80
+
81
+ component = stack.add_component(
82
+ label="test",
83
+ component_type="RunTestComponent",
84
+ )
85
+
86
+ stack.build()
87
+
88
+ self.assertGreater(
89
+ len(test_component.RUN_ORDER),
90
+ 0,
91
+ )
92
+
93
+ def test_basic_build_order_stack(self):
94
+
95
+ stack = xstack.Stack(
96
+ component_paths=[COMPONENT_PATH],
97
+ )
98
+
99
+ test_component = stack.component_library.request("RunTestComponent")
100
+ test_component.RUN_ORDER = []
101
+
102
+ component_a = stack.add_component(
103
+ label="test",
104
+ component_type="RunTestComponent",
105
+ )
106
+
107
+ component_b = stack.add_component(
108
+ label="test",
109
+ component_type="RunTestComponent",
110
+ )
111
+
112
+ stack.build()
113
+
114
+ self.assertEqual(
115
+ component_a,
116
+ test_component.RUN_ORDER[0],
117
+ )
118
+
119
+ self.assertEqual(
120
+ component_b,
121
+ test_component.RUN_ORDER[1],
122
+ )
123
+
124
+ def test_adjust_build_order_stack(self):
125
+
126
+ stack = xstack.Stack(
127
+ component_paths=[COMPONENT_PATH],
128
+ )
129
+
130
+ test_component = stack.component_library.request("RunTestComponent")
131
+ test_component.RUN_ORDER = []
132
+
133
+ component_a = stack.add_component(
134
+ label="test a",
135
+ component_type="RunTestComponent",
136
+ )
137
+
138
+ component_b = stack.add_component(
139
+ label="test b",
140
+ component_type="RunTestComponent",
141
+ )
142
+
143
+ component_a.set_parent(
144
+ parent=None,
145
+ child_index=1
146
+ )
147
+
148
+ stack.build()
149
+
150
+ self.assertEqual(
151
+ component_b,
152
+ test_component.RUN_ORDER[0],
153
+ )
154
+
155
+ self.assertEqual(
156
+ component_a,
157
+ test_component.RUN_ORDER[1],
158
+ )
159
+
160
+ def test_adjust_build_parent_stack(self):
161
+
162
+ stack = xstack.Stack(
163
+ component_paths=[COMPONENT_PATH],
164
+ )
165
+
166
+ test_component = stack.component_library.request("RunTestComponent")
167
+ test_component.RUN_ORDER = []
168
+
169
+ component_a = stack.add_component(
170
+ label="test a",
171
+ component_type="RunTestComponent",
172
+ )
173
+
174
+ component_b = stack.add_component(
175
+ label="test b",
176
+ component_type="RunTestComponent",
177
+ )
178
+
179
+ component_a.set_parent(parent=component_b)
180
+
181
+ stack.build()
182
+
183
+ self.assertEqual(
184
+ component_b,
185
+ test_component.RUN_ORDER[0],
186
+ )
187
+
188
+ self.assertEqual(
189
+ component_a,
190
+ test_component.RUN_ORDER[1],
191
+ )
192
+
193
+ def test_invalid_component(self):
194
+
195
+ stack = xstack.Stack(
196
+ component_paths=[COMPONENT_PATH],
197
+ )
198
+
199
+ stack.add_component(label="", component_type="InvalidComponent")
200
+
201
+ result = stack.build()
202
+
203
+ self.assertFalse(result)
204
+
205
+ def test_invalid_requirement(self):
206
+
207
+ stack = xstack.Stack(
208
+ component_paths=[COMPONENT_PATH],
209
+ )
210
+
211
+ stack.add_component(label="", component_type="ComponentWithExpectedRequirementNotSet")
212
+
213
+ result = stack.build()
214
+
215
+ self.assertFalse(result)
216
+
217
+ def test_valid_input(self):
218
+
219
+ stack = xstack.Stack(
220
+ component_paths=[COMPONENT_PATH],
221
+ )
222
+
223
+ component = stack.add_component(label="", component_type="ComponentWithExpectedRequirementNotSet")
224
+
225
+ component.input("expected_requirement").set(True)
226
+
227
+ result = stack.build()
228
+
229
+ self.assertTrue(result)
230
+
231
+ def test_not_executed_status(self):
232
+ stack = xstack.Stack(
233
+ component_paths=[COMPONENT_PATH],
234
+ )
235
+
236
+ component = stack.add_component(
237
+ label="",
238
+ component_type="MinimalComponent",
239
+ )
240
+
241
+ self.assertEqual(
242
+ component.status(),
243
+ xstack.constants.Status.NotExecuted,
244
+ )
245
+
246
+ def test_executed_successfully_status(self):
247
+ stack = xstack.Stack(
248
+ component_paths=[COMPONENT_PATH],
249
+ )
250
+
251
+ component = stack.add_component(
252
+ label="",
253
+ component_type="MinimalComponent",
254
+ )
255
+ stack.build()
256
+
257
+ self.assertEqual(
258
+ component.status(),
259
+ xstack.constants.Status.Success,
260
+ )
261
+
262
+ def test_execution_failed_status(self):
263
+ stack = xstack.Stack(
264
+ component_paths=[COMPONENT_PATH],
265
+ )
266
+
267
+ component = stack.add_component(
268
+ label="",
269
+ component_type="FailingComponent",
270
+ )
271
+ stack.build()
272
+
273
+ self.assertEqual(
274
+ component.status(),
275
+ xstack.constants.Status.Failed,
276
+ )
277
+
278
+ def test_invalid_status(self):
279
+ stack = xstack.Stack(
280
+ component_paths=[COMPONENT_PATH],
281
+ )
282
+
283
+ component = stack.add_component(
284
+ label="",
285
+ component_type="ComponentWithExpectedRequirementNotSet",
286
+ )
287
+ stack.build()
288
+
289
+ self.assertEqual(
290
+ component.status(),
291
+ xstack.constants.Status.Invalid,
292
+ )
293
+
294
+ def test_option_setting(self):
295
+ stack = xstack.Stack(
296
+ component_paths=[COMPONENT_PATH],
297
+ )
298
+
299
+ component = stack.add_component(
300
+ label="",
301
+ component_type="ComponentWithOption",
302
+ )
303
+
304
+ component.option("test_option").set("bar")
305
+
306
+ result = stack.build()
307
+
308
+ self.assertTrue(
309
+ result
310
+ )
311
+
312
+ def test_progression(self):
313
+ self._reset_counter()
314
+
315
+ stack = xstack.Stack(
316
+ component_paths=[COMPONENT_PATH],
317
+ )
318
+
319
+ for i in range(1, 10):
320
+ stack.add_component(
321
+ label="",
322
+ component_type="ComponentWithOption",
323
+ options={"test_option": "bar"},
324
+ )
325
+
326
+ stack.build_progressed.connect(self._increment_counter)
327
+ result = stack.build()
328
+
329
+ self.assertEqual(
330
+ self.counter,
331
+ 10,
332
+ )
333
+
334
+ def _reset_counter(self):
335
+ counter = 0
336
+
337
+ def _increment_counter(self, *args, **kwargs):
338
+ self.counter += 1
339
+
340
+
341
+ # ------------------------------------------------------------------------------
342
+ class TestDuplicate(unittest.TestCase):
343
+ """
344
+ Tests for Component.duplicate, in particular that each duplicate is
345
+ parented under its final parent before its on_enter_stack runs.
346
+ """
347
+
348
+ def _make_nested(self):
349
+ stack = xstack.Stack(component_paths=[COMPONENT_PATH])
350
+ top = stack.add_component(label="Top LF", component_type="ParentHookingComponent")
351
+ middle = stack.add_component(label="Middle LF", component_type="ParentHookingComponent", parent=top)
352
+ bottom = stack.add_component(label="Bottom LF", component_type="ParentHookingComponent", parent=middle)
353
+ return stack, top, middle, bottom
354
+
355
+ def test_duplicate_is_sibling_by_default(self):
356
+ stack, top, middle, bottom = self._make_nested()
357
+ root = stack.add_component(label="Root", component_type="MinimalComponent")
358
+ top.set_parent(root)
359
+
360
+ duplicate = top.duplicate()
361
+
362
+ self.assertIs(duplicate.parent, root)
363
+ self.assertIs(duplicate.parent_on_enter, root)
364
+
365
+ def test_children_enter_stack_under_the_duplicated_parent(self):
366
+ stack, top, middle, bottom = self._make_nested()
367
+
368
+ top_twin = top.duplicate(search_for="LF", replace_with="RT")
369
+ middle_twin = top_twin.children[0]
370
+ bottom_twin = middle_twin.children[0]
371
+
372
+ self.assertEqual(
373
+ [top_twin.label(), middle_twin.label(), bottom_twin.label()],
374
+ ["Top RT", "Middle RT", "Bottom RT"],
375
+ )
376
+
377
+ # -- Each duplicate saw its duplicated parent when it entered the stack
378
+ self.assertIs(middle_twin.parent_on_enter, top_twin)
379
+ self.assertIs(bottom_twin.parent_on_enter, middle_twin)
380
+
381
+ # -- So hooking to the parent connects to the duplicated parent
382
+ self.assertEqual(middle_twin.input("Parent").get(resolved=False), "[Top RT].[output].[Control]")
383
+ self.assertEqual(bottom_twin.input("Parent").get(resolved=False), "[Middle RT].[output].[Control]")
384
+
385
+ # -- The originals are untouched
386
+ self.assertEqual(top.children, [middle])
387
+ self.assertEqual(middle.children, [bottom])
388
+ self.assertEqual(middle.input("Parent").get(resolved=False), "[Top LF].[output].[Control]")
389
+
390
+ def test_duplicate_under_an_explicit_parent(self):
391
+ stack, top, middle, bottom = self._make_nested()
392
+ other = stack.add_component(label="Other", component_type="ParentHookingComponent")
393
+
394
+ duplicate = middle.duplicate(parent=other)
395
+
396
+ self.assertIs(duplicate.parent, other)
397
+ self.assertIs(duplicate.parent_on_enter, other)
398
+ self.assertIs(duplicate.children[0].parent_on_enter, duplicate)
399
+ self.assertNotIn(duplicate, top.children)
400
+
401
+ def test_duplicate_without_children(self):
402
+ stack, top, middle, bottom = self._make_nested()
403
+
404
+ duplicate = middle.duplicate(include_children=False)
405
+
406
+ self.assertEqual(duplicate.children, [])
407
+ self.assertIs(duplicate.parent, top)
408
+
409
+
410
+ # ------------------------------------------------------------------------------
411
+ class TestAdditionalData(unittest.TestCase):
412
+ """
413
+ Tests for the on_serialise / on_deserialise hooks.
414
+ """
415
+
416
+ def setUp(self):
417
+ self.tmp_dir = tempfile.TemporaryDirectory()
418
+
419
+ def tearDown(self):
420
+ self.tmp_dir.cleanup()
421
+
422
+ def _make_stack(self):
423
+ return xstack.Stack(component_paths=[COMPONENT_PATH])
424
+
425
+ def _make_tree(self, stack):
426
+ root = stack.add_component(label="root", component_type="AdditionalDataComponent")
427
+ child = stack.add_component(label="child", component_type="AdditionalDataComponent", parent=root)
428
+ root.payload = {"name": "root", "values": [1, 2, 3]}
429
+ child.payload = {"name": "child"}
430
+ return root, child
431
+
432
+ def test_serialise_includes_additional_data(self):
433
+ stack = self._make_stack()
434
+ root, child = self._make_tree(stack)
435
+
436
+ data = stack.serialise()
437
+
438
+ self.assertEqual(data["tree"][0]["additional_data"], {"name": "root", "values": [1, 2, 3]})
439
+ self.assertEqual(data["tree"][0]["children"][0]["additional_data"], {"name": "child"})
440
+
441
+ def test_deserialise_passes_additional_data_back(self):
442
+ stack = self._make_stack()
443
+ self._make_tree(stack)
444
+ data = stack.serialise()
445
+
446
+ loaded = self._make_stack()
447
+ loaded.deserialise(data)
448
+
449
+ root = loaded.root_components[0]
450
+ self.assertEqual(root.received, {"name": "root", "values": [1, 2, 3]})
451
+ self.assertEqual(root.children[0].received, {"name": "child"})
452
+
453
+ def test_on_deserialise_runs_before_children_are_added(self):
454
+ stack = self._make_stack()
455
+ self._make_tree(stack)
456
+ data = stack.serialise()
457
+
458
+ children_when_called = []
459
+ original = xstack.Component.deserialise_additional_data
460
+
461
+ def record(component, additional_data):
462
+ children_when_called.append((component.label(), len(component.children)))
463
+ return original(component, additional_data)
464
+
465
+ xstack.Component.deserialise_additional_data = record
466
+ try:
467
+ self._make_stack().deserialise(data)
468
+ finally:
469
+ xstack.Component.deserialise_additional_data = original
470
+
471
+ self.assertEqual(children_when_called, [("root", 0), ("child", 0)])
472
+
473
+ def test_missing_additional_data_gives_an_empty_dictionary(self):
474
+ stack = self._make_stack()
475
+ self._make_tree(stack)
476
+ data = stack.serialise()
477
+
478
+ # -- Data saved before this was supported has no additional_data
479
+ del data["tree"][0]["additional_data"]
480
+ del data["tree"][0]["children"][0]["additional_data"]
481
+
482
+ loaded = self._make_stack()
483
+ loaded.deserialise(data)
484
+
485
+ self.assertEqual(loaded.root_components[0].received, {})
486
+ self.assertEqual(loaded.root_components[0].children[0].received, {})
487
+
488
+ def test_failing_hooks_do_not_break_serialising_or_loading(self):
489
+ stack = self._make_stack()
490
+ stack.add_component(label="failing", component_type="FailingAdditionalDataComponent")
491
+ good = stack.add_component(label="good", component_type="AdditionalDataComponent")
492
+ good.payload = {"kept": True}
493
+
494
+ data = stack.serialise()
495
+ self.assertEqual(data["tree"][0]["additional_data"], {})
496
+
497
+ loaded = self._make_stack()
498
+ loaded.deserialise(data)
499
+
500
+ self.assertEqual(len(loaded.components()), 2)
501
+ self.assertEqual(loaded.root_components[1].received, {"kept": True})
502
+
503
+ def test_import_subtree_passes_additional_data(self):
504
+ stack = self._make_stack()
505
+ root, child = self._make_tree(stack)
506
+ filepath = os.path.join(self.tmp_dir.name, "subtree.json")
507
+ root.save_settings(filepath)
508
+
509
+ target_stack = self._make_stack()
510
+ target = target_stack.add_component(label="target", component_type="MinimalComponent")
511
+ target.import_subtree(filepath)
512
+
513
+ imported = target.children[0]
514
+ self.assertEqual(imported.received, {"name": "root", "values": [1, 2, 3]})
515
+ self.assertEqual(imported.children[0].received, {"name": "child"})
516
+
517
+ def test_load_settings_passes_additional_data(self):
518
+ stack = self._make_stack()
519
+ root, child = self._make_tree(stack)
520
+ filepath = os.path.join(self.tmp_dir.name, "settings.json")
521
+ child.save_settings(filepath)
522
+
523
+ other = self._make_stack().add_component(label="other", component_type="AdditionalDataComponent")
524
+ other.load_settings(filepath)
525
+
526
+ self.assertEqual(other.received, {"name": "child"})
527
+
528
+
529
+ # ------------------------------------------------------------------------------
530
+ class TestImportSubtree(unittest.TestCase):
531
+ """
532
+ Tests for Stack.import_subtree_under and Component.import_subtree —
533
+ the save-subset-then-load-under-a-parent workflow.
534
+ """
535
+
536
+ def setUp(self):
537
+ # -- A temp directory for any JSON files written by these tests.
538
+ self._tmpdir = tempfile.TemporaryDirectory()
539
+ self.tmp_path = self._tmpdir.name
540
+
541
+ def tearDown(self):
542
+ self._tmpdir.cleanup()
543
+
544
+ # --------------------------------------------------------------------------
545
+ # Helpers
546
+ # --------------------------------------------------------------------------
547
+
548
+ def _make_stack(self):
549
+ return xstack.Stack(component_paths=[COMPONENT_PATH])
550
+
551
+ def _tmp_json(self, name="subtree.json"):
552
+ return os.path.join(self.tmp_path, name)
553
+
554
+ # --------------------------------------------------------------------------
555
+ # Single-component export → import-under-parent
556
+ # --------------------------------------------------------------------------
557
+
558
+ def test_import_subtree_under_adds_loaded_component_as_child(self):
559
+ # -- Set up source stack with one component to export
560
+ source_stack = self._make_stack()
561
+ source_component = source_stack.add_component(
562
+ label="source_component",
563
+ component_type="MinimalComponent",
564
+ )
565
+
566
+ filepath = self._tmp_json()
567
+ source_component.save_settings(filepath)
568
+
569
+ # -- Set up destination stack with a target parent
570
+ dest_stack = self._make_stack()
571
+ target_parent = dest_stack.add_component(
572
+ label="target_parent",
573
+ component_type="MinimalComponent",
574
+ )
575
+
576
+ # -- Import
577
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
578
+
579
+ # -- Target should now have exactly one child with the source label
580
+ self.assertEqual(len(target_parent.children), 1)
581
+ self.assertEqual(target_parent.children[0].label(), "source_component")
582
+
583
+ def test_import_subtree_regenerates_uuid(self):
584
+ source_stack = self._make_stack()
585
+ source_component = source_stack.add_component(
586
+ label="source_component",
587
+ component_type="MinimalComponent",
588
+ )
589
+ source_uuid = source_component.uuid()
590
+
591
+ filepath = self._tmp_json()
592
+ source_component.save_settings(filepath)
593
+
594
+ dest_stack = self._make_stack()
595
+ target_parent = dest_stack.add_component(
596
+ label="target_parent",
597
+ component_type="MinimalComponent",
598
+ )
599
+
600
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
601
+
602
+ imported = target_parent.children[0]
603
+ self.assertNotEqual(
604
+ imported.uuid(),
605
+ source_uuid,
606
+ "Imported component must get a fresh UUID, not the source's UUID.",
607
+ )
608
+
609
+ def test_import_subtree_preserves_option_values(self):
610
+ source_stack = self._make_stack()
611
+ source_component = source_stack.add_component(
612
+ label="source_component",
613
+ component_type="ComponentWithOption",
614
+ )
615
+ source_component.option("test_option").set("custom_value")
616
+
617
+ filepath = self._tmp_json()
618
+ source_component.save_settings(filepath)
619
+
620
+ dest_stack = self._make_stack()
621
+ target_parent = dest_stack.add_component(
622
+ label="target_parent",
623
+ component_type="MinimalComponent",
624
+ )
625
+
626
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
627
+
628
+ imported = target_parent.children[0]
629
+ self.assertEqual(
630
+ imported.option("test_option").get(),
631
+ "custom_value",
632
+ )
633
+
634
+ def test_import_subtree_preserves_input_values(self):
635
+ source_stack = self._make_stack()
636
+ source_component = source_stack.add_component(
637
+ label="source_component",
638
+ component_type="ComponentWithExpectedRequirementSet",
639
+ )
640
+ source_component.input("expected_requirement").set(42)
641
+
642
+ filepath = self._tmp_json()
643
+ source_component.save_settings(filepath)
644
+
645
+ dest_stack = self._make_stack()
646
+ target_parent = dest_stack.add_component(
647
+ label="target_parent",
648
+ component_type="MinimalComponent",
649
+ )
650
+
651
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
652
+
653
+ imported = target_parent.children[0]
654
+ self.assertEqual(
655
+ imported.input("expected_requirement").get(),
656
+ 42,
657
+ )
658
+
659
+ def test_import_subtree_preserves_disabled_state(self):
660
+ source_stack = self._make_stack()
661
+ source_component = source_stack.add_component(
662
+ label="source_component",
663
+ component_type="MinimalComponent",
664
+ )
665
+ source_component.set_enabled(False)
666
+
667
+ filepath = self._tmp_json()
668
+ source_component.save_settings(filepath)
669
+
670
+ dest_stack = self._make_stack()
671
+ target_parent = dest_stack.add_component(
672
+ label="target_parent",
673
+ component_type="MinimalComponent",
674
+ )
675
+
676
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
677
+
678
+ imported = target_parent.children[0]
679
+ self.assertFalse(imported.is_enabled())
680
+
681
+ # --------------------------------------------------------------------------
682
+ # Recursive subtree
683
+ # --------------------------------------------------------------------------
684
+
685
+ def test_import_subtree_preserves_child_hierarchy(self):
686
+ # -- Build a 3-deep subtree on the source side
687
+ source_stack = self._make_stack()
688
+ root = source_stack.add_component(
689
+ label="root",
690
+ component_type="MinimalComponent",
691
+ )
692
+ child = source_stack.add_component(
693
+ label="child",
694
+ component_type="MinimalComponent",
695
+ parent=root,
696
+ )
697
+ grandchild = source_stack.add_component(
698
+ label="grandchild",
699
+ component_type="MinimalComponent",
700
+ parent=child,
701
+ )
702
+
703
+ filepath = self._tmp_json()
704
+ root.save_settings(filepath)
705
+
706
+ # -- Import into a fresh stack
707
+ dest_stack = self._make_stack()
708
+ target_parent = dest_stack.add_component(
709
+ label="target_parent",
710
+ component_type="MinimalComponent",
711
+ )
712
+
713
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
714
+
715
+ imported_root = target_parent.children[0]
716
+ self.assertEqual(imported_root.label(), "root")
717
+ self.assertEqual(len(imported_root.children), 1)
718
+
719
+ imported_child = imported_root.children[0]
720
+ self.assertEqual(imported_child.label(), "child")
721
+ self.assertEqual(len(imported_child.children), 1)
722
+
723
+ imported_grandchild = imported_child.children[0]
724
+ self.assertEqual(imported_grandchild.label(), "grandchild")
725
+ self.assertEqual(len(imported_grandchild.children), 0)
726
+
727
+ def test_import_subtree_regenerates_uuids_through_full_depth(self):
728
+ source_stack = self._make_stack()
729
+ root = source_stack.add_component(
730
+ label="root",
731
+ component_type="MinimalComponent",
732
+ )
733
+ child = source_stack.add_component(
734
+ label="child",
735
+ component_type="MinimalComponent",
736
+ parent=root,
737
+ )
738
+
739
+ source_uuids = {root.uuid(), child.uuid()}
740
+
741
+ filepath = self._tmp_json()
742
+ root.save_settings(filepath)
743
+
744
+ dest_stack = self._make_stack()
745
+ target_parent = dest_stack.add_component(
746
+ label="target_parent",
747
+ component_type="MinimalComponent",
748
+ )
749
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
750
+
751
+ imported_uuids = {
752
+ target_parent.children[0].uuid(),
753
+ target_parent.children[0].children[0].uuid(),
754
+ }
755
+
756
+ self.assertEqual(
757
+ len(source_uuids & imported_uuids),
758
+ 0,
759
+ "No imported component should share a UUID with the source.",
760
+ )
761
+
762
+ # --------------------------------------------------------------------------
763
+ # parent=None case
764
+ # --------------------------------------------------------------------------
765
+
766
+ def test_import_subtree_under_none_parent_adds_as_root_components(self):
767
+ source_stack = self._make_stack()
768
+ source_component = source_stack.add_component(
769
+ label="source_component",
770
+ component_type="MinimalComponent",
771
+ )
772
+
773
+ filepath = self._tmp_json()
774
+ source_component.save_settings(filepath)
775
+
776
+ dest_stack = self._make_stack()
777
+ # -- Destination stack starts empty
778
+ self.assertEqual(len(dest_stack.root_components), 0)
779
+
780
+ dest_stack.import_subtree_under(parent=None, filepath=filepath)
781
+
782
+ # -- The imported component should now be a root component
783
+ self.assertEqual(len(dest_stack.root_components), 1)
784
+ self.assertEqual(dest_stack.root_components[0].label(), "source_component")
785
+
786
+ # --------------------------------------------------------------------------
787
+ # Full-stack file shape (Stack.save output)
788
+ # --------------------------------------------------------------------------
789
+
790
+ def test_import_subtree_under_accepts_full_stack_file(self):
791
+ # -- A stack-format file (with "tree" key) has multiple roots
792
+ source_stack = self._make_stack()
793
+ source_stack.add_component(label="root_a", component_type="MinimalComponent")
794
+ source_stack.add_component(label="root_b", component_type="MinimalComponent")
795
+
796
+ filepath = self._tmp_json()
797
+ source_stack.save(filepath)
798
+
799
+ dest_stack = self._make_stack()
800
+ target_parent = dest_stack.add_component(
801
+ label="target_parent",
802
+ component_type="MinimalComponent",
803
+ )
804
+
805
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
806
+
807
+ # -- Both roots from the source file become children of the target
808
+ child_labels = sorted(c.label() for c in target_parent.children)
809
+ self.assertEqual(child_labels, ["root_a", "root_b"])
810
+
811
+ # --------------------------------------------------------------------------
812
+ # Error / edge cases
813
+ # --------------------------------------------------------------------------
814
+
815
+ def test_import_subtree_nonexistent_file_is_noop(self):
816
+ dest_stack = self._make_stack()
817
+ target_parent = dest_stack.add_component(
818
+ label="target_parent",
819
+ component_type="MinimalComponent",
820
+ )
821
+
822
+ # -- Should not raise; just no-op
823
+ dest_stack.import_subtree_under(
824
+ parent=target_parent,
825
+ filepath=self._tmp_json("does_not_exist.json"),
826
+ )
827
+
828
+ self.assertEqual(len(target_parent.children), 0)
829
+
830
+ def test_import_subtree_empty_filepath_is_noop(self):
831
+ dest_stack = self._make_stack()
832
+ target_parent = dest_stack.add_component(
833
+ label="target_parent",
834
+ component_type="MinimalComponent",
835
+ )
836
+
837
+ dest_stack.import_subtree_under(parent=target_parent, filepath="")
838
+
839
+ self.assertEqual(len(target_parent.children), 0)
840
+
841
+ # --------------------------------------------------------------------------
842
+ # Component.import_subtree (convenience wrapper)
843
+ # --------------------------------------------------------------------------
844
+
845
+ def test_component_import_subtree_adds_loaded_component_as_child(self):
846
+ source_stack = self._make_stack()
847
+ source_component = source_stack.add_component(
848
+ label="source_component",
849
+ component_type="MinimalComponent",
850
+ )
851
+
852
+ filepath = self._tmp_json()
853
+ source_component.save_settings(filepath)
854
+
855
+ dest_stack = self._make_stack()
856
+ target_parent = dest_stack.add_component(
857
+ label="target_parent",
858
+ component_type="MinimalComponent",
859
+ )
860
+
861
+ # -- Use the Component.import_subtree convenience wrapper
862
+ target_parent.import_subtree(filepath)
863
+
864
+ self.assertEqual(len(target_parent.children), 1)
865
+ self.assertEqual(target_parent.children[0].label(), "source_component")
866
+
867
+ # --------------------------------------------------------------------------
868
+ # Round-trip
869
+ # --------------------------------------------------------------------------
870
+
871
+ def test_round_trip_preserves_options_inputs_and_hierarchy(self):
872
+ source_stack = self._make_stack()
873
+ root = source_stack.add_component(
874
+ label="root",
875
+ component_type="ComponentWithOption",
876
+ )
877
+ root.option("test_option").set("root_value")
878
+
879
+ child = source_stack.add_component(
880
+ label="child",
881
+ component_type="ComponentWithOption",
882
+ parent=root,
883
+ )
884
+ child.option("test_option").set("child_value")
885
+
886
+ filepath = self._tmp_json()
887
+ root.save_settings(filepath)
888
+
889
+ dest_stack = self._make_stack()
890
+ target_parent = dest_stack.add_component(
891
+ label="target_parent",
892
+ component_type="MinimalComponent",
893
+ )
894
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
895
+
896
+ imported_root = target_parent.children[0]
897
+ imported_child = imported_root.children[0]
898
+
899
+ self.assertEqual(imported_root.option("test_option").get(), "root_value")
900
+ self.assertEqual(imported_child.option("test_option").get(), "child_value")
901
+
902
+ # --------------------------------------------------------------------------
903
+ # Label collision warning
904
+ # --------------------------------------------------------------------------
905
+
906
+ def test_import_subtree_warns_on_label_collision(self):
907
+ # -- Source component with a label
908
+ source_stack = self._make_stack()
909
+ source_component = source_stack.add_component(
910
+ label="duplicate_label",
911
+ component_type="MinimalComponent",
912
+ )
913
+
914
+ filepath = self._tmp_json()
915
+ source_component.save_settings(filepath)
916
+
917
+ # -- Destination already has a component with the same label
918
+ dest_stack = self._make_stack()
919
+ dest_stack.add_component(
920
+ label="duplicate_label",
921
+ component_type="MinimalComponent",
922
+ )
923
+ target_parent = dest_stack.add_component(
924
+ label="target_parent",
925
+ component_type="MinimalComponent",
926
+ )
927
+
928
+ # -- Capture the log to verify a warning was given.
929
+ with self.assertLogs("xstack.stack", level="WARNING") as captured:
930
+ dest_stack.import_subtree_under(
931
+ parent=target_parent,
932
+ filepath=filepath,
933
+ )
934
+
935
+ output = "\n".join(captured.output)
936
+ self.assertIn("duplicate_label", output)
937
+ self.assertIn("label collision", output.lower())
938
+
939
+ # -- The import should still have happened despite the warning.
940
+ self.assertEqual(len(target_parent.children), 1)
941
+
942
+ # --------------------------------------------------------------------------
943
+ # Subtree-load doesn't disturb existing components
944
+ # --------------------------------------------------------------------------
945
+
946
+ def test_import_subtree_does_not_modify_existing_components(self):
947
+ source_stack = self._make_stack()
948
+ source_component = source_stack.add_component(
949
+ label="source_component",
950
+ component_type="MinimalComponent",
951
+ )
952
+
953
+ filepath = self._tmp_json()
954
+ source_component.save_settings(filepath)
955
+
956
+ dest_stack = self._make_stack()
957
+ existing_component = dest_stack.add_component(
958
+ label="existing",
959
+ component_type="MinimalComponent",
960
+ )
961
+ existing_uuid = existing_component.uuid()
962
+
963
+ target_parent = dest_stack.add_component(
964
+ label="target_parent",
965
+ component_type="MinimalComponent",
966
+ )
967
+
968
+ dest_stack.import_subtree_under(parent=target_parent, filepath=filepath)
969
+
970
+ # -- existing_component should still be in the stack with the same UUID
971
+ self.assertIn(existing_component, dest_stack.root_components)
972
+ self.assertEqual(existing_component.uuid(), existing_uuid)
973
+
974
+
975
+ # ------------------------------------------------------------------------------
976
+ class TestBuildResults(unittest.TestCase):
977
+ """
978
+ Tests for how builds report failure, disabled hierarchies and nested builds.
979
+ """
980
+
981
+ def _make_stack(self):
982
+ stack = xstack.Stack(component_paths=[COMPONENT_PATH])
983
+ self.finished = []
984
+ self.failed = []
985
+ self.started = []
986
+ stack.build_finished.connect(self.finished.append)
987
+ stack.build_failed.connect(lambda component, details: self.failed.append(component))
988
+ stack.build_started.connect(lambda: self.started.append(True))
989
+ return stack
990
+
991
+ def test_run_returning_false_fails_the_build(self):
992
+ stack = self._make_stack()
993
+ component = stack.add_component(label="false", component_type="ReturnsFalseComponent")
994
+ after = stack.add_component(label="after", component_type="MinimalComponent")
995
+
996
+ self.assertFalse(stack.build())
997
+ self.assertEqual(component.status(), xstack.constants.Status.Failed)
998
+ self.assertEqual(after.status(), xstack.constants.Status.NotExecuted)
999
+ self.assertTrue(component.last_error())
1000
+ self.assertEqual(self.finished, [False])
1001
+ self.assertEqual(self.failed, [component])
1002
+
1003
+ def test_exception_reports_the_traceback(self):
1004
+ stack = self._make_stack()
1005
+ component = stack.add_component(label="fail", component_type="FailingComponent")
1006
+ details = []
1007
+ stack.build_failed.connect(lambda failed, text: details.append(text))
1008
+
1009
+ self.assertFalse(stack.build())
1010
+ self.assertIn("Enforced Failure", details[0])
1011
+ self.assertEqual(self.failed, [component])
1012
+
1013
+ def test_invalid_component_reports_failure(self):
1014
+ stack = self._make_stack()
1015
+ component = stack.add_component(label="invalid", component_type="InvalidComponent")
1016
+
1017
+ self.assertFalse(stack.build())
1018
+ self.assertEqual(self.finished, [False])
1019
+ self.assertEqual(self.failed, [component])
1020
+
1021
+ def test_success_emits_finished(self):
1022
+ stack = self._make_stack()
1023
+ stack.add_component(label="ok", component_type="MinimalComponent")
1024
+
1025
+ self.assertTrue(stack.build())
1026
+ self.assertEqual(self.finished, [True])
1027
+ self.assertEqual(self.failed, [])
1028
+
1029
+ def test_disabled_component_skips_its_children(self):
1030
+ stack = self._make_stack()
1031
+ parent = stack.add_component(label="parent", component_type="MinimalComponent")
1032
+ child = stack.add_component(label="child", component_type="MinimalComponent", parent=parent)
1033
+ grandchild = stack.add_component(label="grandchild", component_type="MinimalComponent", parent=child)
1034
+ parent.set_enabled(False)
1035
+
1036
+ self.assertTrue(stack.build())
1037
+ self.assertEqual(child.status(), xstack.constants.Status.NotExecuted)
1038
+ self.assertEqual(grandchild.status(), xstack.constants.Status.NotExecuted)
1039
+
1040
+ def test_nested_build_leaves_the_outer_build_alone(self):
1041
+ stack = self._make_stack()
1042
+ first = stack.add_component(label="first", component_type="MinimalComponent")
1043
+ runner = stack.add_component(
1044
+ label="runner",
1045
+ component_type="NestedBuildComponent",
1046
+ options={"Target": "block"},
1047
+ )
1048
+ block = stack.add_component(label="block", component_type="MinimalComponent")
1049
+ stack.add_component(label="inner", component_type="MinimalComponent", parent=block)
1050
+
1051
+ self.assertTrue(stack.build(build_up_to=runner))
1052
+
1053
+ # -- The nested build did not reset the status of the outer components,
1054
+ # -- or emit the build signals part way through
1055
+ self.assertEqual(first.status(), xstack.constants.Status.Success)
1056
+ self.assertEqual(self.started, [True])
1057
+ self.assertEqual(self.finished, [True])
1058
+
1059
+ def test_nested_failure_fails_the_outer_build(self):
1060
+ stack = self._make_stack()
1061
+ runner = stack.add_component(
1062
+ label="runner",
1063
+ component_type="NestedBuildComponent",
1064
+ options={"Target": "block"},
1065
+ )
1066
+ after = stack.add_component(label="after", component_type="MinimalComponent")
1067
+ block = stack.add_component(label="block", component_type="MinimalComponent")
1068
+ inner = stack.add_component(label="inner", component_type="ReturnsFalseComponent", parent=block)
1069
+
1070
+ self.assertFalse(stack.build())
1071
+ self.assertEqual(runner.status(), xstack.constants.Status.Failed)
1072
+ self.assertEqual(after.status(), xstack.constants.Status.NotExecuted)
1073
+
1074
+ # -- The component which actually failed is the one reported
1075
+ self.assertEqual(self.failed, [inner])
1076
+ self.assertEqual(self.finished, [False])
1077
+
1078
+ def test_recursive_nested_builds_are_refused(self):
1079
+ stack = self._make_stack()
1080
+ block_a = stack.add_component(label="a", component_type="MinimalComponent")
1081
+ stack.add_component(label="run b", component_type="NestedBuildComponent", options={"Target": "b"}, parent=block_a)
1082
+ block_b = stack.add_component(label="b", component_type="MinimalComponent")
1083
+ stack.add_component(label="run a", component_type="NestedBuildComponent", options={"Target": "a"}, parent=block_b)
1084
+
1085
+ self.assertFalse(stack.build(build_below=block_a))
1086
+ self.assertEqual(self.finished, [False])
1087
+
1088
+
1089
+ # ------------------------------------------------------------------------------
1090
+ class TestLoading(unittest.TestCase):
1091
+ """
1092
+ Tests for loading data with missing component types, versions and unknown keys.
1093
+ """
1094
+
1095
+ def _make_stack(self):
1096
+ return xstack.Stack(component_paths=[COMPONENT_PATH])
1097
+
1098
+ def test_missing_component_keeps_its_data(self):
1099
+ stack = self._make_stack()
1100
+ root = stack.add_component(label="root", component_type="ComponentWithOption")
1101
+ root.option("test_option").set("kept")
1102
+ root.set_enabled(False)
1103
+ stack.add_component(label="child", component_type="MinimalComponent", parent=root)
1104
+
1105
+ data = stack.serialise()
1106
+ data["tree"][0]["component_type"] = "Not A Real Component"
1107
+ data["tree"][0]["additional_data"] = {"anything": [1, 2]}
1108
+ original = json.dumps(data)
1109
+
1110
+ loaded = self._make_stack()
1111
+ with self.assertLogs("xstack.stack", level="WARNING"):
1112
+ loaded.deserialise(json.loads(original))
1113
+
1114
+ placeholder = loaded.root_components[0]
1115
+ self.assertIsInstance(placeholder, xstack.MissingComponent)
1116
+ self.assertEqual(placeholder.missing_identifier, "Not A Real Component")
1117
+ self.assertEqual(placeholder.children[0].label(), "child")
1118
+
1119
+ # -- Saving it again loses nothing
1120
+ self.assertEqual(json.dumps(loaded.serialise()), original)
1121
+
1122
+ def test_missing_component_does_not_build(self):
1123
+ stack = self._make_stack()
1124
+ stack.add_component(label="root", component_type="MinimalComponent")
1125
+ data = stack.serialise()
1126
+ data["tree"][0]["component_type"] = "Not A Real Component"
1127
+
1128
+ loaded = self._make_stack()
1129
+ loaded.deserialise(data)
1130
+
1131
+ with self.assertLogs("xstack.component", level="WARNING") as captured:
1132
+ self.assertFalse(loaded.build())
1133
+
1134
+ self.assertIn("Not A Real Component", "\n".join(captured.output))
1135
+
1136
+ def test_switching_a_missing_component_keeps_matching_values(self):
1137
+ stack = self._make_stack()
1138
+ stack.add_component(label="root", component_type="ComponentWithOption", options={"test_option": "kept"})
1139
+ data = stack.serialise()
1140
+ data["tree"][0]["component_type"] = "Not A Real Component"
1141
+
1142
+ loaded = self._make_stack()
1143
+ loaded.deserialise(data)
1144
+ replaced = loaded.replace_component(loaded.root_components[0], "ComponentWithOption")
1145
+
1146
+ self.assertEqual(replaced.option("test_option").get(), "kept")
1147
+
1148
+ def test_older_data_is_migrated(self):
1149
+ data = dict(
1150
+ label="stack",
1151
+ format="galaxy",
1152
+ tree=[
1153
+ dict(
1154
+ component_type="MigratingComponent",
1155
+ label="migrating",
1156
+ uuid="abc",
1157
+ inputs={},
1158
+ options={"Old Name": "value"},
1159
+ children=[],
1160
+ ),
1161
+ ],
1162
+ )
1163
+
1164
+ stack = self._make_stack()
1165
+ stack.deserialise(data)
1166
+
1167
+ component = stack.root_components[0]
1168
+ self.assertEqual(component.option("New Name").get(), "value")
1169
+ self.assertEqual(component.serialise()["version"], 2)
1170
+
1171
+ def test_unknown_option_is_reported(self):
1172
+ stack = self._make_stack()
1173
+
1174
+ with self.assertLogs("xstack.stack", level="WARNING") as captured:
1175
+ stack.add_component(label="opt", component_type="ComponentWithOption", options={"unknown": 1})
1176
+
1177
+ self.assertIn("unknown", "\n".join(captured.output))
1178
+
1179
+
1180
+ class TestDeprecatedNames(unittest.TestCase):
1181
+ """
1182
+ A component's deprecated_names resolve to the component, which always
1183
+ shows and saves with its current identifier.
1184
+ """
1185
+
1186
+ def _make_stack(self):
1187
+ return xstack.Stack(component_paths=[COMPONENT_PATH])
1188
+
1189
+ def _data(self, component_type, options=None, version=None):
1190
+ component_data = dict(
1191
+ component_type=component_type,
1192
+ label="renamed",
1193
+ uuid="abc",
1194
+ inputs={},
1195
+ options=options or {},
1196
+ children=[],
1197
+ )
1198
+ if version is not None:
1199
+ component_data["version"] = version
1200
+ return dict(label="stack", format="galaxy", tree=[component_data])
1201
+
1202
+ def test_resolve_component_type(self):
1203
+ stack = self._make_stack()
1204
+
1205
+ self.assertEqual(stack.resolve_component_type("Old Renamed Component"), "RenamedComponent")
1206
+ self.assertEqual(stack.resolve_component_type("Older Renamed Component"), "RenamedComponent")
1207
+ self.assertEqual(stack.resolve_component_type("RenamedComponent"), "RenamedComponent")
1208
+ self.assertEqual(stack.resolve_component_type("Not A Real Component"), "Not A Real Component")
1209
+ self.assertIsNone(stack.resolve_component_type(None))
1210
+
1211
+ def test_live_identifier_wins_over_deprecated_name(self):
1212
+ stack = self._make_stack()
1213
+
1214
+ self.assertEqual(stack.resolve_component_type("MinimalComponent"), "MinimalComponent")
1215
+ component = stack.add_component(label="minimal", component_type="MinimalComponent")
1216
+ self.assertEqual(component.identifier, "MinimalComponent")
1217
+
1218
+ def test_bare_string_deprecated_names_are_ignored(self):
1219
+ stack = self._make_stack()
1220
+
1221
+ self.assertEqual(stack.resolve_component_type("Bare Old Name"), "Bare Old Name")
1222
+ self.assertEqual(stack.resolve_component_type("B"), "B")
1223
+
1224
+ def test_add_component_by_deprecated_name(self):
1225
+ stack = self._make_stack()
1226
+
1227
+ component = stack.add_component(
1228
+ label="renamed",
1229
+ component_type="Old Renamed Component",
1230
+ options={"test_option": "value"},
1231
+ )
1232
+
1233
+ self.assertEqual(type(component).__name__, "RenamedComponent")
1234
+ self.assertEqual(component.identifier, "RenamedComponent")
1235
+ self.assertEqual(component.option("test_option").get(), "value")
1236
+
1237
+ def test_deprecated_name_is_logged_once(self):
1238
+ stack = self._make_stack()
1239
+ xstack.stack._LOGGED_DEPRECATED_NAMES.discard("Older Renamed Component")
1240
+
1241
+ with self.assertLogs("xstack.stack", level="INFO") as captured:
1242
+ stack.resolve_component_type("Older Renamed Component")
1243
+ stack.resolve_component_type("Older Renamed Component")
1244
+
1245
+ messages = [line for line in captured.output if "Older Renamed Component" in line]
1246
+ self.assertEqual(len(messages), 1)
1247
+ self.assertIn("RenamedComponent", messages[0])
1248
+
1249
+ def test_loading_a_deprecated_name_saves_the_new_name(self):
1250
+ stack = self._make_stack()
1251
+ stack.deserialise(self._data("Old Renamed Component", options={"test_option": "kept"}))
1252
+
1253
+ component = stack.root_components[0]
1254
+ self.assertNotIsInstance(component, xstack.MissingComponent)
1255
+ self.assertEqual(component.identifier, "RenamedComponent")
1256
+ self.assertEqual(component.option("test_option").get(), "kept")
1257
+ self.assertEqual(stack.serialise()["tree"][0]["component_type"], "RenamedComponent")
1258
+
1259
+ def test_deprecated_name_is_resolved_before_migrate(self):
1260
+ stack = self._make_stack()
1261
+
1262
+ # -- The factory loads the components module itself, so the class is
1263
+ # -- taken from the factory rather than imported
1264
+ component_class = stack.component_library.request("RenamedMigratingComponent")
1265
+ component_class.migrated_component_types.clear()
1266
+
1267
+ stack.deserialise(self._data("Old Migrating Name", options={"Old Option": "value"}, version=1))
1268
+
1269
+ component = stack.root_components[0]
1270
+ self.assertEqual(component.identifier, "RenamedMigratingComponent")
1271
+ self.assertEqual(component.option("New Option").get(), "value")
1272
+ self.assertEqual(component.serialise()["version"], 2)
1273
+ self.assertEqual(component_class.migrated_component_types, ["RenamedMigratingComponent"])
1274
+
1275
+ def test_of_type_lookups_resolve_deprecated_names(self):
1276
+ stack = self._make_stack()
1277
+ component = stack.add_component(label="renamed", component_type="RenamedComponent")
1278
+ stack.add_component(label="minimal", component_type="MinimalComponent")
1279
+
1280
+ self.assertEqual(stack.components(of_type="Old Renamed Component"), [component])
1281
+ self.assertIs(stack.get_component_by_type("Old Renamed Component"), component)
1282
+ self.assertIs(stack.get_component_by_label("renamed", of_type="Old Renamed Component"), component)
1283
+ self.assertIsNone(stack.get_component_by_label("minimal", of_type="Old Renamed Component"))
1284
+
1285
+ def test_unclaimed_name_is_still_a_placeholder(self):
1286
+ stack = self._make_stack()
1287
+
1288
+ with self.assertLogs("xstack.stack", level="WARNING"):
1289
+ stack.deserialise(self._data("Not A Real Component"))
1290
+
1291
+ placeholder = stack.root_components[0]
1292
+ self.assertIsInstance(placeholder, xstack.MissingComponent)
1293
+ self.assertEqual(placeholder.missing_identifier, "Not A Real Component")
1294
+ self.assertEqual(stack.serialise()["tree"][0]["component_type"], "Not A Real Component")
1295
+
1296
+ def test_deprecated_names_are_not_listed(self):
1297
+ stack = self._make_stack()
1298
+ identifiers = stack.component_library.identifiers()
1299
+
1300
+ self.assertIn("RenamedComponent", identifiers)
1301
+ self.assertNotIn("Old Renamed Component", identifiers)
1302
+ self.assertNotIn("Old Migrating Name", identifiers)
1303
+
1304
+ def test_replace_component_with_deprecated_name(self):
1305
+ stack = self._make_stack()
1306
+ original = stack.add_component(label="thing", component_type="MinimalComponent")
1307
+
1308
+ replaced = stack.replace_component(original, "Old Renamed Component")
1309
+
1310
+ self.assertEqual(replaced.identifier, "RenamedComponent")
1311
+
1312
+
1313
+ if __name__ == "__main__":
1314
+ unittest.main()