/ tests / test_inline_bindings.py
test_inline_bindings.py
 1  """
 2  test_inline_bindings.py - Test inline binding syntax (Phase 3)
 3  
 4  This tests the >> operator for inline bindings in part constructors:
 5  
 6      class Pulse(Holon):
 7          size: Length = 100
 8  
 9          def specify_parts(self):
10              # Inline binding: circle radius bound to size parameter
11              self.circle = Circle(radius=self.size_parameter >> 100)
12              self.parts = [self.circle]
13  
14  The >> operator creates a BoundValue that:
15  1. Uses the default value (100) for initial construction
16  2. Stores the binding for compilation into generator code
17  
18  This is more concise than the separate specify_relationships() approach.
19  """
20  
21  from DreamTalk.imports import *
22  
23  
24  class InlinePulse(Holon):
25      """
26      A holon using inline binding syntax.
27  
28      The circle's radius is bound to the size parameter using >>.
29      """
30      # Type-hinted parameter
31      size: Length = 100
32  
33      def specify_parts(self):
34          # Inline binding: circle radius <- size parameter
35          # The >> operator means: "bind this, using 100 as default"
36          self.circle = Circle(radius=self.size_parameter >> 100)
37          self.parts = [self.circle]
38  
39  
40  class InlineBindingTest(Dream):
41      """Test the inline binding syntax."""
42  
43      def unfold(self):
44          # Create a pulse with inline binding
45          pulse = InlinePulse()
46  
47          # The size parameter should control the circle radius
48          # Animate size from 100 to 200 to 50
49          self.play(pulse.animate.size(200), run_time=1)
50          self.play(pulse.animate.size(50), run_time=1)
51          self.play(pulse.animate.size(100), run_time=0.5)
52  
53          self.wait(0.5)
54  
55  
56  if __name__ == "__main__":
57      InlineBindingTest()