Update diagnostics/os_diagnostics.py

This commit is contained in:
2026-03-19 18:33:33 +00:00
parent 1a8d04de91
commit a72af812f6

View File

@@ -2,6 +2,10 @@ from pybricks.parameters import Port
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
import uio
import ujson
import umath
import uselect
import ustruct
import usys
import urandom
from urandom import random
from pybricks.iodevices import UARTDevice as _UARTDevice
@@ -878,12 +882,62 @@ class USysTest:
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] MicroPython information:", usys.implementation)
successfultests += 4
self.successfultests += 1
print("Completed Test 1/4: versioninfo - SUCCESSFUL")
except Exception as ex:
failedtests["versioninfo"] = ex.errno
def print_results(self):
printVersionDiagnostics()
print(f"\n=== Results: {self.successfultests}/0 tests passed ===")
print("Completed Test 4/4: versioninfo - FAILED")
def teststdin(self):
# 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:
print("Failed tests:")
for key, value in self.failedtests.items():