twister: Allow an empty quarantine file

Added an exception to scl.py module, to not process an empty
yaml file, because of error from pykwalify. New exception
is handled when processing quarantine files, to allow
an empty file.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
This commit is contained in:
Grzegorz Chwierut 2023-09-15 15:21:06 +02:00 committed by Carles Cufí
commit f53a0e9ce5
3 changed files with 20 additions and 3 deletions

View file

@ -21,6 +21,11 @@ except ImportError:
log = logging.getLogger("scl")
class EmptyYamlFileException(Exception):
pass
#
#
def yaml_load(filename):
@ -78,5 +83,7 @@ def yaml_load_verify(filename, schema):
"""
# 'document.yaml' contains a single YAML document.
y = yaml_load(filename)
if not y:
raise EmptyYamlFileException('No data in YAML file: %s' % filename)
_yaml_validate(y, schema)
return y

View file

@ -194,8 +194,11 @@ class TestPlan:
raise TwisterRuntimeError("No quarantine list given to be verified")
if ql:
for quarantine_file in ql:
# validate quarantine yaml file against the provided schema
scl.yaml_load_verify(quarantine_file, self.quarantine_schema)
try:
# validate quarantine yaml file against the provided schema
scl.yaml_load_verify(quarantine_file, self.quarantine_schema)
except scl.EmptyYamlFileException:
logger.debug(f'Quarantine file {quarantine_file} is empty')
self.quarantine = Quarantine(ql)
def load(self):
@ -454,7 +457,7 @@ class TestPlan:
# if there is already an existed <board>_<revision>.yaml, then use it to
# load platform directly, otherwise, iterate the directory to
# get all valid board revision based on each <board>_<revision>.conf.
if not "@" in platform.name:
if '@' not in platform.name:
tmp_dir = os.listdir(os.path.dirname(file))
for item in tmp_dir:
# Need to make sure the revision matches

View file

@ -247,3 +247,10 @@ def test_yaml_validate(schema_exists, validate, expected_error):
core_mock.assert_called_once()
else:
core_mock.assert_not_called()
def test_yaml_load_empty_file(tmp_path):
quarantine_file = tmp_path / 'empty_quarantine.yml'
quarantine_file.write_text("# yaml file without data")
with pytest.raises(scl.EmptyYamlFileException):
scl.yaml_load_verify(quarantine_file, None)