2020-05-19 08:18:53 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2020 Intel Corporation
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
2020-12-12 06:55:15 +08:00
|
|
|
This test file contains foundational testcases for Twister tool
|
2020-05-19 08:18:53 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
|
2020-12-08 01:29:36 +08:00
|
|
|
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
|
2020-05-19 08:18:53 +08:00
|
|
|
|
|
|
|
import scl
|
2020-12-12 06:55:15 +08:00
|
|
|
from twisterlib import TwisterConfigParser
|
2020-05-19 08:18:53 +08:00
|
|
|
|
|
|
|
def test_yamlload():
|
|
|
|
""" Test to check if loading the non-existent files raises the errors """
|
|
|
|
filename = 'testcase_nc.yaml'
|
|
|
|
with pytest.raises(FileNotFoundError):
|
|
|
|
scl.yaml_load(filename)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("filename, schema",
|
|
|
|
[("testcase_correct_schema.yaml", "testcase-schema.yaml"),
|
|
|
|
("platform_correct_schema.yaml", "platform-schema.yaml")])
|
|
|
|
def test_correct_schema(filename, schema, test_data):
|
|
|
|
""" Test to validate the testcase schema"""
|
|
|
|
filename = test_data + filename
|
2020-12-08 01:29:36 +08:00
|
|
|
schema = scl.yaml_load(ZEPHYR_BASE +'/scripts/schemas/twister//' + schema)
|
2020-12-12 06:55:15 +08:00
|
|
|
data = TwisterConfigParser(filename, schema)
|
2020-05-19 08:18:53 +08:00
|
|
|
data.load()
|
|
|
|
assert data
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("filename, schema",
|
|
|
|
[("testcase_incorrect_schema.yaml", "testcase-schema.yaml"),
|
|
|
|
("platform_incorrect_schema.yaml", "platform-schema.yaml")])
|
|
|
|
def test_incorrect_schema(filename, schema, test_data):
|
|
|
|
""" Test to validate the exception is raised for incorrect testcase schema"""
|
|
|
|
filename = test_data + filename
|
2020-12-08 01:29:36 +08:00
|
|
|
schema = scl.yaml_load(ZEPHYR_BASE +'/scripts/schemas/twister//' + schema)
|
2020-05-19 08:18:53 +08:00
|
|
|
with pytest.raises(Exception) as exception:
|
|
|
|
scl.yaml_load_verify(filename, schema)
|
|
|
|
assert str(exception.value) == "Schema validation failed"
|