Skip to content

Commit

Permalink
don't leak message that has braken story loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed Mar 6, 2017
1 parent ffbf8ec commit c9518e4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
50 changes: 49 additions & 1 deletion botstory/ast/callable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ async def run_one_story(ctx):
assert user_storage.value == talk.user


# Loop & Callable Stories


@pytest.mark.asyncio
async def test_story_loop_inside_of_callable():
inside_of_loop = SimpleTrigger()
Expand Down Expand Up @@ -422,8 +425,8 @@ def inner_job(ctx):

@pytest.mark.asyncio
async def test_exit_outside_of_callable_and_loop():
in_progress_inside_callable_trigger = SimpleTrigger(0)
exit_inside_callable_trigger = SimpleTrigger(0)
in_progress_inside_callable_trigger = SimpleTrigger(0)
in_progress_outside_callable_trigger = SimpleTrigger(0)
with answer.Talk() as talk:
story = talk.story
Expand Down Expand Up @@ -469,3 +472,48 @@ async def in_progress_outside_callable_store(ctx):
assert exit_inside_callable_trigger.result() == 1
assert in_progress_inside_callable_trigger.result() == 1
assert in_progress_outside_callable_trigger.result() == 1


@pytest.mark.asyncio
async def test_exit_outside_of_callable_and_loop_but_do_not_match_again():
exit_outside_callable_trigger = SimpleTrigger(0)
with answer.Talk() as talk:
story = talk.story

@story.callable()
def one_callable():
@story.part()
def inner_init(ctx):
pass

@story.loop()
def inner_loop():
@story.on('in-progress')
def in_progress():
@story.part()
def do_in_progress(ctx):
pass

@story.on('exit')
def exit():
@story.part()
def break_loop(ctx):
return loop.BreakLoop()

@story.on('start')
def start_story():
@story.part()
async def call_callable(ctx):
return await one_callable(ctx)

@story.on('exit')
def exit_outside_callable():
@story.part()
async def exit_outside_callable_store(ctx):
exit_outside_callable_trigger.inc()

await talk.pure_text('start')
await talk.pure_text('in-progress')
await talk.pure_text('exit')

assert exit_outside_callable_trigger.result() == 0
2 changes: 1 addition & 1 deletion botstory/ast/story_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def current_step(self):
return self.stack_tail()['step']

def does_it_match_any_story(self):
return self.compiled_story() is not None
return self.compiled_story() is not None and not self.matched

def get_child_story(self):
"""
Expand Down

0 comments on commit c9518e4

Please sign in to comment.