示例#1
0
def test1_trans_topology_a():
    ao = ActiveObject()
    ao.start_at(outer)
    pp(ao.spy_full())
    assert (ao.spy_full() == [
        'START', 'SEARCH_FOR_SUPER_SIGNAL:outer', 'ENTRY_SIGNAL:outer',
        'INIT_SIGNAL:outer', '<- Queued:(0) Deferred:(0)'
    ])
    pp(ao.spy_full())
    print(ao.trace())
    event_w = Event(signal=signals.WaitComplete)
    ao.clear_trace()
    ao.post_fifo(event_w)
    import time
    time.sleep(0.1)
    pp(ao.spy_rtc())
    print(ao.trace())

    # clear the spy and the trace
    ao.clear_spy()
    ao.clear_trace()

    # post a number of events and see what happens
    event_wait_complete = Event(signal=signals.WaitComplete)
    event_reset_chart = Event(signal=signals.ResetChart)
    ao.post_fifo(event_wait_complete)
    ao.post_fifo(event_reset_chart)
    ao.post_fifo(event_wait_complete)
    ao.post_fifo(event_reset_chart)
    time.sleep(0.3)
    print(ao.trace())
    pp(ao.spy_full())
示例#2
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)'
    ])
def test1_trans_topology_a():
  ao = ActiveObject()
  ao.start_at(outer)
  pp(ao.spy_full())
  assert(ao.spy_full() ==
    ['START',
     'SEARCH_FOR_SUPER_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'INIT_SIGNAL:outer',
     '<- Queued:(0) Deferred:(0)']
  )
  pp(ao.spy_full())
  print(ao.trace())
  event_w = Event(signal=signals.WaitComplete)
  ao.clear_trace()
  ao.post_fifo(event_w)
  import time
  time.sleep(0.1)
  pp(ao.spy_rtc())
  print(ao.trace())

  # stop the threads
  ao.stop()

  # clear the spy and the trace
  ao.clear_spy()
  ao.clear_trace()

  # post a number of events and see what happens
  event_wait_complete = Event(signal=signals.WaitComplete)
  event_reset_chart = Event(signal=signals.ResetChart)
  ao.post_fifo(event_wait_complete)
  ao.post_fifo(event_reset_chart)
  ao.post_fifo(event_wait_complete)
  ao.post_fifo(event_reset_chart)
  time.sleep(0.3)
  print(ao.trace())
  pp(ao.spy_full())
示例#4
0
def test_tazor_example():
    tazor = ActiveObject()
    tazor.start_at(arming)
    time.sleep(0.4)
    tazor.post_fifo(Event(signal=signals.TRIGGER_PULLED))
    time.sleep(0.1)  # if you don't wait it won't look like it is working

    assert (tazor.spy_full() == [
        'START', 'SEARCH_FOR_SUPER_SIGNAL:arming',
        'SEARCH_FOR_SUPER_SIGNAL:tazor_operating',
        'ENTRY_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:arming',
        'INIT_SIGNAL:arming', '<- Queued:(0) Deferred:(0)',
        'BATTERY_CHARGE:arming', 'SEARCH_FOR_SUPER_SIGNAL:armed',
        'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE',
        'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(1)',
        'BATTERY_CHARGE:armed', 'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed',
        'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed',
        'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed',
        '<- Queued:(0) Deferred:(2)', 'BATTERY_CHARGE:armed',
        'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed',
        'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed',
        'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed',
        '<- Queued:(0) Deferred:(3)', 'TRIGGER_PULLED:armed',
        'TRIGGER_PULLED:arming', 'TRIGGER_PULLED:tazor_operating',
        'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE',
        'TRIGGER_PULLED:tazor_operating:HOOK', '<- Queued:(1) Deferred:(2)',
        'CAPACITOR_CHARGE:armed', 'CAPACITOR_CHARGE:arming',
        'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:armed',
        'EXIT_SIGNAL:arming', 'EXIT_SIGNAL:tazor_operating',
        'ENTRY_SIGNAL:tazor_operating', 'RECALL:CAPACITOR_CHARGE',
        'POST_FIFO:CAPACITOR_CHARGE', 'INIT_SIGNAL:tazor_operating',
        '<- Queued:(1) Deferred:(1)', 'CAPACITOR_CHARGE:tazor_operating',
        'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating',
        'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE',
        'INIT_SIGNAL:tazor_operating', '<- Queued:(1) Deferred:(0)',
        'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:tazor_operating',
        'ENTRY_SIGNAL:tazor_operating', 'INIT_SIGNAL:tazor_operating',
        '<- Queued:(0) Deferred:(0)'
    ])
    print(tazor.trace())
