Exemplo n.º 1
0
def test_reducer_precedence():
    "Tests that reducers take precedence over mappers"

    @mr.hook(mr.REDUCE, "foo")
    def red(data):
        return

    @mr.hook(mr.MAP, "foo")
    def m(datum):
        yield "bar", True

    mr.feed("foo", 1)
    assert not list(mr.process())
Exemplo n.º 2
0
def test_simple_filter():
    "Tests that simple filters work"

    @mr.hook(mr.FILTER, "filterable")
    def delete_even(input):
        return input % 2 == 0

    for i in range(500):
        mr.feed("filterable", i)

    results = list(mr.process())
    assert len(results) == 1
    pattern, odds = results[0]
    assert all(x % 2 == 1 for x in odds)
Exemplo n.º 3
0
def test_foobar():
    mr.reset_hooks()
    
    @mr.hook(mr.MAP, "foo")
    def process_foo(query):
        yield "bar", query + 1
    
    @mr.hook(mr.MAP, "bar")
    def process_bar(query):
        yield "abc", query + 1

    mr.feed("foo", 0)
    
    results = list(mr.process())
    assert len(results) == 1
    print results
    assert results[0] == ("abc", [2])
Exemplo n.º 4
0
def test_recursive():
    mr.reset_hooks()

    @mr.hook(mr.MAP, "ill")
    def hospital(input):
        if input == "pregger":
            yield "healthy", "babby"
        elif input == "chicken pox":
            yield "healthy", "itchy"

    @mr.hook(mr.MAP, "healthy")
    def apartment(input):
        if input == "tummy":
            yield "ill", "pregger"
        elif input == "babby":
            yield "ill", "chicken pox"
        elif input == "itchy":
            yield "medicine", "ointment"

    mr.feed("healthy", "tummy")
    assert list(mr.process())[0] == ("medicine", ["ointment"])
Exemplo n.º 5
0
import mr
from mr.forkingrouter import ForkingRouter
mr.set_router(ForkingRouter())

@mr.hook(mr.MAP, "query")
def parse_query(query):
    "Takes an integer and yields a prime number and another query."
    if query % 2 == 0:
        yield "prime", 2
        yield "query", query / 2
        return
    i = 3
    while i < query / 2:
        if query % i == 0:
            yield "prime", i
            yield "query", query / i
            return
        i += 2
    yield "prime", query

mr.feed("query", 124846525121166472890127769845656706959834701767553316679575342375728606681436245953703527478773456698735316531921607496638484885416740029028542605893861455745313937474271661656548230159065196413238268640890)

print list(mr.process())