From 84b76231d06f0d698888fb768c73dac01f949d93 Mon Sep 17 00:00:00 2001 From: Ivan Devat Date: Wed, 17 Jan 2018 13:46:25 +0100 Subject: [PATCH] correct improve assertion message and testing tool --- pcs/test/tools/assertions.py | 14 +++++++++++--- pcs/test/tools/command_env/assistant.py | 9 ++++++--- pcs/test/tools/command_env/config_fs.py | 2 -- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pcs/test/tools/assertions.py b/pcs/test/tools/assertions.py index 39fddca72..9bdada5d1 100644 --- a/pcs/test/tools/assertions.py +++ b/pcs/test/tools/assertions.py @@ -271,27 +271,34 @@ def assert_report_item_equal(real_report_item, report_item_info): ) def _unexpected_report_given( + all_expected_report_info_list, expected_report_info_list, real_report_item, real_report_item_list ): return AssertionError( ( "\n Unexpected real report given: \n {0}" - "\n all real reports: \n {2}" - "\n expected reports are: \n {1}" + "\n remaining expected reports are: \n {1}" + "\n all expected reports are: \n {2}" + "\n all real reports: \n {3}" ) .format( _format_report_item(real_report_item), - "\n ".join(map(_format_report_item, real_report_item_list)), "\n ".join(map(repr, expected_report_info_list)) if expected_report_info_list else "No other report is expected!" , + "\n ".join(map(repr, all_expected_report_info_list)) + if all_expected_report_info_list + else "No report is expected!" + , + "\n ".join(map(_format_report_item, real_report_item_list)), ) ) def assert_report_item_list_equal( real_report_item_list, expected_report_info_list, hint="" ): + all_expected_report_info_list = expected_report_info_list[:] for real_report_item in real_report_item_list: found_report_info = __find_report_info( expected_report_info_list, @@ -299,6 +306,7 @@ def assert_report_item_list_equal( ) if found_report_info is None: raise _unexpected_report_given( + all_expected_report_info_list, expected_report_info_list, real_report_item, real_report_item_list, diff --git a/pcs/test/tools/command_env/assistant.py b/pcs/test/tools/command_env/assistant.py index d6b290eaa..b40204a4c 100644 --- a/pcs/test/tools/command_env/assistant.py +++ b/pcs/test/tools/command_env/assistant.py @@ -221,16 +221,19 @@ def get_env(self): ) return self._env - def assert_reports(self, reports): + def assert_reports(self, expected_reports): self.__reports_asserted = True self.__assert_environment_created() self._env.report_processor.assert_reports( - reports + self.__extra_reports + expected_reports + self.__extra_reports ) def assert_raise_library_error( - self, command, reports, expected_in_processor=None + self, command, reports=None, expected_in_processor=None ): + if reports is None: + reports = [] + if not isinstance(reports, list): raise self.__list_of_reports_expected(reports) diff --git a/pcs/test/tools/command_env/config_fs.py b/pcs/test/tools/command_env/config_fs.py index 64e7254ed..49cec4f40 100644 --- a/pcs/test/tools/command_env/config_fs.py +++ b/pcs/test/tools/command_env/config_fs.py @@ -23,7 +23,6 @@ def open( return_value=return_value, ) self.__calls.place(name, call, before, instead) - return self def exists( self, path, return_value="", name="fs.exists", before=None, instead=None @@ -34,4 +33,3 @@ def exists( return_value=return_value, ) self.__calls.place(name, call, before, instead) - return self