def test_tazor_example(fabric_fixture):
  tazor = ActiveObject()
  tazor.start_at(arming)
  time.sleep(0.4)
  tazor.post_fifo(Event(signal=signals.TRIGGER_PULLED))
  time.sleep(0.1)  # if you don't wait it won't look like it is working

  assert(tazor.spy_full() ==
    ['START',
     'SEARCH_FOR_SUPER_SIGNAL:arming',
     'SEARCH_FOR_SUPER_SIGNAL:tazor_operating',
     'ENTRY_SIGNAL:tazor_operating',
     'ENTRY_SIGNAL:arming',
     'INIT_SIGNAL:arming',
     '<- Queued:(0) Deferred:(0)',
     'BATTERY_CHARGE:arming',
     'SEARCH_FOR_SUPER_SIGNAL:armed',
     'ENTRY_SIGNAL:armed',
     'POST_DEFERRED:CAPACITOR_CHARGE',
     'INIT_SIGNAL:armed',
     '<- Queued:(0) Deferred:(1)',
     'BATTERY_CHARGE:armed',
     'BATTERY_CHARGE:arming',
     'EXIT_SIGNAL:armed',
     'SEARCH_FOR_SUPER_SIGNAL:armed',
     'ENTRY_SIGNAL:armed',
     'POST_DEFERRED:CAPACITOR_CHARGE',
     'INIT_SIGNAL:armed',
     '<- Queued:(0) Deferred:(2)',
     'BATTERY_CHARGE:armed',
     'BATTERY_CHARGE:arming',
     'EXIT_SIGNAL:armed',
     'SEARCH_FOR_SUPER_SIGNAL:armed',
     'ENTRY_SIGNAL:armed',
     'POST_DEFERRED:CAPACITOR_CHARGE',
     'INIT_SIGNAL:armed',
     '<- Queued:(0) Deferred:(3)',
     'TRIGGER_PULLED:armed',
     'TRIGGER_PULLED:arming',
     'TRIGGER_PULLED:tazor_operating',
     'RECALL:CAPACITOR_CHARGE',
     'POST_FIFO:CAPACITOR_CHARGE',
     'TRIGGER_PULLED:tazor_operating:HOOK',
     '<- Queued:(1) Deferred:(2)',
     'CAPACITOR_CHARGE:armed',
     'CAPACITOR_CHARGE:arming',
     'CAPACITOR_CHARGE:tazor_operating',
     'EXIT_SIGNAL:armed',
     'EXIT_SIGNAL:arming',
     'EXIT_SIGNAL:tazor_operating',
     'ENTRY_SIGNAL:tazor_operating',
     'RECALL:CAPACITOR_CHARGE',
     'POST_FIFO:CAPACITOR_CHARGE',
     'INIT_SIGNAL:tazor_operating',
     '<- Queued:(1) Deferred:(1)',
     'CAPACITOR_CHARGE:tazor_operating',
     'EXIT_SIGNAL:tazor_operating',
     'ENTRY_SIGNAL:tazor_operating',
     'RECALL:CAPACITOR_CHARGE',
     'POST_FIFO:CAPACITOR_CHARGE',
     'INIT_SIGNAL:tazor_operating',
     '<- Queued:(1) Deferred:(0)',
     'CAPACITOR_CHARGE:tazor_operating',
     'EXIT_SIGNAL:tazor_operating',
     'ENTRY_SIGNAL:tazor_operating',
     'INIT_SIGNAL:tazor_operating',
     '<- Queued:(0) Deferred:(0)'])
  print(tazor.trace())
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)'])