+def yes_no(q, default=True):
+ a = input(q + " (Y/n)?" if default else " (y/N)?")
+ a=a.lower()
+ if a == '':
+ return default
+ elif a == "n":
+ a = False
+ elif a == "y":
+ a = True
+ return a
+
+def multi_choice(q, choices, defaultPos=None):
+ if defaultPos is not None:
+ print("{} [{}]?".format(q, defaultPos))
+ else:
+ print(q + "?")
+ for pos, choice in enumerate(choices):
+ print("{}) {}".format(pos, choice))
+ a = input()
+ a=a.lower()
+ try:
+ if a == '':
+ a = defaultPos
+ else:
+ a = int(a)
+ return choices[a]
+ except Exception as e:
+ print(e)
+ return None
+
+def await_true(name, fun, interval=0, patience=60):
+ from agnostic import sleep
+ from utime import ticks_ms, ticks_add, ticks_diff
+ print("Waiting {} sec until {} (CTRL+C give up)".format(patience, name))
+ deadline = ticks_add(ticks_ms(), int(patience * 1000))
+ try:
+ while ticks_diff(deadline, ticks_ms()) > 0:
+ if fun():
+ return True
+ else:
+ sleep(interval)
+ return False
+ except KeyboardInterrupt:
+ return False
+
+
+def test_module(module, runner=None):
+ import unittest