From 612b0afba71dd4368fd9cde0cadbbdaa6e8e22d3 Mon Sep 17 00:00:00 2001 From: Mike FABIAN Date: Thu, 17 Jun 2021 10:02:03 +0200 Subject: [PATCH] Add CI tests --- .fmf/version | 1 + plans/basic.fmf | 5 +++ tests/main.fmf | 5 +++ tests/test_unicode_emoji.py | 70 +++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 .fmf/version create mode 100644 plans/basic.fmf create mode 100644 tests/main.fmf create mode 100644 tests/test_unicode_emoji.py diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/plans/basic.fmf b/plans/basic.fmf new file mode 100644 index 0000000..c1627f9 --- /dev/null +++ b/plans/basic.fmf @@ -0,0 +1,5 @@ +summary: Basic smoke test +discover: + how: fmf +execute: + how: tmt diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..5369092 --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,5 @@ +require: +- python3 +- unicode-emoji +test: python3 test_unicode_emoji.py +framework: shell diff --git a/tests/test_unicode_emoji.py b/tests/test_unicode_emoji.py new file mode 100644 index 0000000..379d856 --- /dev/null +++ b/tests/test_unicode_emoji.py @@ -0,0 +1,70 @@ +from collections import defaultdict +import unittest +import sys + +class TestUnicodeEmoji(unittest.TestCase): + dir_path = "/usr/share/unicode/emoji/" + + def test_dummy(self): + self.assertEqual(True, True) + + @unittest.expectedFailure + def test_expected_failure(self): + self.assertEqual(False, True) + + def test_emoji_data(self): + self.parser(filename=self.dir_path+"emoji-data.txt") + + def test_emoji_sequences(self): + self.parser(filename=self.dir_path+"emoji-sequences.txt") + + def test_emoji_zwj_sequences(self): + self.parser(filename=self.dir_path+"emoji-zwj-sequences.txt") + + def parser(self, filename): + file_content = list() + report = defaultdict(dict) + with open(filename, "r") as fobj: + lines = fobj.readlines() + + count = 0 + curr_head = None + for line in lines: + + def count_group_emoji(line, count): + ''' + This function increments the count with the value inside "[ ]" + ''' + if "[" in line: + return count + int(line.split("[")[1].split("]")[0]) + return count + 1 + + if line.startswith("\n"): + continue + + elif count == 0 and not line.startswith("#"): + curr_head = line.split(";")[0].strip() + count = count_group_emoji(line , count) + report[curr_head]['actual_count'] = count + + elif line.startswith("# Total elements"): + report[curr_head]['expected_count'] = int(line.split(":")[1]) + count = 0 + + elif not line.startswith("#"): + count = count_group_emoji(line ,count) + report[curr_head]['actual_count'] = count + + print(report) + + def validate(report): + ''' + This function will validate if the actual_count equals expected_count + ''' + for key,data in report.items(): + self.assertEqual(data['actual_count'],data['expected_count']) + + validate(report) + +if __name__ == "__main__": + unittest.main()