Skip to content

Commit bb1307d

Browse files
committed
Add tests
1 parent b58ba8c commit bb1307d

File tree

7 files changed

+211
-38
lines changed

7 files changed

+211
-38
lines changed

poetry.lock

Lines changed: 138 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ build-backend = "poetry.core.masonry.api"
2424
[tool.poetry.group.dev.dependencies]
2525
fastapi = {extras = ["standard"], version = "^0.115.8"}
2626
ruff = "^0.9.6"
27+
simpsons-rdf = "^0.3.0"
28+
httpx = "^0.28.1"
29+
pytest = "^8.4.2"
2730

2831
[project.scripts]
2932
sparql-file = "sparql_file.cli:app"

tests/__init__.py

Whitespace-only changes.

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from sparql_file import sparql_file
2+
from .utils import copy_file
3+
from simpsons_rdf import simpsons
4+
5+
6+
def test_api_with_turtle_graph(tmp_path):
7+
p = tmp_path / "graph_file.ttl"
8+
copy_file(simpsons.graph_file, p)
9+
sparql_file(p)
10+
11+
12+
def test_api_with_turtle_graph_specify_format(tmp_path):
13+
p = tmp_path / "graph_file.ttl"
14+
copy_file(simpsons.graph_file, p)
15+
sparql_file(p, graph_format="turtle")

tests/test_cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from sparql_file.cli import app
2+
from .utils import copy_file
3+
from simpsons_rdf import simpsons
4+
import pytest
5+
6+
from typer.testing import CliRunner
7+
8+
runner = CliRunner()
9+
10+
11+
@pytest.mark.skip(reason="I don't know how to send send sig term in this case")
12+
def test_cli_with_turtle_graph(tmp_path):
13+
p = tmp_path / "graph_file.ttl"
14+
copy_file(simpsons.graph_file, p)
15+
16+
result = runner.invoke(app, [f"{p}"])
17+
assert result.exit_code == 0
18+
19+
20+
@pytest.mark.skip(reason="I don't know how to send send sig term in this case")
21+
def test_cli_with_turtle_graph_specify_format(tmp_path):
22+
p = tmp_path / "graph_file.ttl"
23+
copy_file(simpsons.graph_file, p)
24+
25+
result = runner.invoke(app, [f"{p}", "--graph-format", "turtle"])
26+
assert result.exit_code == 0

tests/test_env.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .utils import copy_file
2+
from simpsons_rdf import simpsons
3+
import os
4+
5+
from fastapi.testclient import TestClient
6+
7+
8+
def test_endpoint_with_turtle_graph(tmp_path):
9+
p = tmp_path / "graph_file.ttl"
10+
copy_file(simpsons.graph_file, p)
11+
os.environ["GRAPH_FILE"] = str(p)
12+
13+
from sparql_file.env import app
14+
15+
client = TestClient(app)
16+
17+
response = client.post(
18+
"/",
19+
data="select ?s ?p ?o {?s ?p ?o} limit 1",
20+
headers={"Content-Type": "application/sparql-query"},
21+
)
22+
assert response.status_code == 200

tests/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def copy_file(src, target):
2+
target.parent.mkdir(parents=True, exist_ok=True)
3+
with (
4+
open(src, "r") as input,
5+
open(target, "w") as output,
6+
):
7+
output.write(input.read())

0 commit comments

Comments
 (0)