Skip to content

Instantly share code, notes, and snippets.

@rmoehn
Last active May 26, 2018 05:13
Show Gist options
  • Save rmoehn/76ad05167f5e41197803f5fd5e6caac7 to your computer and use it in GitHub Desktop.
Save rmoehn/76ad05167f5e41197803f5fd5e6caac7 to your computer and use it in GitHub Desktop.
Naive driver for debugging oughtinc/patchwork#4
import sys
from patchwork.actions import Reply, Unlock
from patchwork.datastore import Datastore
from patchwork.scheduling import RootQuestionSession, Scheduler
from patchwork.text_manipulation import make_link_texts
def main():
db = Datastore()
sched = Scheduler(db)
with RootQuestionSession(sched, "what is the sum of list [[6] []]") as sess:
initial_context = sess.current_context
print(sess.current_context)
print(sess.act(Unlock("$3")))
print("The initial context was:\n {}".format(initial_context))
print("The final answer is:\n {}".format(sess.act(Reply("6"))))
print("\n* * * * *\n")
with RootQuestionSession(sched, "what is the sum of list [[6] []]") as sess:
if sess.is_fulfilled():
print("That question has already been answered: ")
print(make_link_texts(sess.final_answer_promise, db)[sess.final_answer_promise])
print("\n* * * * *\n")
with RootQuestionSession(sched, "what is the sum of list [[6] [[7] []]]") as sess:
print(sess.current_context)
if sess.current_context is None:
print("The expected failure occurred.")
sys.exit(1)
else:
print("You fixed it! Maybe.")
sys.exit(0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment