Example #1
0
def test_scribble_to_learn_nature_of_event_processor():
  ao = ActiveObject(name="Testing")
  ao.start_at(s11_state)
  time.sleep(0.1)
  ao.post_fifo(Event(signal=signals.T))
  time.sleep(0.5)
  pp(ao.spy())
Example #2
0
def test_scribble_to_learn_nature_of_event_processor():
  ao = ActiveObject(name="Testing")
  ao.start_at(s11_state)
  time.sleep(0.1)
  ao.post_fifo(Event(signal=signals.T))
  time.sleep(0.5)
  pp(ao.spy())
Example #3
0
def test_interior_postings_example():
    ao = ActiveObject()
    ao.start_at(middle)
    time.sleep(0.4)
    ao.post_fifo(Event(signal=signals.D))
    time.sleep(0.5)  # if you don't wait it won't look like it is working
    pp(ao.spy)
    assert (ao.spy_full() == [
        'START', 'SEARCH_FOR_SUPER_SIGNAL:middle',
        'SEARCH_FOR_SUPER_SIGNAL:outer', 'ENTRY_SIGNAL:outer',
        'ENTRY_SIGNAL:middle', 'INIT_SIGNAL:middle',
        '<- Queued:(0) Deferred:(0)', 'A:middle',
        'SEARCH_FOR_SUPER_SIGNAL:inner', 'ENTRY_SIGNAL:inner',
        'POST_DEFERRED:B', 'INIT_SIGNAL:inner', '<- Queued:(0) Deferred:(1)',
        'A:inner', 'A:middle', 'EXIT_SIGNAL:inner',
        'SEARCH_FOR_SUPER_SIGNAL:inner', 'ENTRY_SIGNAL:inner',
        'POST_DEFERRED:B', 'INIT_SIGNAL:inner', '<- Queued:(0) Deferred:(2)',
        'A:inner', 'A:middle', 'EXIT_SIGNAL:inner',
        'SEARCH_FOR_SUPER_SIGNAL:inner', 'ENTRY_SIGNAL:inner',
        'POST_DEFERRED:B', 'INIT_SIGNAL:inner', '<- Queued:(0) Deferred:(3)',
        'D:inner', 'D:middle', 'D:outer', 'RECALL:B', 'POST_FIFO:B',
        'D:outer:HOOK', '<- Queued:(1) Deferred:(2)', 'B:inner', 'B:middle',
        'B:outer', 'EXIT_SIGNAL:inner', 'EXIT_SIGNAL:middle',
        'EXIT_SIGNAL:outer', 'ENTRY_SIGNAL:outer', 'RECALL:B', 'POST_FIFO:B',
        'INIT_SIGNAL:outer', '<- Queued:(1) Deferred:(1)', 'B:outer',
        'EXIT_SIGNAL:outer', 'ENTRY_SIGNAL:outer', 'RECALL:B', 'POST_FIFO:B',
        'INIT_SIGNAL:outer', '<- Queued:(1) Deferred:(0)', 'B:outer',
        'EXIT_SIGNAL:outer', 'ENTRY_SIGNAL:outer', 'INIT_SIGNAL:outer',
        '<- Queued:(0) Deferred:(0)'
    ])
Example #4
0
 def fr_entry(cache, e):
     '''The file_read state ENTRY_SIGNAL event handler'''
     cache.dict = json.load(open(cache.file_path, 'r'))
     cache.json = json.dumps(cache.dict, sort_keys=True, indent=2)
     cache.last_modified = os.path.getmtime(cache.file_path)
     cache.created_at = time.ctime(os.path.getctime(cache.file_path))
     payload = {
         'dict': cache.dict,
         'last_modified': cache.last_modified,
         'created_at': cache.created_at,
         'expired': cache.expired()
     }
     cache.post_fifo(Event(signal=signals.CACHE, payload=payload))
     cache.post_lifo(Event(signal=signals.read_successful))
     pp(cache.json)
     return return_status.HANDLED
  def run(self):
    def print_signal_char_on_windows(character):
      '''print a character in dos'''
      print(" {}".format(character))
    def print_signal_char(character):
      '''print a character on the same line that we received input in linux'''
      print("\033[F:{}  ".format(character), end='')  # print on the same line
    pfn = print_signal_char_on_windows if sys.platform == 'win32' else print_signal_char
    while self.thread_event.is_set():
      character = input("\n:")
      character = character.upper()
      pfn(character)  # print the signal we are going to send to the terminal
      if len(character) != 1 or character not in self.post_functions: 
        print("Event not defined.") 
      else:
        self.post_functions[character]()  # call the post function
      time.sleep(0.1)

    pp(self.chart.spy())
    print(self.chart.trace())
    self.chart.stop()  # not needed, active object threads are daemonic

    print ("Terminating")
