def test_composite_transform_unsupported():
    from datapipelines import UnsupportedError
    transformer = CompositeDataTransformer(
        {IntFloatTransformer(), FloatIntTransformer()})

    value = 0
    with pytest.raises(UnsupportedError):
        transformer.transform(str, value)
def test_composite_transform():
    transformer = CompositeDataTransformer(
        {IntFloatTransformer(), FloatIntTransformer()})

    value = 0
    assert type(transformer.transform(float, value)) is float

    value = 0.0
    assert type(transformer.transform(int, value)) is int
示例#3
0
def create_default_pipeline(api_key, verbose=False):
    from datapipelines import DataPipeline, CompositeDataTransformer
    from ..datastores.cache import Cache
    from ..datastores.riotapi import RiotAPI
    from ..datastores.ddragon import DDragonDataSource
    from ..transformers.staticdata import StaticDataTransformer
    from ..transformers.champion import ChampionTransformer
    from ..transformers.championmastery import ChampionMasteryTransformer
    from ..transformers.summoner import SummonerTransformer
    from ..transformers.match import MatchTransformer
    from ..transformers.masteries import MasteriesTransformer
    from ..transformers.runes import RunesTransformer
    from ..transformers.spectator import SpectatorTransformer
    from ..transformers.status import StatusTransformer
    from ..transformers.leagues import LeagueTransformer

    services = [
        Cache(),  # TODO Add expirations from file
        DDragonDataSource(),  # TODO: Should this be default?
        RiotAPI(api_key=api_key)
    ]
    riotapi_transformer = CompositeDataTransformer([
        StaticDataTransformer(),
        ChampionTransformer(),
        ChampionMasteryTransformer(),
        SummonerTransformer(),
        MatchTransformer(),
        MasteriesTransformer(),
        RunesTransformer(),
        SpectatorTransformer(),
        StatusTransformer(),
        LeagueTransformer()
    ])
    pipeline = DataPipeline(services, [riotapi_transformer])
    pipeline._transformer = riotapi_transformer

    # Manually put the cache on the pipeline. TODO Is this the best way?
    for datastore in services:
        if isinstance(datastore, Cache):
            pipeline._cache = datastore
            break
    else:
        pipeline._cache = None

    if verbose:
        for service in services:
            for p in service.provides:
                print("Provides:", p)
        for transformer in riotapi_transformer:
            for t in transformer.transforms.items():
                print("Transformer:", t)
        print()

    return pipeline
示例#4
0
from datapipelines import CompositeDataTransformer

from .staticdata import StaticDataTransformer
from .champion import ChampionTransformer
from .championmastery import ChampionMasteryTransformer
from .summoner import SummonerTransformer
from .match import MatchTransformer
from .spectator import SpectatorTransformer
from .status import StatusTransformer
from .leagues import LeagueTransformer

riotapi_transformer = CompositeDataTransformer([
    StaticDataTransformer(),
    ChampionTransformer(),
    ChampionMasteryTransformer(),
    SummonerTransformer(),
    MatchTransformer(),
    SpectatorTransformer(),
    StatusTransformer(),
    LeagueTransformer()
])

__transformers__ = [riotapi_transformer]
def test_composite_transforms():
    transformer = CompositeDataTransformer(
        {IntFloatTransformer(), FloatIntTransformer()})
    assert transformer.transforms == {int: {float}, float: {int}}