Skip to content

Commit

Permalink
correct improve assertion message and testing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
idevat committed Jan 17, 2018
1 parent b2833cc commit 84b7623
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 11 additions & 3 deletions pcs/test/tools/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,34 +271,42 @@ 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,
real_report_item
)
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,
Expand Down
9 changes: 6 additions & 3 deletions pcs/test/tools/command_env/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions pcs/test/tools/command_env/config_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +33,3 @@ def exists(
return_value=return_value,
)
self.__calls.place(name, call, before, instead)
return self

0 comments on commit 84b7623

Please sign in to comment.