Example: 50-OpenMV-Boards/99-Tests/unittests.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# OpenMV单元测试
#
import os
import gc

TEST_DIR = "unittest"
TEMP_DIR = "unittest/temp"
DATA_DIR = "unittest/data"
SCRIPT_DIR = "unittest/script"

if not (TEST_DIR in os.listdir("")):
    raise Exception("Unittest dir not found!")

print("")
test_failed = False


def print_result(test, result):
    s = "Unittest (%s)" % (test)
    padding = "." * (60 - len(s))
    print(s + padding + result)


for test in sorted(os.listdir(SCRIPT_DIR)):
    if test.endswith(".py"):
        test_result = "PASSED"
        test_path = "/".join((SCRIPT_DIR, test))
        try:
            exec(open(test_path).read())
            gc.collect()
            if unittest(DATA_DIR, TEMP_DIR) is False:
                raise Exception()
        except Exception as e:
            if "unavailable" in str(e):
                test_result = "DISABLED"
            else:
                test_failed = True
                test_result = "FAILED"
        print_result(test, test_result)

if test_failed:
    print("\nSome tests have FAILED!!!\n\n")
else:
    print("\nAll tests PASSED.\n\n")

results matching ""

    No results matching ""