From 891134a33e4b3e03f7e4c3f91c4f7cb0234f3c56 Mon Sep 17 00:00:00 2001 From: joshua-badger <67024357+joshua-badger@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:23:40 -0700 Subject: [PATCH] feat(matcher): Allow bytes type in from_term function (#281) * feat(matcher): Allow bytes type for from_term function * feat(matcher): Update documentation --- pact/matchers.py | 4 ++-- tests/test_matchers.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pact/matchers.py b/pact/matchers.py index 55424fdd2..52a414804 100644 --- a/pact/matchers.py +++ b/pact/matchers.py @@ -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()} diff --git a/tests/test_matchers.py b/tests/test_matchers.py index 70fee2e18..1cc446f3b 100644 --- a/tests/test_matchers.py +++ b/tests/test_matchers.py @@ -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)