From 26b6c3301124d153cda957a92f4ca930d8b983fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20=C5=A0igut?= Date: Thu, 11 Apr 2024 12:38:58 +0200 Subject: [PATCH] Import CI tests from RHEL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-Authored-By: Miro HronĨok --- .fmf/version | 1 + plan.fmf | 4 ++ tests/smoke/main.fmf | 5 +++ tests/smoke/pyyaml_dump.py | 3 ++ tests/smoke/pyyaml_load.py | 13 ++++++ tests/smoke/pyyaml_object.py | 24 ++++++++++ tests/smoke/pyyaml_parse.py | 9 ++++ tests/smoke/runtest.sh | 86 ++++++++++++++++++++++++++++++++++++ 8 files changed, 145 insertions(+) create mode 100644 .fmf/version create mode 100644 plan.fmf create mode 100644 tests/smoke/main.fmf create mode 100644 tests/smoke/pyyaml_dump.py create mode 100644 tests/smoke/pyyaml_load.py create mode 100644 tests/smoke/pyyaml_object.py create mode 100644 tests/smoke/pyyaml_parse.py create mode 100755 tests/smoke/runtest.sh diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/plan.fmf b/plan.fmf new file mode 100644 index 0000000..e6427de --- /dev/null +++ b/plan.fmf @@ -0,0 +1,4 @@ +discover: + how: fmf +execute: + how: tmt diff --git a/tests/smoke/main.fmf b/tests/smoke/main.fmf new file mode 100644 index 0000000..7d9c513 --- /dev/null +++ b/tests/smoke/main.fmf @@ -0,0 +1,5 @@ +test: ./runtest.sh +framework: beakerlib +require: + - python3-pyyaml +duration: 5m diff --git a/tests/smoke/pyyaml_dump.py b/tests/smoke/pyyaml_dump.py new file mode 100644 index 0000000..a6f4a6d --- /dev/null +++ b/tests/smoke/pyyaml_dump.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python +import yaml +print(yaml.dump({'name': 'Silenthand Olleander', 'race': 'Human', 'traits': ['ONE_HAND', 'ONE_EYE']})) diff --git a/tests/smoke/pyyaml_load.py b/tests/smoke/pyyaml_load.py new file mode 100644 index 0000000..6bf48f2 --- /dev/null +++ b/tests/smoke/pyyaml_load.py @@ -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) diff --git a/tests/smoke/pyyaml_object.py b/tests/smoke/pyyaml_object.py new file mode 100644 index 0000000..b689c05 --- /dev/null +++ b/tests/smoke/pyyaml_object.py @@ -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)) diff --git a/tests/smoke/pyyaml_parse.py b/tests/smoke/pyyaml_parse.py new file mode 100644 index 0000000..3850b78 --- /dev/null +++ b/tests/smoke/pyyaml_parse.py @@ -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))) diff --git a/tests/smoke/runtest.sh b/tests/smoke/runtest.sh new file mode 100755 index 0000000..cef0e09 --- /dev/null +++ b/tests/smoke/runtest.sh @@ -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 +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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