Example #1
0
def _find_root_path(path):
    candidates = imap(lambda x: x.join(".farmfs"), path.parents())
    matches = ifilter(lambda x: x.isdir(), candidates)
    root = next(take(1)(matches), None)
    if root:
        nested_root = next(take(1)(matches), None)
        if nested_root:
            raise ValueError("Farmfs volumes cannot be nested")
        return root.parent()
    else:
        raise ValueError("Volume not found: %s" % path)
Example #2
0
def test_pipeline():
    identity_pipeline = pipeline()
    assert isinstance(identity_pipeline([1, 2, 3]),
                      Iterator), "identity_pipeline should be an iterator"
    assert list(identity_pipeline([1, 2, 3])) == [1, 2, 3]

    inc_pipeline = pipeline(fmap(inc))
    assert isinstance(inc_pipeline([1, 2, 3]),
                      Iterator), "inc_pipeline should be an iterator."
    assert list(inc_pipeline([1, 2, 3])) == [2, 3, 4]

    inc_list_pipeline = pipeline(fmap(inc), list)
    assert isinstance(inc_list_pipeline([1, 2, 3]),
                      list), "inc_list_pipeline should return a list"
    assert inc_list_pipeline([1, 2, 3]) == [2, 3, 4]

    range_pipeline = pipeline(irange, even_list, take(3), list)
    assert range_pipeline(0, 1) == [0, 2, 4]
Example #3
0
def test_irange():
    assert list(take(3)(irange(0, 1))) == [0, 1, 2]
    assert list(take(3)(irange(0, -1))) == [0, -1, -2]
Example #4
0
def test_take():
    assert list(take(3)([1, 2, 3, 4, 5])) == [1, 2, 3]
    assert list(take(3)([1, 2])) == [1, 2]