Finish UIO
This commit is contained in:
@@ -60,6 +60,11 @@ class OSDiagnostics:
|
|||||||
uerrnotestobject.print_results()
|
uerrnotestobject.print_results()
|
||||||
self.successfultests += uerrnotestobject.successfultests
|
self.successfultests += uerrnotestobject.successfultests
|
||||||
self.failedtests.update(uerrnotestobject.failedtests)
|
self.failedtests.update(uerrnotestobject.failedtests)
|
||||||
|
def testUIO(self):
|
||||||
|
uiotestobject = UIOTest(self.hub, self.motorclass)
|
||||||
|
uiotestobject.print_results()
|
||||||
|
self.successfultests += uiotestobject.successfultests
|
||||||
|
self.failedtests.update(uiotestobject.failedtests)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -267,28 +272,25 @@ class UIOTest(OSDiagnostics):
|
|||||||
self.motorclass = motorclass
|
self.motorclass = motorclass
|
||||||
self.successfultests = 0
|
self.successfultests = 0
|
||||||
self.failedtests = {}
|
self.failedtests = {}
|
||||||
# uio contains BytesIO, StringIO, and FileIO, but due to SPIKE Prime's lack of a filesystem, the test will omit FileIO
|
# uio contains BytesIO, StringIO, and FileIO, but due to SPIKE Prime's lack of a filesystem, the test will omit FileIO and only include BytesIO and StringIO
|
||||||
def testbytesio(self):
|
def testbytesio(self):
|
||||||
failed = False
|
|
||||||
try:
|
try:
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
|
|
||||||
buffer.write(b'Hello, ')
|
buffer.write(b'Hello, ')
|
||||||
buffer.write(b'Pybricks!')
|
buffer.write(b'Pybricks byte stream!')
|
||||||
|
|
||||||
current_content = buffer.getvalue()
|
current_content = buffer.getvalue()
|
||||||
print(f"Buffer content (via getvalue()): {current_content}")
|
print(f"Buffer content (via getvalue()): {current_content}")
|
||||||
# Output: b'Hello, Pybricks!'
|
|
||||||
|
|
||||||
print(f"Current cursor position (should be 16): {buffer.tell()}")
|
print(f"Current cursor position: {buffer.tell()}")
|
||||||
# TODO: After testing that BytesIO actually works on this system, add checks to make sure that the outputs match what they should.
|
# 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)
|
buffer.seek(0)
|
||||||
|
|
||||||
read_data = buffer.read()
|
read_data = buffer.read()
|
||||||
print(f"Read data (via read()): {read_data}")
|
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
|
print(f"Current cursor position after reading: {buffer.tell()}")
|
||||||
|
|
||||||
buffer.close()
|
buffer.close()
|
||||||
print("Buffer was closed successfully.")
|
print("Buffer was closed successfully.")
|
||||||
@@ -298,3 +300,39 @@ class UIOTest(OSDiagnostics):
|
|||||||
print("An unexpected error occured.")
|
print("An unexpected error occured.")
|
||||||
print("Completed Test 1/2: BytesIO - FAILED")
|
print("Completed Test 1/2: BytesIO - FAILED")
|
||||||
self.failedtests["BytesIO"] = ex.errno
|
self.failedtests["BytesIO"] = ex.errno
|
||||||
|
def teststringio(self):
|
||||||
|
try:
|
||||||
|
buffer = io.StringIO()
|
||||||
|
|
||||||
|
buffer.write('Hello, ')
|
||||||
|
buffer.write('Pybricks string stream!')
|
||||||
|
|
||||||
|
current_content = buffer.getvalue()
|
||||||
|
print(f"Buffer content (via getvalue()): {current_content}")
|
||||||
|
|
||||||
|
print(f"Current cursor position: {buffer.tell()}")
|
||||||
|
# TODO: After testing that StringIO 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}")
|
||||||
|
|
||||||
|
print(f"Current cursor position after reading: {buffer.tell()}")
|
||||||
|
|
||||||
|
buffer.close()
|
||||||
|
print("Buffer was closed successfully.")
|
||||||
|
print("Completed Test 2/2: StringIO - SUCCESSFUL")
|
||||||
|
self.successfultests += 1
|
||||||
|
except Exception as ex:
|
||||||
|
print("An unexpected error occured.")
|
||||||
|
print("Completed Test 2/2: StringIO - FAILED")
|
||||||
|
self.failedtests["StringIO"] = ex.errno
|
||||||
|
|
||||||
|
def print_results(self):
|
||||||
|
self.testbytesio()
|
||||||
|
self.teststringio()
|
||||||
|
print(f"\n=== Results: {self.successfultests}/2 tests passed ===")
|
||||||
|
if self.failedtests:
|
||||||
|
print("Failed tests:")
|
||||||
|
for key, value in self.failedtests.items():
|
||||||
|
print(f" {key}: {value}")
|
||||||
Reference in New Issue
Block a user