Skip to content

Commit

Permalink
refactor: removed unused save_items
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Zhang committed Jan 2, 2025
1 parent 829c907 commit fdde17c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 57 deletions.
5 changes: 0 additions & 5 deletions crawlab/core/item.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import sys
from typing import Iterable

from crawlab.entity.ipc_message import IPCMessage


def save_item(*items: dict):
return save_items(items)


def save_items(items: Iterable[dict]):
msg = IPCMessage(
type="data",
payload=items,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "crawlab-sdk"
version = "0.7.0rc5"
version = "0.7.0rc6"
description = "Python SDK for Crawlab"
authors = ["Marvin Zhang <[email protected]>"]
readme = "README.md"
Expand Down
52 changes: 1 addition & 51 deletions tests/core/test_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from crawlab.core.item import save_item, save_items
from crawlab.core.item import save_item


def test_save_item_single(capsys):
Expand Down Expand Up @@ -33,53 +33,3 @@ def test_save_item_multiple(capsys):
assert isinstance(message["payload"], list)
assert len(message["payload"]) == 2
assert message["payload"] == list(test_items)


def test_save_items(capsys):
test_items = [
{"name": "test1", "value": 123},
{"name": "test2", "value": 456},
{"name": "test3", "value": 789},
]
save_items(test_items)

capsys_res = capsys.readouterr()
message = json.loads(capsys_res.out)

assert message["type"] == "data"
assert message["ipc"] is True
assert isinstance(message["payload"], list)
assert len(message["payload"]) == 3
assert message["payload"] == test_items


def test_save_items_empty(capsys):
save_items([])

capsys_res = capsys.readouterr()
message = json.loads(capsys_res.out)

assert message["type"] == "data"
assert message["ipc"] is True
assert isinstance(message["payload"], list)
assert len(message["payload"]) == 0


def test_save_items_generator(capsys):
def item_generator():
yield {"name": "test1", "value": 123}
yield {"name": "test2", "value": 456}

save_items(item_generator())

capsys_res = capsys.readouterr()
message = json.loads(capsys_res.out)

assert message["type"] == "data"
assert message["ipc"] is True
assert isinstance(message["payload"], list)
assert len(message["payload"]) == 2
assert message["payload"] == [
{"name": "test1", "value": 123},
{"name": "test2", "value": 456},
]

0 comments on commit fdde17c

Please sign in to comment.