Skip to content

Commit

Permalink
Implement temporary workaround for Python 2/3 kwarg ordering differen…
Browse files Browse the repository at this point in the history
…ces.
  • Loading branch information
Fizzadar committed Oct 30, 2021
1 parent 76267b8 commit bdf9552
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def _delete(self, key, args=None):
self.facts[key].pop(args[0], None)


# TODO: remove after python2 removal, as only required because of different default ordering in 2/3
def _sort_kwargs_str(string):
return ', '.join(sorted(string.split(', ')))


class FakeHost(object):
noop_description = None

Expand All @@ -170,10 +175,14 @@ def get_fact(self, fact_cls, **kwargs):
if fact is None:
raise KeyError('Missing test fact data: {0}'.format(fact_key))
if kwargs:
kwargs_str = get_kwargs_str(kwargs)
fact_ordered_keys = {
_sort_kwargs_str(key): value
for key, value in fact.items()
}
kwargs_str = _sort_kwargs_str(get_kwargs_str(kwargs))
if kwargs_str not in fact:
logger.info('Possible missing fact key: {0}'.format(kwargs_str))
return fact.get(kwargs_str)
return fact_ordered_keys.get(kwargs_str)
return fact

def create_fact(self, fact_cls, data, kwargs):
Expand Down

0 comments on commit bdf9552

Please sign in to comment.