From e1a064810f56b34d78ca9d000120b8a93323b501 Mon Sep 17 00:00:00 2001 From: Jakub Filak Date: Wed, 23 Jul 2014 11:00:28 +0200 Subject: [LIBREPORT PATCH 56/93] testsuite: report python sanity tests Signed-off-by: Jakub Filak --- tests/Makefile.am | 3 ++- tests/local.at | 13 +++++++++++++ tests/osinfo.at | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/report_python.at | 33 ++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/report_python.at diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ec40e1..750fa16 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -38,7 +38,8 @@ TESTSUITE_AT = \ reported_to.at \ make_description.at \ libreport_types.at \ - xml_definition.at + xml_definition.at \ + report_python.at EXTRA_DIST += $(TESTSUITE_AT) TESTSUITE = $(srcdir)/testsuite diff --git a/tests/local.at b/tests/local.at index 758906d..b5fae97 100644 --- a/tests/local.at +++ b/tests/local.at @@ -24,4 +24,17 @@ AT_COMPILE([$1]) AT_CHECK([./$1], 0, [ignore], [ignore]) AT_CLEANUP]) +# ------------------------ +# AT_PYTESTFUN(NAME, SOURCE) +# ------------------------ + +# Create a test named NAME by running Python file with contents SOURCE. The +# stdout and stderr output of the Python program is ignored by Autotest. + +m4_define([AT_PYTESTFUN], +[AT_SETUP([$1]) +AT_DATA([$1], [$2]) +AT_CHECK([PYTHONPATH=../../../src python ./$1], 0, [ignore], [ignore]) +AT_CLEANUP]) + AT_INIT diff --git a/tests/osinfo.at b/tests/osinfo.at index 529ca13..b57452d 100644 --- a/tests/osinfo.at +++ b/tests/osinfo.at @@ -393,3 +393,55 @@ int main(void) return 0; } ]]) + +## ------------------- ## +## parse_osinfo_python ## +## ------------------- ## + +AT_PYTESTFUN([parse_osinfo_python], +[[import sys + +sys.path.insert(0, "../../../src/report-python/.libs") + +report = __import__("report-python", globals(), locals(), [], -1) +sys.modules["report"] = report + +lines = [ + 'NAME=fedora', + 'VERSION="20 (Heisenbug)"', + 'ID=fedora', + 'VERSION_ID=20', + 'PRETTY_NAME="Fedora 20 (Heisenbug)"', + 'ANSI_COLOR="0;34"', + 'CPE_NAME="cpe:/o:fedoraproject:fedora:20"', + 'HOME_URL="https://fedoraproject.org/"', + 'BUG_REPORT_URL="https://bugzilla.redhat.com/"', + 'REDHAT_BUGZILLA_PRODUCT="Fedora"', + 'REDHAT_BUGZILLA_PRODUCT_VERSION=20', + 'REDHAT_SUPPORT_PRODUCT="Fedora"', + 'REDHAT_SUPPORT_PRODUCT_VERSION=20', +] + +expected = { + 'NAME':'fedora', + 'VERSION':'20 (Heisenbug)', + 'ID':'fedora', + 'VERSION_ID':'20', + 'PRETTY_NAME':'Fedora 20 (Heisenbug)', + 'ANSI_COLOR':'0;34', + 'CPE_NAME':'cpe:/o:fedoraproject:fedora:20', + 'HOME_URL':'https://fedoraproject.org/', + 'BUG_REPORT_URL':'https://bugzilla.redhat.com/', + 'REDHAT_BUGZILLA_PRODUCT':'Fedora', + 'REDHAT_BUGZILLA_PRODUCT_VERSION':'20', + 'REDHAT_SUPPORT_PRODUCT':'Fedora', + 'REDHAT_SUPPORT_PRODUCT_VERSION':'20' +} + +osrel = report.parse_os_release_lines(lines) + +print sorted(expected.items()) +print sorted(osrel.items()) + +sys.exit(not bool(osrel == expected)) +]]) diff --git a/tests/report_python.at b/tests/report_python.at new file mode 100644 index 0000000..17e4fb3 --- /dev/null +++ b/tests/report_python.at @@ -0,0 +1,33 @@ +# -*- Autotest -*- + +AT_BANNER([report_python]) + +## ----------------------- ## +## get_from_etc_os_release ## +## ----------------------- ## + +AT_PYTESTFUN([get_from_etc_os_release], +[[import sys + +sys.path.insert(0, "../../../src/report-python/.libs") + +report = __import__("report-python", globals(), locals(), [], -1) +sys.modules["report"] = report + +import os + +if not os.path.exists("/etc/os-release"): + print "Cannot run the test: '/etc/os-release' does not exist" + sys.exit(1) + +exit_code = 0 +if report.getProduct_fromOSRELEASE() != report.getProduct(): + print "getProduct() did not return PRODUCT from /etc/os-release" + exit_code += 1 + +if report.getVersion_fromOSRELEASE() != report.getVersion(): + print "getVersion() did not return PRODUCT from /etc/os-release" + exit_code += 1 + +sys.exit(exit_code) +]]) diff --git a/tests/testsuite.at b/tests/testsuite.at index 97b2442..a569457 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -13,3 +13,4 @@ m4_include([reported_to.at]) m4_include([make_description.at]) m4_include([libreport_types.at]) m4_include([xml_definition.at]) +m4_include([report_python.at]) -- 1.8.3.1