From e027e70baafd0124b493b85c5242098410a9a331 Mon Sep 17 00:00:00 2001 From: Fabian Arrotin Date: Oct 18 2016 15:18:09 +0000 Subject: Merge pull request #23 from DriesVerachtert/master basic tests for python-iniparse --- diff --git a/tests/p_python-iniparse/0-install-python-iniparse.sh b/tests/p_python-iniparse/0-install-python-iniparse.sh new file mode 100755 index 0000000..98f61ca --- /dev/null +++ b/tests/p_python-iniparse/0-install-python-iniparse.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Author Dries Verachtert + +# Install python-iniparse: required by yum so a quite important package in CentOS +t_Log "Running $0 - installing python-iniparse." + +t_InstallPackage python-iniparse diff --git a/tests/p_python-iniparse/1-test-python-iniparse.sh b/tests/p_python-iniparse/1-test-python-iniparse.sh new file mode 100755 index 0000000..73887cd --- /dev/null +++ b/tests/p_python-iniparse/1-test-python-iniparse.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Author: Dries Verachtert + +t_Log "Running $0 - test python-iniparse" + +TESTINI=`mktemp` + +# Test contents: a part of /etc/yum.conf +cat > $TESTINI <<'EOF' +[main] +cachedir=/var/cache/yum/$basearch/$releasever +keepcache=0 +debuglevel=2 +logfile=/var/log/yum.log +EOF + +cat << EOF | python - $TESTINI | grep -q '/var/log/yum.log' +import sys +from iniparse import INIConfig + +cfg = INIConfig(open(sys.argv[1])) +print cfg.main.logfile +EOF +t_CheckExitStatus $? + +# A second test with multiple sections +cat > $TESTINI <<'EOF' +# comment 1 +[section1] +# comment 2 +section1var1=val1 +[section2] +# comment 3 +[section3] +section3var1=val2 +section3var2=val3 +EOF + +cat << EOF | python - $TESTINI | grep -q "\['section1', 'section2', 'section3'\] val1 val2 val3" +import sys +from iniparse import INIConfig + +cfg = INIConfig(open(sys.argv[1])) +print str(list(cfg)) + ' ' + cfg.section1.section1var1 + ' ' + cfg.section3.section3var1 + ' ' + cfg.section3.section3var2 +EOF + +t_CheckExitStatus $? + +rm -f $TESTINI