Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_cli.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from pathlib import Path | from pathlib import Path | ||||
from tempfile import TemporaryDirectory | from tempfile import TemporaryDirectory | ||||
from typing import Dict | from typing import Dict | ||||
seirl: use `import yaml`, you don't want a "dump" function in the global namespace. | |||||
import yaml | |||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
from swh.graph.cli import cli | from swh.graph.cli import cli | ||||
DATA_DIR = Path(__file__).parents[0] / "dataset" | DATA_DIR = Path(__file__).parents[0] / "dataset" | ||||
Show All 11 Lines | |||||
def test_pipeline(): | def test_pipeline(): | ||||
"""run full compression pipeline""" | """run full compression pipeline""" | ||||
# bare bone configuration, to allow testing the compression pipeline | # bare bone configuration, to allow testing the compression pipeline | ||||
# with minimum RAM requirements on trivial graphs | # with minimum RAM requirements on trivial graphs | ||||
config = {"graph": {"compress": {"batch_size": 1000}}} | config = {"graph": {"compress": {"batch_size": 1000}}} | ||||
runner = CliRunner() | runner = CliRunner() | ||||
with TemporaryDirectory(suffix=".swh-graph-test") as tmpdir: | with TemporaryDirectory(suffix=".swh-graph-test") as tmpdir: | ||||
config_path = Path(tmpdir, "config.yml") | |||||
Done Inline ActionsYou're calling Path() twice :-P seirl: You're calling Path() twice :-P | |||||
config_path.write_text(yaml.dump(config)) | |||||
Done Inline Actionsone liner protip: Path(tmpdir, 'config.yml').write_text(yaml.dumps(config)) seirl: one liner protip: `Path(tmpdir, 'config.yml').write_text(yaml.dumps(config))` | |||||
result = runner.invoke( | result = runner.invoke( | ||||
cli, | cli, | ||||
["compress", "--graph", DATA_DIR / "example", "--outdir", tmpdir], | [ | ||||
obj={"config": config}, | "--config-file", | ||||
config_path, | |||||
"compress", | |||||
"--graph", | |||||
DATA_DIR / "example", | |||||
"--outdir", | |||||
tmpdir, | |||||
], | |||||
) | ) | ||||
assert result.exit_code == 0, result | assert result.exit_code == 0, result | ||||
properties = read_properties(Path(tmpdir) / "example.properties") | properties = read_properties(Path(tmpdir) / "example.properties") | ||||
assert int(properties["nodes"]) == 21 | assert int(properties["nodes"]) == 21 | ||||
assert int(properties["arcs"]) == 23 | assert int(properties["arcs"]) == 23 |
use import yaml, you don't want a "dump" function in the global namespace.