Skip to content

Commit

Permalink
Merge 41e045a into 8553b34
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapaioa committed Nov 19, 2019
2 parents 8553b34 + 41e045a commit 487942e
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/widgetastic_patternfly/__init__.py
Expand Up @@ -275,24 +275,29 @@ def dismiss(self):

def match_messages(self, text=None, t=None, partial=False, inverse=False):
msg_type = t if isinstance(t, (tuple, list, set, type(None))) else (t, )
# below is a little bit tricky statement
# if inverse is True, further comparison statements will be treated as is
# and inverted by not_ otherwise
# If inverse is True, further comparison statements will be treated as is.
# Otherwise, they will be inverted by not_().
op = bool if inverse else not_
log_part = 'partial' if partial else 'exact'
if t is not None:
self.logger.info('%s match of the flash message %r of type %r', log_part, text, t)
log_inverse = "inverse " if inverse else ""
log_type = f", type: {t!r}" if msg_type else ""
if isinstance(text, Pattern):
log_part = "pattern"
log_text = f", pattern: {text.pattern!r}"
else:
self.logger.info('%s match of the flash message %r', log_part, text)
log_part = "partial" if partial else "exact"
log_text = f", text: {text!r}" if text else ""
self.logger.info(f"Performing {log_inverse}{log_part} match of flash message"
f"{log_text}{log_type}")

matched_messages = []
for message in self.messages:
if msg_type and op(message.type in msg_type):
continue

if text and op((partial and text in message.text) or
(not partial and text == message.text)):
if isinstance(text, Pattern) and op(text.match(message.text)):
continue
if isinstance(text, str) and op((partial and text in message.text) or
(not partial and text == message.text)):
continue

matched_messages.append(message)
return matched_messages

Expand All @@ -309,7 +314,13 @@ def assert_no_error(self, wait=0):
return True

def assert_message(self, text, t=None, partial=False, wait=0):
log_part = 'partial' if partial else 'exact'
# If text is a compiled regex instead of a string, log it as a pattern match.
if isinstance(text, Pattern):
log_part = 'pattern'
log_text = text.pattern
else:
log_part = 'partial' if partial else 'exact'
log_text = text
try:
msgs = wait_for(self.match_messages, func_kwargs=dict(text=text, t=t, partial=partial),
timeout=wait)[0]
Expand All @@ -319,11 +330,12 @@ def assert_message(self, text, t=None, partial=False, wait=0):
raise TimedOutError
except TimedOutError:
if t is not None:
e_text = '{}: {}'.format(t, text)
e_text = f"{t}: {log_text}"
else:
e_text = text
raise AssertionError('assert {} match of message: {}. \n Available messages: {}'
.format(log_part, e_text, [msg.text for msg in self.messages]))
e_text = log_text
msg_text = [msg.text for msg in self.messages]
raise AssertionError(f"assert {log_part} match of message: {e_text}.\n"
f"Available messages: {msg_text}")

def assert_success_message(self, text, t=None, partial=False, wait=0):
self.assert_no_error(wait=wait)
Expand Down Expand Up @@ -1284,7 +1296,7 @@ def get_item_by_nodeid(self, nodeid):
except NoSuchElementException:
raise CandidateNotFound({
'message':
'Could not find the item with nodeid {} in Boostrap tree {}'.format(
'Could not find the item with nodeid {} in Bootstrap tree {}'.format(
nodeid,
self.tree_id),
'path': '',
Expand Down Expand Up @@ -1430,7 +1442,7 @@ def expand_path(self, *path, **kwargs):
if not self.validate_node(node, step, image):
raise CandidateNotFound({
'message':
'Could not find the item {} in Boostrap tree {}'.format(
'Could not find the item {} in Bootstrap tree {}'.format(
self.pretty_path(steps_tried),
self.tree_id),
'path': path,
Expand All @@ -1444,7 +1456,7 @@ def expand_path(self, *path, **kwargs):
if node is not None and not self.expand_node(self.get_nodeid(node)):
raise CandidateNotFound({
'message':
'Could not find the item {} in Boostrap tree {}'.format(
'Could not find the item {} in Bootstrap tree {}'.format(
self.pretty_path(steps_tried),
self.tree_id),
'path': path,
Expand All @@ -1462,7 +1474,7 @@ def expand_path(self, *path, **kwargs):
else:
raise CandidateNotFound({
'message':
'Could not find the item {} in Boostrap tree {}'.format(
'Could not find the item {} in Bootstrap tree {}'.format(
self.pretty_path(steps_tried),
self.tree_id),
'path': path,
Expand Down

0 comments on commit 487942e

Please sign in to comment.