Skip to content

Commit

Permalink
contain now supports dicts and arrays. Partially fix #59
Browse files Browse the repository at this point in the history
  • Loading branch information
sgissinger committed Nov 18, 2020
1 parent e686434 commit 074d0fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions grappa/operators/contain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from array import array
from six.moves import collections_abc
import six

from ..operator import Operator


Expand Down Expand Up @@ -59,21 +61,21 @@ class ContainOperator(Operator):
NORMALIZE_TYPES = (
collections_abc.Iterator,
collections_abc.MappingView,
collections_abc.Set
collections_abc.Set,
array
)

def match(self, subject, *expected):
if isinstance(subject, self.NORMALIZE_TYPES):
subject = list(subject)
elif isinstance(subject, collections_abc.Mapping):
subject = list(subject.values())

if self._is_not_a_sequence(subject):
if not isinstance(subject, collections_abc.Sequence):
return False, ['is not a valid sequence type']

return self._matches(subject, *expected)

def _is_not_a_sequence(self, value):
return not isinstance(value, collections_abc.Sequence)

def _matches(self, subject, *expected):
reasons = []

Expand Down

0 comments on commit 074d0fe

Please sign in to comment.