]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - test/src/testing/__init__.py
Massive pylinting session and added Github Actions
[Adafruit_Blinka-hackapet.git] / test / src / testing / __init__.py
index 859b4fe9ec163fe780731ebcab7b175e2ba0a27d..e3173d1b19af1708f9f8a5eac6312352ce826772 100644 (file)
@@ -1,14 +1,16 @@
 # mitigate heap fragmentation issues by pre-loading major libraries
 import gc
-gc.collect()
+
 gc.collect()
 import unittest
+
 gc.collect()
 
+
 def yes_no(q, default=True):
     a = input(q + " (Y/n)?" if default else " (y/N)?")
-    a=a.lower()
-    if a == '':
+    a = a.lower()
+    if a == "":
         return default
     elif a == "n":
         a = False
@@ -16,6 +18,7 @@ def yes_no(q, default=True):
         a = True
     return a
 
+
 def multi_choice(q, choices, defaultPos=None):
     if defaultPos is not None:
         print("{} [{}]?".format(q, defaultPos))
@@ -24,9 +27,9 @@ def multi_choice(q, choices, defaultPos=None):
     for pos, choice in enumerate(choices):
         print("{}) {}".format(pos, choice))
     a = input()
-    a=a.lower()
+    a = a.lower()
     try:
-        if a == '':
+        if a == "":
             a = defaultPos
         else:
             a = int(a)
@@ -35,13 +38,15 @@ def multi_choice(q, choices, defaultPos=None):
         print(e)
         return None
 
+
 def await_true(name, fun, interval=0, patience=60):
-    from adafruit_blinka.agnostic import sleep
-    from utime import ticks_ms, ticks_add, ticks_diff
+    from adafruit_blinka.agnostic.time import sleep, monotonic
+
     print("Waiting {} sec until {} (CTRL+C give up)".format(patience, name))
-    deadline = ticks_add(ticks_ms(), int(patience * 1000))
+
+    deadline = monotonic() + patience
     try:
-        while ticks_diff(deadline, ticks_ms()) > 0:
+        while deadline - monotonic() > 0:
             if fun():
                 return True
             else:
@@ -53,6 +58,7 @@ def await_true(name, fun, interval=0, patience=60):
 
 def test_module(module, runner=None):
     import unittest
+
     if runner is None:
         runner = unittest.TestRunner()
     suite = unittest.TestSuite()
@@ -65,10 +71,11 @@ def test_module(module, runner=None):
             pass
     return runner.run(suite)
 
+
 def test_module_name(absolute, runner=None):
     try:
         print("Suite begin: {}".format(absolute))
-        module=__import__(absolute)
+        module = __import__(absolute)
         relatives = absolute.split(".")
         if len(relatives) > 1:
             for relative in relatives[1:]:
@@ -77,6 +84,7 @@ def test_module_name(absolute, runner=None):
     finally:
         print("Suite end: {}".format(absolute))
 
+
 def test_interactive(*module_names):
     for module_name in module_names:
         if yes_no("Run suite {}".format(module_name)):
@@ -91,15 +99,20 @@ def test_prepare(casetype):
 
 def main():
     """
-    moduleNames = ["testing.implementation.all.digitalio",]
+    moduleNames = ["testing.implementation.universal.digitalio",]
     if agnostic.implementation == "micropython":
         moduleNames.extend([ "testing.implementation.micropython.digitalio",])
 
     """
-    moduleNames = ["testing.implementation.all.bitbangio"]
+    moduleNames = ["testing.implementation.universal.bitbangio"]
 
-    unittest.raiseException = True # terminates with stack information on userspace Exception
-    unittest.raiseBaseException = True # terminates with stack information on system Exception
+    unittest.raiseException = (
+        True  # terminates with stack information on userspace Exception
+    )
+    unittest.raiseBaseException = (
+        True  # terminates with stack information on system Exception
+    )
     test_interactive(*moduleNames)
 
-gc.collect()
\ No newline at end of file
+
+gc.collect()