Update diagnostics/os_diagnostics.py
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from pybricks.parameters import Port
|
||||
from uerrno import EAGAIN, EBUSY, ECANCELED, EINVAL, EIO, ENODEV, EOPNOTSUPP, EPERM, ETIMEDOUT
|
||||
import uio
|
||||
from pybricks.iodevices import UARTDevice as _UARTDevice
|
||||
from pybricks.tools import wait, multitask, run_task
|
||||
|
||||
@@ -62,7 +63,12 @@ class OSDiagnostics:
|
||||
|
||||
|
||||
|
||||
class UerrnoTest(OSDiagnostics):
|
||||
class UerrnoTest:
|
||||
def __init__(self, hub, motorclass):
|
||||
self.hub = hub
|
||||
self.motorclass = motorclass
|
||||
self.successfultests = 0
|
||||
self.failedtests = {}
|
||||
def testeagain(self):
|
||||
# Triggered by calling multitask() nested inside another multitask()
|
||||
print("Starting Test 1/9: EAGAIN - Try Again Error")
|
||||
@@ -254,4 +260,41 @@ class UerrnoTest(OSDiagnostics):
|
||||
if self.failedtests:
|
||||
print("Failed tests:")
|
||||
for key, value in self.failedtests.items():
|
||||
print(f" {key}: {value}")
|
||||
print(f" {key}: {value}")
|
||||
class UIOTest(OSDiagnostics):
|
||||
def __init__(self, hub, motorclass):
|
||||
self.hub = hub
|
||||
self.motorclass = motorclass
|
||||
self.successfultests = 0
|
||||
self.failedtests = {}
|
||||
# uio contains BytesIO, StringIO, and FileIO, but due to SPIKE Prime's lack of a filesystem, the test will omit FileIO
|
||||
def testbytesio(self):
|
||||
failed = False
|
||||
try:
|
||||
buffer = io.BytesIO()
|
||||
|
||||
buffer.write(b'Hello, ')
|
||||
buffer.write(b'Pybricks!')
|
||||
|
||||
current_content = buffer.getvalue()
|
||||
print(f"Buffer content (via getvalue()): {current_content}")
|
||||
# Output: b'Hello, Pybricks!'
|
||||
|
||||
print(f"Current cursor position (should be 16): {buffer.tell()}")
|
||||
# TODO: After testing that BytesIO actually works on this system, add checks to make sure that the outputs match what they should.
|
||||
buffer.seek(0)
|
||||
|
||||
read_data = buffer.read()
|
||||
print(f"Read data (via read()): {read_data}")
|
||||
# Output: Read data (via read()): b'Hello, Pybricks!'
|
||||
|
||||
print(f"Current cursor position after reading: {buffer.tell()}") # Output should be 16
|
||||
|
||||
buffer.close()
|
||||
print("Buffer was closed successfully.")
|
||||
print("Completed Test 1/2: BytesIO - SUCCESSFUL")
|
||||
self.successfultests += 1
|
||||
except Exception as ex:
|
||||
print("An unexpected error occured.")
|
||||
print("Completed Test 1/2: BytesIO - FAILED")
|
||||
self.failedtests["BytesIO"] = ex.errno
|
||||
Reference in New Issue
Block a user