Skip to content

Commit

Permalink
Fix tmt test import error when restraint metadata attributes are em…
Browse files Browse the repository at this point in the history
…pty (#3451)
  • Loading branch information
therazix authored Jan 9, 2025
1 parent d686811 commit 9cc6692
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions tests/test/import/data/parent/empty-dependencies/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[General]
name=/empty_dependencies
owner=Nobody <nobody@localhost.localdomain>
description=Empty dependencies
license=MIT
confidential=no
destructive=no

[restraint]
entry_point=bash -x ./runtest.sh
dependencies=
softDependencies=
max_time=5m
3 changes: 3 additions & 0 deletions tests/test/import/data/parent/empty-dependencies/runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "A simple test"
10 changes: 10 additions & 0 deletions tests/test/import/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ rlJournalStart
rlRun 'popd'
rlPhaseEnd

rlPhaseStartTest "Empty dependencies (Restraint)"
rlRun 'pushd $tmp/data/parent/empty-dependencies'
rlRun -s 'tmt test import --restraint --no-nitrate --no-purpose' '0'
rlAssertExists "main.fmf"
rlRun 'cat main.fmf'
rlAssertGrep 'require:\s*\[\]' "main.fmf"
rlAssertGrep 'recommend:\s*\[\]' "main.fmf"
rlRun 'popd'
rlPhaseEnd

rlPhaseStartTest "Target run having a single line"
rlRun 'pushd $tmp/data/parent/single-line-run'
rlRun -s 'tmt test import --makefile --no-nitrate --no-purpose' '0'
Expand Down
4 changes: 2 additions & 2 deletions tmt/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ def sanitize_name(name: str) -> str:
if requires:
data['require'] = [
sanitize_name(require.strip()) for line in requires
for require in line.split(rec_separator)]
for require in line.split(rec_separator) if require.strip()]
echo(style('require: ', fg='green') + ' '.join(data['require']))

# Requires or softDependencies (optional) goes to recommend
recommends = re.findall(regex_recommend, testinfo, re.MULTILINE)
if recommends:
data['recommend'] = [
sanitize_name(recommend.strip()) for line in recommends
for recommend in line.split(rec_separator)]
for recommend in line.split(rec_separator) if recommend.strip()]
echo(
style('recommend: ', fg='green') + ' '.join(data['recommend']))

Expand Down

0 comments on commit 9cc6692

Please sign in to comment.