bstinson / centos / t_functional

Forked from centos/t_functional 4 years ago
Clone

Blame tests/p_python-iniparse/1-test-python-iniparse.sh

Dries Verachtert 65aada
#!/bin/bash
Dries Verachtert 65aada
# Author: Dries Verachtert <dries.verachtert@dries.eu>
Dries Verachtert 65aada
Dries Verachtert 65aada
t_Log "Running $0 - test python-iniparse"
Dries Verachtert 65aada
Pablo Greco 3bde5e
if [ "$centos_ver" -ge 8 ] ; then
Pablo Greco 3bde5e
PYTHON=python3
Pablo Greco 3bde5e
else
Pablo Greco 3bde5e
PYTHON=python
Pablo Greco 3bde5e
fi
Pablo Greco 3bde5e
Dries Verachtert 65aada
TESTINI=`mktemp`
Dries Verachtert 65aada
Dries Verachtert 65aada
# Test contents: a part of /etc/yum.conf
Dries Verachtert 65aada
cat > $TESTINI <<'EOF'
Dries Verachtert 65aada
[main]
Dries Verachtert 65aada
cachedir=/var/cache/yum/$basearch/$releasever
Dries Verachtert 65aada
keepcache=0
Dries Verachtert 65aada
debuglevel=2
Dries Verachtert 65aada
logfile=/var/log/yum.log
Dries Verachtert 65aada
EOF
Dries Verachtert 65aada
Pablo Greco 3bde5e
cat << EOF | $PYTHON - $TESTINI | grep -q '/var/log/yum.log'
Dries Verachtert 65aada
import sys
Dries Verachtert 65aada
from iniparse import INIConfig
Dries Verachtert 65aada
Dries Verachtert 65aada
cfg = INIConfig(open(sys.argv[1]))
Pablo Greco 3bde5e
print (cfg.main.logfile)
Dries Verachtert 65aada
EOF
Dries Verachtert 65aada
t_CheckExitStatus $?
Dries Verachtert 65aada
Dries Verachtert 65aada
# A second test with multiple sections
Dries Verachtert 65aada
cat > $TESTINI <<'EOF'
Dries Verachtert 65aada
# comment 1
Dries Verachtert 65aada
[section1]
Dries Verachtert 65aada
# comment 2
Dries Verachtert 65aada
section1var1=val1
Dries Verachtert 65aada
[section2]
Dries Verachtert 65aada
# comment 3
Dries Verachtert 65aada
[section3]
Dries Verachtert 65aada
section3var1=val2
Dries Verachtert 65aada
section3var2=val3
Dries Verachtert 65aada
EOF
Dries Verachtert 65aada
Pablo Greco 3bde5e
cat << EOF | $PYTHON - $TESTINI | grep -q "\['section1', 'section2', 'section3'\] val1 val2 val3"
Dries Verachtert 65aada
import sys
Dries Verachtert 65aada
from iniparse import INIConfig
Dries Verachtert 65aada
Dries Verachtert 65aada
cfg = INIConfig(open(sys.argv[1]))
Pablo Greco 3bde5e
print (str(list(cfg)) + ' ' + cfg.section1.section1var1 + ' ' + cfg.section3.section3var1 + ' ' + cfg.section3.section3var2)
Dries Verachtert 65aada
EOF
Dries Verachtert 65aada
Dries Verachtert 65aada
t_CheckExitStatus $?
Dries Verachtert 65aada
Dries Verachtert 65aada
rm -f $TESTINI