# Serial Flux Python example: Exception-safe automated test
#
# Shows a recommended pattern that always stops logging even when
# a test step raises an exception.

import time

def test_step(name, delay=0.25):
    print(f"STEP: {name}")
    time.sleep(delay)

SF.startLogging()

try:
    test_step("Reset target")
    test_step("Read version")
    test_step("Configure target")
    test_step("Run functional test")
    print("RESULT: PASS")

except Exception as exc:
    print(f"RESULT: ERROR - {exc}")
    raise

finally:
    SF.stopLogging()
    print("Logging closed.")
