Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/coordo-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ jobs:

- name: Run tests
run: uv run test.py

- name: Run pytest
run: uv run pytest
5 changes: 5 additions & 0 deletions coordo-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ coordo = "coordo.cli:app"
[tool.setuptools.package-data]
"coordo" = ["static/*", "**/*.sql"]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = ["-s"]

[dependency-groups]
dev = [
"ruff>=0.15.8",
"pytest>=8.0",
]
2 changes: 2 additions & 0 deletions coordo-py/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright COORDONNÉES 2025, 2026
# SPDX-License-Identifier: MPL-2.0
24 changes: 24 additions & 0 deletions coordo-py/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright COORDONNÉES 2025, 2026
# SPDX-License-Identifier: MPL-2.0

import pytest
from pathlib import Path

DATA_DIR = Path("tests/test_data")
INVENTORY_DIR = DATA_DIR / "inventory"

@pytest.fixture
def inventory_package():
return "catalog/inventory"

@pytest.fixture
def inventory_inquiry():
return INVENTORY_DIR / "inquiry.xlsx"

@pytest.fixture
def inventory_data():
return INVENTORY_DIR / "data.xlsx"

@pytest.fixture
def inventory_file():
return INVENTORY_DIR / "file.csv"
33 changes: 33 additions & 0 deletions coordo-py/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright COORDONNÉES 2025, 2026
# SPDX-License-Identifier: MPL-2.0

import shutil
from typer.testing import CliRunner
from coordo.cli import app

runner = CliRunner()

def get_output_and_check_exitcode(result):
print(result.stdout_bytes.decode())
assert result.exit_code == 0

def test_add_data_to_package(inventory_package, inventory_inquiry, inventory_data, inventory_file):
"""
Test the following workflow:
- Load data from a kobotoolbox inquiry and a file into a package.
- Add a foreign key between two fields.
- Remove the foreign key.
- Add the foreign key again.
"""
result = runner.invoke(app, ["load", "kobotoolbox", str(inventory_inquiry), str(inventory_data), "--package", inventory_package, "--action", "add"])
get_output_and_check_exitcode(result)
result = runner.invoke(app, ["load", "file", str(inventory_file), "--package", inventory_package, "--action", "add"])
get_output_and_check_exitcode(result)
result = runner.invoke(app, ["add-foreignkey", "ind.ess_arb", "file.ess_arb", "--package", inventory_package])
get_output_and_check_exitcode(result)
result = runner.invoke(app, ["remove-foreignkey", "ind.ess_arb", "file.ess_arb", "--package", inventory_package])
get_output_and_check_exitcode(result)
result = runner.invoke(app, ["add-foreignkey", "ind.ess_arb", "file.ess_arb", "--package", inventory_package])
get_output_and_check_exitcode(result)
print(f"Removing package '{inventory_package}'")
shutil.rmtree(inventory_package)
Binary file added coordo-py/tests/test_data/inventory/data.xlsx
Binary file not shown.
37 changes: 37 additions & 0 deletions coordo-py/tests/test_data/inventory/file.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ess_arb,value
1,0.422
2,0.694
4,0.607
5,0.607
7,0.56
8,0.738
9,0.723
10,0.56
16,0.642
25,0.8
33,0.636
35,0.627
37,0.56
39,0.886
58,0.56
67,0.56
70,0.682
72,0.736
77,0.56
93,0.854
96,0.8
105,0.681
111,0.671
127,0.55
133,0.681
145,0.465
166,0.56
173,0.56
187,0.56
194,0.641
195,0.664
198,0.56
213,0.49
243,0.56
248,0.646
251,0.56
Binary file added coordo-py/tests/test_data/inventory/inquiry.xlsx
Binary file not shown.
40 changes: 39 additions & 1 deletion coordo-py/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading