From b684bff04be3cdfd66f14c11877478ec3e437ba0 Mon Sep 17 00:00:00 2001 From: Mike FABIAN Date: Mon, 11 Nov 2024 18:54:10 +0100 Subject: [PATCH] Resolves: RHELMISC-5984 require ibus-typing-booster instead of emoji-picker, rewrite test to better show when something goes wrong --- tests/main.fmf | 2 +- tests/test_appstream.py | 60 +++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/tests/main.fmf b/tests/main.fmf index dce9b1e..8605a7a 100644 --- a/tests/main.fmf +++ b/tests/main.fmf @@ -1,5 +1,5 @@ require: - appstream -- emoji-picker +- ibus-typing-booster test: python3 test_appstream.py -v framework: shell diff --git a/tests/test_appstream.py b/tests/test_appstream.py index 6642809..76d9b50 100644 --- a/tests/test_appstream.py +++ b/tests/test_appstream.py @@ -13,34 +13,54 @@ class TestAppstream(unittest.TestCase): def test_appstreamcli_search(self): cp = subprocess.run( - ['env LC_ALL=en_US.UTF-8 appstreamcli search emoji-picker'], + ['env LC_ALL=en_US.UTF-8 appstreamcli search ibus-typing-booster'], encoding='UTF-8', text=True, shell=True, capture_output=True) + print('----------------------------------------') + print(cp.stdout) + print('----------------------------------------') output_lines = cp.stdout.split('\n') + result_dict = {} + identifier = '' + for line in output_lines: + if line == '---' or ':' not in line: + continue + key, value = map(str.strip, line.split(':', maxsplit=1)) + if key == 'Identifier': + identifier = value + result_dict[identifier] = {} + result_dict[identifier][key] = value print('----------------------------------------') - print(output_lines) + print(result_dict) print('----------------------------------------') + typing_booster_identifier = ( + 'org.freedesktop.ibus.engine.typing_booster [inputmethod]') + print(f'Assert that {typing_booster_identifier} in {result_dict.keys()}') self.assertTrue( - 'Identifier: org.freedesktop.ibus.engine.typing_booster.emoji_picker [desktop-application]' - in output_lines) - self.assertTrue( - 'Name: Emoji Picker' - in output_lines) - self.assertTrue( - 'Summary: Emoji browsing tool' - in output_lines) - self.assertTrue( - 'Homepage: https://mike-fabian.github.io/ibus-typing-booster/' - in output_lines) - self.assertTrue( - 'Icon: org.freedesktop.ibus.engine.typing_booster.emoji_picker.png' - in output_lines) - # This section not always there, better don’t test for this: - # self.assertTrue( - # 'Package: emoji-picker' - # in output_lines) + typing_booster_identifier + in result_dict.keys()) + expected_dict = { + typing_booster_identifier: { + 'Identifier': typing_booster_identifier, + 'Name': 'Typing Booster', + 'Summary': 'Predictive input method', + # The 'Package' section seems to be not always there, + # better do not test for this: + # 'Package': 'ibus-typing-booster', + 'Homepage': 'https://mike-fabian.github.io/ibus-typing-booster/', + 'Icon': 'org.freedesktop.ibus.engine.typing_booster.png', + } + } + for result_key, result_value in result_dict.items(): + if result_key == typing_booster_identifier: + for expected_key, expected_value in ( + expected_dict[typing_booster_identifier].items()): + print(f'Assert that {expected_key} is {expected_value}:') + self.assertEqual( + result_dict[result_key][expected_key], + expected_value) if __name__ == "__main__": unittest.main()