Import CI tests from RHEL

This is from RHEL distgit tests/PyYAML, directory Sanity/Smoke.

The original commit hash: fd668cd6d20ca9c46d9bfa5ccf34f3a925317b25

Only necessary files were kept.

Co-Authored-By: Lukas Zachar <lzachar@redhat.com>
Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
This commit is contained in:
Štěpán Šigut 2024-04-11 12:38:58 +02:00 committed by Miro Hrončok
parent a32a024c18
commit 26b6c33011
8 changed files with 145 additions and 0 deletions

1
.fmf/version Normal file
View File

@ -0,0 +1 @@
1

4
plan.fmf Normal file
View File

@ -0,0 +1,4 @@
discover:
how: fmf
execute:
how: tmt

5
tests/smoke/main.fmf Normal file
View File

@ -0,0 +1,5 @@
test: ./runtest.sh
framework: beakerlib
require:
- python3-pyyaml
duration: 5m

View File

@ -0,0 +1,3 @@
#!/usr/bin/env python
import yaml
print(yaml.dump({'name': 'Silenthand Olleander', 'race': 'Human', 'traits': ['ONE_HAND', 'ONE_EYE']}))

View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
import yaml
documents = """
---
name: foo
---
name: bar
---
name: foobar
"""
for data in yaml.load_all(documents, Loader=yaml.SafeLoader):
print(data)

View File

@ -0,0 +1,24 @@
import yaml
class Hero:
def __init__(self, name, hp, sp):
self.name = name
self.hp = hp
self.sp = sp
def __repr__(self):
return "%s(name=%r, hp=%r, sp=%r)" % (
self.__class__.__name__, self.name, self.hp, self.sp)
STRING = """
!!python/object:__main__.Hero
name: Welthyr Syxgon
hp: 1200
sp: 0
"""
try:
yaml.load(STRING, Loader=yaml.SafeLoader)
raise RuntimeError("Didn't raise exception")
except yaml.constructor.ConstructorError:
pass
print(yaml.unsafe_load(STRING))

View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
import yaml
document = """
a: 1
b:
c: 3
d: 4
"""
print(yaml.dump(yaml.load(document, Loader=yaml.SafeLoader)))

86
tests/smoke/runtest.sh Executable file
View File

@ -0,0 +1,86 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/PyYAML/Sanity/Smoke
# Description: Smoke test for this component
# Author: Stepan Sigut <ssigut@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGES=${PACKAGES:-"python3 python3-pyyaml"}
PYTHON=${PYTHON:-"python3"}
PATTERN1="{'name': 'foo'}
{'name': 'bar'}
{'name': 'foobar'}"
PATTERN3="name: Silenthand Olleander
race: Human
traits: [ONE_HAND, ONE_EYE]"
PATTERN4="a: 1
b: {c: 3, d: 4}"
PATTERN5="Hero(name='Welthyr Syxgon', hp=1200, sp=0)"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
set -o pipefail
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
# export python's MAJOR and MINOR version
rlRun "export $($PYTHON -c \
'import sys; print("MAJOR={0} MINOR={1}".format(\
sys.version_info[0],sys.version_info[1]))')"
rlRun "cp py* $TmpDir"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest "Running pyyaml_load.py"
rlRun "$PYTHON pyyaml_load.py | tee dump.log" 0
rlAssertGrep "$PATTERN1" "dump.log"
rlPhaseEnd
rlPhaseStartTest "Running pyyaml_dump.py"
rlRun "$PYTHON pyyaml_dump.py | tee dump.log" 0
rlAssertGrep "$PATTERN3" "dump.log"
rlPhaseEnd
rlPhaseStartTest "Running pyyaml_parse.py"
rlRun "$PYTHON pyyaml_parse.py | tee dump.log" 0
rlAssertGrep "$PATTERN4" "dump.log"
rlPhaseEnd
rlPhaseStartTest "Running pyyaml_object.py"
rlRun "$PYTHON pyyaml_object.py | tee dump.log" 0
rlAssertGrep "$PATTERN5" "dump.log"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd