Skip to content

Commit

Permalink
💥 load_proxy -> make_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Aug 7, 2023
1 parent 6bf8851 commit 36fe728
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ftmq/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
log = logging.getLogger(__name__)


def load_proxy(data: dict[str, Any], dataset: str | None = None) -> CE:
def make_proxy(data: dict[str, Any], dataset: str | None = None) -> CE:
datasets = ensure_list(data.pop("datasets", None))
if dataset is not None:
datasets.append(dataset)
Expand Down Expand Up @@ -89,7 +89,7 @@ def smart_read_proxies(
break
data = orjson.loads(line)
if serialize:
data = load_proxy(data)
data = make_proxy(data)
yield data


Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from nomenklatura.entity import CompositeEntity

from ftmq.cli import cli
from ftmq.io import load_proxy
from ftmq.io import make_proxy

runner = CliRunner()

Expand All @@ -24,7 +24,7 @@ def test_cli(fixtures_path: Path):
assert result.exit_code == 0
lines = _get_lines(result.output)
assert len(lines) == 151
proxy = load_proxy(orjson.loads(lines[0]))
proxy = make_proxy(orjson.loads(lines[0]))
assert isinstance(proxy, CompositeEntity)

result = runner.invoke(cli, ["-i", in_uri, "-d", "other_dataset"])
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_cli_apply(fixtures_path: Path):
assert result.exit_code == 0
lines = _get_lines(result.output)
assert len(lines) == 151
proxy = load_proxy(orjson.loads(lines[0]))
proxy = make_proxy(orjson.loads(lines[0]))
assert isinstance(proxy, CompositeEntity)
assert "another_dataset" in proxy.datasets
assert "eu_authorities" in proxy.datasets
Expand All @@ -78,7 +78,7 @@ def test_cli_apply(fixtures_path: Path):
assert result.exit_code == 0
lines = _get_lines(result.output)
assert len(lines) == 151
proxy = load_proxy(orjson.loads(lines[0]))
proxy = make_proxy(orjson.loads(lines[0]))
assert isinstance(proxy, CompositeEntity)
assert "another_dataset" in proxy.datasets
assert "eu_authorities" not in proxy.datasets
Expand Down Expand Up @@ -114,5 +114,5 @@ def test_cli_io(fixtures_path: Path):
assert result.exit_code == 0
lines = _get_lines(result.output)
assert len(lines) == 151
proxy = load_proxy(orjson.loads(lines[0]))
proxy = make_proxy(orjson.loads(lines[0]))
assert isinstance(proxy, CompositeEntity)
7 changes: 3 additions & 4 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

from ftmq.io import (
apply_datasets,
load_proxy,
make_proxy,
smart_read,
smart_read_proxies,
smart_write,
smart_write_proxies,
)

from .conftest import setup_s3
from tests.conftest import setup_s3


def test_io_read(fixtures_path: Path):
Expand Down Expand Up @@ -49,7 +48,7 @@ def test_io_write_stdout(capsys, proxies: list[CE]):
captured = capsys.readouterr()
proxy = None
for line in captured.out.split("\n"):
proxy = load_proxy(orjson.loads(line))
proxy = make_proxy(orjson.loads(line))
break
assert isinstance(proxy, CompositeEntity)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from followthemoney import model

from ftmq.exceptions import ValidationError
from ftmq.io import load_proxy
from ftmq.io import make_proxy
from ftmq.query import Query


def test_proxy_composite():
data = {"id": "1", "schema": "Thing", "properties": {"name": "Test"}}
proxy = load_proxy(data)
proxy = make_proxy(data)
assert proxy.id == "1"
assert proxy.get("name") == ["Test"]
assert proxy.datasets == {"default"}
Expand All @@ -19,7 +19,7 @@ def test_proxy_composite():
"properties": {"name": "Test"},
"datasets": ["test_dataset"],
}
proxy = load_proxy(data)
proxy = make_proxy(data)
assert proxy.id == "1"
assert proxy.get("name") == ["Test"]
assert proxy.datasets == {"test_dataset"}
Expand All @@ -30,7 +30,7 @@ def test_proxy_composite():
"properties": {"name": "Test"},
"datasets": ["test_dataset", "ds2"],
}
proxy = load_proxy(data, "another_dataset")
proxy = make_proxy(data, "another_dataset")
assert proxy.id == "1"
assert proxy.get("name") == ["Test"]
assert proxy.datasets == {"another_dataset", "ds2", "test_dataset"}
Expand Down

0 comments on commit 36fe728

Please sign in to comment.