Skip to content

Commit

Permalink
feat(matcher): Allow bytes type in from_term function (#281)
Browse files Browse the repository at this point in the history
* feat(matcher): Allow bytes type for from_term function

* feat(matcher): Update documentation
  • Loading branch information
joshua-badger committed Jan 3, 2022
1 parent 588b55d commit 891134a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pact/matchers.py
Expand Up @@ -184,13 +184,13 @@ def from_term(term):
Parse the provided term into the JSON for the mock service.
:param term: The term to be parsed.
:type term: None, list, dict, int, float, str, unicode, Matcher
:type term: None, list, dict, int, float, str, bytes, unicode, Matcher
:return: The JSON representation for this term.
:rtype: dict, list, str
"""
if term is None:
return term
elif isinstance(term, (six.string_types, int, float)):
elif isinstance(term, (six.string_types, six.binary_type, int, float)):
return term
elif isinstance(term, dict):
return {k: from_term(v) for k, v in term.items()}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_matchers.py
Expand Up @@ -135,6 +135,9 @@ def test_int(self):
def test_float(self):
self.assertEqual(from_term(3.14), 3.14)

def test_bytes(self):
self.assertEqual(from_term(b'testing'), b'testing')

def test_list(self):
term = [1, 123, 'sample']
self.assertEqual(from_term(term), term)
Expand Down

0 comments on commit 891134a

Please sign in to comment.