Skip to content

Commit 891134a

Browse files
feat(matcher): Allow bytes type in from_term function (#281)
* feat(matcher): Allow bytes type for from_term function * feat(matcher): Update documentation
1 parent 588b55d commit 891134a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pact/matchers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ def from_term(term):
184184
Parse the provided term into the JSON for the mock service.
185185
186186
:param term: The term to be parsed.
187-
:type term: None, list, dict, int, float, str, unicode, Matcher
187+
:type term: None, list, dict, int, float, str, bytes, unicode, Matcher
188188
:return: The JSON representation for this term.
189189
:rtype: dict, list, str
190190
"""
191191
if term is None:
192192
return term
193-
elif isinstance(term, (six.string_types, int, float)):
193+
elif isinstance(term, (six.string_types, six.binary_type, int, float)):
194194
return term
195195
elif isinstance(term, dict):
196196
return {k: from_term(v) for k, v in term.items()}

tests/test_matchers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def test_int(self):
135135
def test_float(self):
136136
self.assertEqual(from_term(3.14), 3.14)
137137

138+
def test_bytes(self):
139+
self.assertEqual(from_term(b'testing'), b'testing')
140+
138141
def test_list(self):
139142
term = [1, 123, 'sample']
140143
self.assertEqual(from_term(term), term)

0 commit comments

Comments
 (0)