コード例 #1
0
ファイル: test_stage.py プロジェクト: giacbrd/SmartPipeline
def test_data():
    item = DataItem()
    assert item.id
    item.payload["text"] = "prova"
    item.payload["id"] = "666"
    item.set_metadata("source", "remote")
    item.set_metadata("version", 3)
    assert item.id == "666"
    assert item.get_metadata("source") == "remote"
    assert item.get_metadata("version") == 3
    assert not item.get_metadata("head")
コード例 #2
0
ファイル: test_stage.py プロジェクト: giacbrd/SmartPipeline
def test_source_container():
    manager = Manager()
    data = [DataItem() for _ in range(100)]
    for i, item in enumerate(data):
        item.set_metadata("id", i + 1)
    container = SourceContainer()
    assert not container.is_set()
    source = ListSource(data)
    container.set(source)
    assert not container.is_stopped()
    assert container.is_set()
    item = container.get_processed()
    assert item.get_metadata("id") == 1
    while not isinstance(item, Stop):
        assert not container.is_stopped()
        item = container.get_processed()
    assert container.is_stopped()
    container = SourceContainer()
    source = ListSource(data)
    container.set(source)
    item = DataItem()
    item.set_metadata("id", 1001)
    container.prepend_item(item)
    item = DataItem()
    item.set_metadata("id", 1002)
    container.prepend_item(item)
    assert container.get_processed().get_metadata("id") == 1001
    assert container.get_processed().get_metadata("id") == 1002
    assert container.get_processed().get_metadata("id") == 1
    assert container.get_processed().get_metadata("id") == 2
    item = DataItem()
    item.set_metadata("id", 1003)
    container.prepend_item(item)
    assert container.get_processed().get_metadata("id") == 1003
    assert container.get_processed().get_metadata("id") == 3
    assert not container.is_stopped()
    container.init_queue(manager.Queue)
    queue = container.out_queue
    item = DataItem()
    item.set_metadata("id", 1004)
    queue.put(item)
    assert container.get_processed().get_metadata("id") == 1004
    container.pop_into_queue()
    assert container.get_processed().get_metadata("id") == 4