Add CI Tests

Resolves: rhbz#2055493
Signed-off-by: Sundeep Anand <suanand@redhat.com>
This commit is contained in:
Sundeep Anand 2022-02-16 18:22:59 +05:30
parent 689772e0c9
commit 97bd0a8960
6 changed files with 164 additions and 1 deletions

View File

@ -3,4 +3,4 @@ product_versions:
- rhel-9 - rhel-9
decision_context: osci_compose_gate decision_context: osci_compose_gate
rules: rules:
- !PassingTestCaseRule {test_case_name: desktop-qe.desktop-ci.tier1-gating.functional} - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

View File

@ -0,0 +1,17 @@
<test>
<entry>
<_name>Foo</_name>
</entry>
<entry>
<!-- This is the comment on the first Bar -->
<_name msgctxt="1">Bar</_name>
</entry>
<entry>
<!-- This is the comment on the second Bar -->
<_name msgctxt="2">Bar</_name>
</entry>
<entry>
<!-- This is the comment on Baz -->
<_name>Baz</_name>
</entry>
</test>

109
tests/intltool_tests.py Normal file
View File

@ -0,0 +1,109 @@
#!/usr/bin/python3
import logging
import subprocess
from difflib import Differ
logging.basicConfig(level=logging.INFO)
COMMANDS = [
"intltool-extract",
"intltool-merge"
]
INPUT_FILE = "cases/context.xml.in"
def test_intltool_installation(cmd: str):
"""
Check if intltool is installed correctly
"""
try:
intltool_cmd = subprocess.Popen([cmd], stdout=subprocess.PIPE)
intltool_cmd_execution_response = intltool_cmd.communicate()
assert "Usage" in str(intltool_cmd_execution_response)
except FileNotFoundError:
logging.error(f"Either {cmd} is not installed or not accessible.")
except OSError:
logging.error(f"Some OSError occurred while executing {cmd}")
except AssertionError:
logging.error(f"[CMD] output does not include text: Usage.")
else:
logging.info(f"Execution of {cmd} succeed. Test Passed.")
def test_intltool_extract(cmd, input_file):
"""
Check intltool extract behavior
"""
try:
intltool_extract = subprocess.Popen(
[cmd, "--type=gettext/xml", input_file, "--update"],
stdout=subprocess.PIPE)
intltool_extract_execution_response = intltool_extract.communicate()
assert "Wrote" in str(intltool_extract_execution_response)
except AssertionError:
logging.error(f"Writing output file for {input_file} file failed.")
except Exception as e:
logging.error(e)
else:
logging.info(f"Writing output file for {input_file} succeed.")
comparison_test_pass = True
with open("{}.h".format(input_file)) as output_file, open("results/{}.h".format("context.xml.in")) as refer_file:
differ = Differ()
for line in differ.compare(output_file.readlines(), refer_file.readlines()):
if line.startswith("+") or line.startswith("-"):
comparison_test_pass = False
try:
assert comparison_test_pass
except AssertionError:
logging.error("Extracted file does NOT match with the result. Test failed.")
else:
logging.info("Extracted file does match with the result. Test passed.")
def test_intltool_merge(cmd, input_file):
"""
Check intltool merge behavior
"""
merged_file = "context.xml"
try:
intltool_merge = subprocess.Popen(
[cmd, "-o", "cases", input_file, "cases/{}".format(merged_file)],
stdout=subprocess.PIPE)
intltool_merge_execution_response = intltool_merge.communicate()
assert "Merging" in str(intltool_merge_execution_response)
except AssertionError:
logging.error(f"Writing output file for {input_file} file failed.")
except Exception as e:
logging.error(e)
else:
logging.info(f"Writing output file for {input_file} succeed.")
comparison_test_pass = True
with open("cases/{}".format(merged_file)) as output_file, open("results/{}".format(merged_file)) as refer_file:
differ = Differ()
for line in differ.compare(output_file.readlines(), refer_file.readlines()):
if line.startswith("+") or line.startswith("-"):
comparison_test_pass = False
try:
assert comparison_test_pass
except AssertionError:
logging.error("Merged file does NOT match with the result. Test failed.")
else:
logging.info("Merged file does match with the result. Test passed.")
if __name__ == "__main__":
"""
Executes test cases
"""
logging.info("Executing test cases for Intltool..")
for CMD in COMMANDS:
test_intltool_installation(CMD)
test_intltool_extract(COMMANDS[0], INPUT_FILE)
test_intltool_merge(COMMANDS[1], INPUT_FILE)
logging.info("Tests execution of Intltool completed!")

19
tests/results/context.xml Normal file
View File

@ -0,0 +1,19 @@
<test>
<entry>
<_name>Foo</_name>
</entry>
<entry>
<!-- This is the comment on the first Bar -->
<_name msgctxt="1">
Bar</_name>
</entry>
<entry>
<!-- This is the comment on the second Bar -->
<_name msgctxt="2">
Bar</_name>
</entry>
<entry>
<!-- This is the comment on Baz -->
<_name>Baz</_name>
</entry>
</test>

View File

@ -0,0 +1,7 @@
char *s = N_("Foo");
/* This is the comment on the first Bar */
char *s = C_("1", "Bar");
/* This is the comment on the second Bar */
char *s = C_("2", "Bar");
/* This is the comment on Baz */
char *s = N_("Baz");

11
tests/tests.yml Normal file
View File

@ -0,0 +1,11 @@
- hosts: localhost
tags:
- classic
roles:
- role: standard-test-basic
required_packages:
- intltool
tests:
- make-check:
dir: .
run: python3 intltool_tests.py