Example #6
0
def test_graffiti_spy():
  ao = ActiveObject(name="scribbled_on")
  ao.start_at(g1_s22_active_objects_graph)
  time.sleep(0.2)
  ao.stop()
  pp(ao.spy())
def test_interior_postings_example(fabric_fixture):
  ao = ActiveObject()
  ao.start_at(middle)
  time.sleep(0.4)
  ao.post_fifo(Event(signal=signals.D))
  time.sleep(0.1)  # if you don't wait it won't look like it is working
  pp(ao.spy)
  assert(ao.spy_full() ==
    ['START',
     'SEARCH_FOR_SUPER_SIGNAL:middle',
     'SEARCH_FOR_SUPER_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'ENTRY_SIGNAL:middle',
     'INIT_SIGNAL:middle',
     '<- Queued:(0) Deferred:(0)',
     'A:middle',
     'SEARCH_FOR_SUPER_SIGNAL:inner',
     'ENTRY_SIGNAL:inner',
     'POST_DEFERRED:B',
     'INIT_SIGNAL:inner',
     '<- Queued:(0) Deferred:(1)',
     'A:inner',
     'A:middle',
     'EXIT_SIGNAL:inner',
     'SEARCH_FOR_SUPER_SIGNAL:inner',
     'ENTRY_SIGNAL:inner',
     'POST_DEFERRED:B',
     'INIT_SIGNAL:inner',
     '<- Queued:(0) Deferred:(2)',
     'A:inner',
     'A:middle',
     'EXIT_SIGNAL:inner',
     'SEARCH_FOR_SUPER_SIGNAL:inner',
     'ENTRY_SIGNAL:inner',
     'POST_DEFERRED:B',
     'INIT_SIGNAL:inner',
     '<- Queued:(0) Deferred:(3)',
     'D:inner',
     'D:middle',
     'D:outer',
     'RECALL:B',
     'POST_FIFO:B',
     'D:outer:HOOK',
     '<- Queued:(1) Deferred:(2)',
     'B:inner',
     'B:middle',
     'B:outer',
     'EXIT_SIGNAL:inner',
     'EXIT_SIGNAL:middle',
     'EXIT_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'RECALL:B',
     'POST_FIFO:B',
     'INIT_SIGNAL:outer',
     '<- Queued:(1) Deferred:(1)',
     'B:outer',
     'EXIT_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'RECALL:B',
     'POST_FIFO:B',
     'INIT_SIGNAL:outer',
     '<- Queued:(1) Deferred:(0)',
     'B:outer',
     'EXIT_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'INIT_SIGNAL:outer',
     '<- Queued:(0) Deferred:(0)'])
Example #8
0
def test_graffiti_spy():
  ao = ActiveObject(name="scribbled_on")
  ao.start_at(g1_s22_active_objects_graph)
  time.sleep(0.2)
  pp(ao.spy())
Example #9
0
    signal=signals.Ready,
    handler=marshal_ready). \
  to_method()

waiting_to_advance = archer.create(state='waiting_to_advance'). \
  catch(
    signal=signals.ENTRY_SIGNAL,
    handler=wta_entry). \
  catch(
    signal=signals.EXIT_SIGNAL,
    handler=wta_exit). \
  to_method()

archer.nest(deceit_in_detail, parent=None). \
  nest(advance, parent=deceit_in_detail). \
  nest(circle_and_fire, parent=advance). \
  nest(skirmish, parent=deceit_in_detail). \
  nest(waiting_to_lure, parent=skirmish). \
  nest(feigned_retreat, parent=deceit_in_detail). \
  nest(marshal, parent=deceit_in_detail). \
  nest(waiting_to_advance, parent=marshal)

if __name__ == '__main__':
  print(archer.name)
  archer.live_trace = True
  archer.time_compression = 100
  archer.start_at(deceit_in_detail)
  archer.post_fifo(Event(signal=signals.Senior_Advance_War_Cry))
  time.sleep(6.0)
  pp('')