Update diagnostics/os_diagnostics.py
This commit is contained in:
@@ -2,6 +2,10 @@ from pybricks.parameters import Port
|
|||||||
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
|
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
|
||||||
import uio
|
import uio
|
||||||
import ujson
|
import ujson
|
||||||
|
import umath
|
||||||
|
import uselect
|
||||||
|
import ustruct
|
||||||
|
import usys
|
||||||
import urandom
|
import urandom
|
||||||
from urandom import random
|
from urandom import random
|
||||||
from pybricks.iodevices import UARTDevice as _UARTDevice
|
from pybricks.iodevices import UARTDevice as _UARTDevice
|
||||||
@@ -799,7 +803,7 @@ class USelectTest:
|
|||||||
# Register the standard input so we can read keyboard presses.
|
# Register the standard input so we can read keyboard presses.
|
||||||
keyboard = poll()
|
keyboard = poll()
|
||||||
keyboard.register(stdin)
|
keyboard.register(stdin)
|
||||||
print("Type a few keys, make sure you get back what characteryou typed, then press Escape.")
|
print("Type a few keys, make sure you get back what character you typed, then press Escape.")
|
||||||
while True:
|
while True:
|
||||||
# Check if a key has been pressed.
|
# Check if a key has been pressed.
|
||||||
if keyboard.poll(0):
|
if keyboard.poll(0):
|
||||||
@@ -878,12 +882,62 @@ class USysTest:
|
|||||||
print("[Hub Diagnostics - MicroPython - Version] MicroPython version:", usys.version)
|
print("[Hub Diagnostics - MicroPython - Version] MicroPython version:", usys.version)
|
||||||
print("[Hub Diagnostics - MicroPython - Version] Pybricks version information:", usys.version_info)
|
print("[Hub Diagnostics - MicroPython - Version] Pybricks version information:", usys.version_info)
|
||||||
print("[Hub Diagnostics - MicroPython - Version] MicroPython information:", usys.implementation)
|
print("[Hub Diagnostics - MicroPython - Version] MicroPython information:", usys.implementation)
|
||||||
successfultests += 4
|
self.successfultests += 1
|
||||||
|
print("Completed Test 1/4: versioninfo - SUCCESSFUL")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
failedtests["versioninfo"] = ex.errno
|
failedtests["versioninfo"] = ex.errno
|
||||||
def print_results(self):
|
print("Completed Test 4/4: versioninfo - FAILED")
|
||||||
printVersionDiagnostics()
|
def teststdin(self):
|
||||||
print(f"\n=== Results: {self.successfultests}/0 tests passed ===")
|
# Register the standard input so we can read keyboard presses.
|
||||||
|
keyboard = poll()
|
||||||
|
keyboard.register(stdin)
|
||||||
|
print("Type a few keys, make sure you get back what character you typed, then press Escape.")
|
||||||
|
while True:
|
||||||
|
# Check if a key has been pressed.
|
||||||
|
if keyboard.poll(0):
|
||||||
|
|
||||||
|
# Read the key and print it.
|
||||||
|
key = stdin.read(1)
|
||||||
|
if key == '\x1b':
|
||||||
|
print("Escape key pressed. Exiting...")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Pressed:", key)
|
||||||
|
if(input("Input Y if the results were accurate:") == "Y"):
|
||||||
|
print("Completed Test 1/4: stdin - SUCCESSFUL")
|
||||||
|
self.successfultests += 1
|
||||||
|
else:
|
||||||
|
self.failedtests["stdin"] = "Unsatisfied"
|
||||||
|
print("Completed Test 1/4: stdin - FAILED")
|
||||||
|
if self.failedtests:
|
||||||
|
print("Failed tests:")
|
||||||
|
for key, value in self.failedtests.items():
|
||||||
|
print(f" {key}: {value}")
|
||||||
|
def teststdout(self):
|
||||||
|
usys.stdout.flush()
|
||||||
|
try:
|
||||||
|
usys.stdout.buffer.write(b"stdout worked!")
|
||||||
|
print("Completed Test 2/4: stdout - SUCCESSFUL")
|
||||||
|
self.successfultests += 1
|
||||||
|
except Exception as ex:
|
||||||
|
print("Completed Test 2/4: stdout - FAILED")
|
||||||
|
self.failedtests["stdout"] = ex.errno
|
||||||
|
def teststderr(self):
|
||||||
|
usys.stderr.flush()
|
||||||
|
try:
|
||||||
|
usys.stderr.buffer.write(b"stderr worked!")
|
||||||
|
print("Completed Test 3/4: stderr - SUCCESSFUL")
|
||||||
|
self.successfultests += 1
|
||||||
|
except Exception as ex:
|
||||||
|
print("Completed Test 3/4: stderr - FAILED")
|
||||||
|
self.failedtests["stderr"] = ex.errno
|
||||||
|
|
||||||
|
def print_results(self):
|
||||||
|
self.teststdin()
|
||||||
|
self.teststdout()
|
||||||
|
self.teststderr()
|
||||||
|
printVersionDiagnostics()
|
||||||
|
print(f"\n=== Results: {self.successfultests}/3 tests passed ===")
|
||||||
if self.failedtests:
|
if self.failedtests:
|
||||||
print("Failed tests:")
|
print("Failed tests:")
|
||||||
for key, value in self.failedtests.items():
|
for key, value in self.failedtests.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user