Exemple #1
0
def suite_iter(suite):
    """suite_iter(suite) -> an iterator on its direct sub-suites.
    For compatibility with Python versions before 2.4"""

    def add_extra_description_field(test):
        test._testoob_extra_description = ""
        return True

    try:
        return _ifilter(add_extra_description_field, iter(suite))
    except TypeError:
        # Before 2.4, test suites weren't iterable
        return _ifilter(add_extra_description_field, iter(suite._tests))
Exemple #2
0
def full_extractor(suite, recursive_iterator=_breadth_first):
    """Extract the text fixtures from a suite.
    Descends recursively into sub-suites."""
    import unittest
    def test_children(node):
        if isinstance(node, unittest.TestSuite): return suite_iter(node)
        return []

    return _ifilter(lambda test: isinstance(test, unittest.TestCase),
                    recursive_iterator(suite, children=test_children))
Exemple #3
0
    def __and__(self, other):
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in _ifilter(self.__contains__, other):
            p, q = self[elem], other[elem]
            newcount = p if p < q else q
            if newcount > 0:
                result[elem] = newcount

        return result
Exemple #4
0
def itruthy(iterable):
    """Returns an iterator to for an iterable with only the truthy values.

  Example::

      tuple(itruthy((0, 1, 2, False, None, True))) -> (1, 2, True)

  :param iterable:
      Iterable sequence.
  :yields:
      Iterator for an iterable with truthy values.
  """
    return _ifilter(bool, iterable)
    def __and__(self, other):
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in _ifilter(self.__contains__, other):
            p, q = self[elem], other[elem]
            newcount = p if p < q else q
            if newcount > 0:
                result[elem] = newcount

        return result
Exemple #6
0
def iselect(predicate, iterable):
    """Select all items from the sequence for which the predicate is true.

      iselect(function or None, sequence) --> iterator

  :param predicate:
      Predicate function. If ``None``, select all truthy items.
  :param iterable:
      Iterable.
  :yields:
      A iterable of all items for which the predicate is true.
  """
    return _ifilter(predicate, iterable)
Exemple #7
0
def iselect(predicate, iterable):
  """Select all items from the sequence for which the predicate is true.

      iselect(function or None, sequence) --> iterator

  :param predicate:
      Predicate function. If ``None``, select all truthy items.
  :param iterable:
      Iterable.
  :yields:
      A iterable of all items for which the predicate is true.
  """
  return _ifilter(predicate, iterable)
Exemple #8
0
def itruthy(iterable):
  """Returns an iterator to for an iterable with only the truthy values.

  Example::

      tuple(itruthy((0, 1, 2, False, None, True))) -> (1, 2, True)

  :param iterable:
      Iterable sequence.
  :yields:
      Iterator for an iterable with truthy values.
  """
  return _ifilter(bool, iterable)
def select_dict(predicate, dictionary):
    """
    Select a dictionary.

    :param predicate:
        Predicate function that accepts two arguments ``key, value``
        and returns ``True`` for selectable elements.
    :returns:
        New dictionary of selected ``key=value`` pairs.
    """
    def _pred(tup):
        return predicate(*tup)
    _predicate = _pred if predicate else all
    return dict(_ifilter(_predicate, dictionary.items()))
Exemple #10
0
def idifference(iterable1, iterable2):
    """Difference between one iterable and another.
  Items from the first iterable are included in the difference.

      iterable1 - iterable2 = difference

  :param iterable1:
      Iterable sequence.
  :param iterable2:
      Iterable sequence.
  :yields:
      Generator for the difference between the two given iterables.
  """
    return _ifilter(functools.partial(omits, iterable2), iterable1)
Exemple #11
0
def idifference(iterable1, iterable2):
  """Difference between one iterable and another.
  Items from the first iterable are included in the difference.

      iterable1 - iterable2 = difference

  :param iterable1:
      Iterable sequence.
  :param iterable2:
      Iterable sequence.
  :yields:
      Generator for the difference between the two given iterables.
  """
  return _ifilter(functools.partial(omits, iterable2), iterable1)
Exemple #12
0
def select_dict(predicate, dictionary):
    """Select from a dictionary.

  :param predicate:
      Predicate function that accepts two arguments ``key, value``
      and returns ``True`` for selectable elements.
  :returns:
      New dictionary of selected ``key=value`` pairs.
  """
    def _pred(tup):
        """Apply arguments to predicate."""
        return predicate(*tup)

    _predicate = _pred if predicate else all
    return dict(_ifilter(_predicate, dictionary.items()))
Exemple #13
0
    def __and__(self, other):
        """ Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        """
        if not isinstance(other, Counter):
            return NotImplemented
        _min = min
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in _ifilter(self.__contains__, other):
            newcount = _min(self[elem], other[elem])
            if newcount > 0:
                result[elem] = newcount
        return result
Exemple #14
0
    def __and__(self, other):
        ''' Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in _ifilter(self.__contains__, other):
            p, q = self[elem], other[elem]
            newcount = p if p < q else q
            if newcount > 0:
                result[elem] = newcount
        return result
Exemple #15
0
    def __and__(self, other):
        ''' Intersection is the minimum of corresponding counts.

        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})

        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        if len(self) < len(other):
            self, other = other, self
        for elem in _ifilter(self.__contains__, other):
            p, q = self[elem], other[elem]
            newcount = p if p < q else q
            if newcount > 0:
                result[elem] = newcount
        return result
Exemple #16
0
def predicate(pred):
    return _iterable_decorator(lambda iterable: _ifilter(pred, iterable))
Exemple #17
0
 def suite():
     result = unittest.TestSuite()
     for test_case in _ifilter(_is_test_case, globals_dict.values()):
         result.addTest(unittest.makeSuite(test_case))
     return result
Exemple #18
0
 def suite():
     result = unittest.TestSuite()
     for test_case in _ifilter(_is_test_case, globals_dict.values()):
         result.addTest(unittest.makeSuite(test_case))
     return result