Add CI tests using the standard test interface

This commit is contained in:
Serhii Turivnyi 2018-06-12 13:34:14 +03:00
parent 25c66aad7e
commit 7932540cb0
5 changed files with 305 additions and 9 deletions

View File

@ -0,0 +1,63 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/python/gettext-tests
# Description: Functional tests for gettext.
# Author: Pooja Yadav <poyadav@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2015 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/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/python/gettext-tests
export TESTVERSION=1.0
BUILT_FILES=
FILES=$(METADATA) gettext_test.py Makefile test_data.py runtest.sh
.PHONY: all install download clean
run: $(FILES) build
./runtest.sh
build: $(BUILT_FILES)
test -x runtest.sh || chmod a+x runtest.sh
clean:
rm -f *~ $(BUILT_FILES)
include /usr/share/rhts/lib/rhts-make.include
$(METADATA): Makefile
@echo "Owner: Pooja Yadav <poyadav@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: Functional test for the gettext module" >> $(METADATA)
@echo "Type: Functional" >> $(METADATA)
@echo "TestTime: 5m" >> $(METADATA)
@echo "RunFor: python" >> $(METADATA)
@echo "Requires: python" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
rhts-lint $(METADATA)

View File

@ -0,0 +1,158 @@
# -*- coding: utf-8 -*-
import subprocess
import gettext
import os
import logging
"""
Saving logs
"""
logging.basicConfig(level=logging.INFO)
test_data = {"fr_FR": '''msgstr "Bonjour le monde!"''',
"de_DE": '''msgstr "Hallo Welt!"''',
"es_ES": '''msgstr "Hola Mundo!"''',
"it_IT": '''msgstr "Ciao mondo!"''',
"pt_BR": '''msgstr "Olá Mundo!"''',
"ja_JP": '''msgstr "「こんにちは世界」"''',
"ko_KR": '''msgstr "안녕하세요!"''',
"ru_RU": '''msgstr "Привет мир!"''',
"zh_CN": '''msgstr "你好,世界!"''',
"zh_TW": '''msgstr "你好,世界!"'''}
logging.info("TEST RESULTS FOR ATOMIC HOST\n\n")
def locale():
"""
Check common files for locale support
"""
try:
locale = subprocess.Popen(["locale", "-a"], stdout=subprocess.PIPE)
stddata = locale.communicate()
if stddata:
actual = stddata[0].split('\n')[:-1]
else:
logging.error("Locale support Test: ERROR\n")
return
expected = ['en_US', 'en_US.iso88591',
'en_US.iso885915', 'en_US.utf8']
if set(expected).issubset(set(actual)):
logging.info("Locale support Test: SUCCESS\n")
else:
logging.error("Locale support Test: ERROR\n")
except OSError as e:
logging.error("Locale support Test: OSError\n")
def check_gettext():
"""
Check if gettext present
"""
try:
cmd1 = ['rpm', '-q', 'gettext']
p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
stddata, stderr = p1.communicate()
logging.info("gettext version: %s" % (stddata))
if 'gettext' in stddata:
logging.info("GNU Internationalized Utilities Test: SUCCESS\n")
else:
logging.error("GNU Internationalized Utilities Test: ERROR\n")
except OSError as e:
logging.error("GNU Internationalized Utilities Test: OSError\n")
def pot_creation():
"""
Creates hello.pot file using test_data.py file
"""
try:
pot_file = subprocess.Popen(
"xgettext -d 'hello' -o hello.pot test_data.py", shell=True)
pot = pot_file.communicate()
except OSError as e:
logging.error(".pot file creation failed: OSError\n")
def make_dir(locale):
path = "./locale/%s/LC_MESSAGES" % (locale)
os.makedirs(path)
def po_creation(locale):
"""
creates .po file using hello.pot file
"""
try:
po_fr = subprocess.Popen(
"msginit --no-translator -l %s -i hello.pot -o ./locale/%s/LC_MESSAGES/%s.po" % (locale, locale, locale), shell=True)
po_fr = po_fr.communicate()
except OSError as e:
logging.error(".po file creation failed: OSError\n")
def trans(locale):
"""
Updates .po file with the translations for corresponding
language
"""
if locale in test_data.keys():
data = test_data[locale]
with open('./locale/%s/LC_MESSAGES/%s.po' % (locale, locale), 'rw') as f1:
data1 = f1.readlines()
data1.pop()
data1.append(data)
for index, data in enumerate(data1):
if "Content-Type" in data:
data1[index] = '"Content-Type: text/plain; charset=UTF-8\\n"\n'
with open('./locale/%s/LC_MESSAGES/%s' % (locale, locale) + ".po", 'w') as f1:
for line in data1:
f1.write(line)
def mo_creation(locale):
"""
Creates .mo file for different locale form .po file
"""
try:
mo_fr = subprocess.Popen("msgfmt ./locale/%s/LC_MESSAGES/%s.po --output-file ./locale/%s/LC_MESSAGES/%s.mo" %
(locale, locale, locale, locale), shell=True)
mo_fr = mo_fr.communicate()
except OSError as e:
logging.error(".mo file creation failed: OSError\n")
def check_trans(locale):
"""
Verify if the output is correct for different language
"""
try:
stddata = subprocess.check_output(
'LANGUAGE=%s python test_data.py %s' % (locale, locale), shell=True)
if stddata.strip() == test_data[locale].strip('msgstr "'):
logging.info("Translation Test for %s: SUCCESS\n" % (locale))
else:
logging.error("Translation Test for %s: ERROR\n" % (locale))
except OSError as e:
logging.error("Translation Test for %s: OSERROR\n" % (locale))
def del_locale():
try:
subprocess.call(['rm', '-rf', './locale'])
except OSError as e:
logging.error("OSError\n")
if __name__ == "__main__":
locale()
check_gettext()
pot_creation()
for locale in test_data.keys():
make_dir(locale)
po_creation(locale)
trans(locale)
mo_creation(locale)
check_trans(locale)
del_locale()

View File

@ -0,0 +1,53 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/python/gettext-tests
# Description: Functional tests for gettext to check i18n features.
# Author: Pooja Yadav <poyadav@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2010 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# 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, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh
. /usr/lib/beakerlib/beakerlib.sh
PACKAGE="gettext"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
rlRun "cp test_data.py gettext_test.py $TmpDir"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
rlLog "Run gettext_test.py"
rlRun "python gettext_test.py"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View File

@ -0,0 +1,13 @@
import gettext
import sys
def hello(locale):
# Set up message catalog access
t = gettext.translation('%s' % (locale), 'locale', fallback=True)
_ = t.ugettext
s = _(u'Hello World!').encode('utf-8')
print s
hello(sys.argv[1])

View File

@ -1,16 +1,25 @@
---
# Tests run on Atomic, Classic and Container
# Tests for Atomic Host
- hosts: localhost
tags:
- atomic
roles:
- role: standard-test-beakerlib
tags:
- atomic
- classic
- container
repositories:
- repo: "https://src.fedoraproject.org/tests/gettext.git"
dest: "gettext"
tests:
- gettext/gettext-tests
- gettext-tests
# Tests for Classic and container
- hosts: localhost
tags:
- classic
- container
roles:
- role: standard-test-beakerlib
tests:
- gettext-tests
required_packages:
- gettext