コード例 #1
0
ファイル: test_factory.py プロジェクト: maet3608/nuts-flow
def test_nut_processor():
    @nut_processor
    def CloneN(iterable, n):
        for e in iterable:
            for _ in range(n):
                yield e

    assert [1, 2] >> CloneN(2) >> Collect() == [1, 1, 2, 2]
コード例 #2
0
    def _cache_fpaths(self):
        """
        Return sorted list of filepaths of cached objects, honoring pick param.

        :return: Filepaths to pickle files.
        :rtype: list of strings
        """
        path = self._cachepath if self._cachepath else self.path
        fpaths = sorted(osp.join(path, n) for n in os.listdir(path))
        return fpaths >> Pick(self.pick) >> Collect()
コード例 #3
0
def test_nut_filterfalse():
    @nut_filterfalse
    def NotGreaterThan(x, threshold):
        return x > threshold

    assert [1, 2, 3, 4] >> NotGreaterThan(2) >> Collect() == [1, 2]
コード例 #4
0
def test_nut_filter():
    @nut_filter
    def GreaterThan(x, threshold):
        return x > threshold

    assert [1, 2, 3, 4] >> GreaterThan(2) >> Collect() == [3, 4]
コード例 #5
0
def test_nut_source():
    @nut_source
    def MyRange(start, end):
        return iter(xrange(start, end))

    assert MyRange(1, 4) >> Collect() == [1, 2, 3]
コード例 #6
0
def test_nut_function():
    @nut_function
    def TimesN(x, n):
        return x * n

    assert [1, 2] >> TimesN(2) >> Collect() == [2, 4]
コード例 #7
0
def test_create_nut_wrapper():
    func = lambda iterable, arg1, arg2: (iterable, arg1, arg2)
    wrapper = _create_nut_wrapper(Nut, func, 0)
    assert isinstance(wrapper(), Nut)
    assert ['a'] >> wrapper(2, 3) >> Collect() == [['a'], 2, 3]