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
16 changes: 9 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ jobs:
python-version: ['3.12']

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- name: Install uv
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@v10.0.1
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: Install dependencies
run: |
uv sync
run: uv sync

- uses: astral-sh/ruff-action@v3
- name: Check formatting
run: uv run ruff format --check --diff .

- name: Check linting
run: uv run ruff check .

- name: Run tests
run: |
uv run pytest
run: uv run pytest
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ To upgrade Lycophron:
uv tool upgrade lycophron
```

### Initalize a local project
### Initialize a local project

Let's initalize a local project named `monkeys`:
Let's initialize a local project named `monkeys`:

```bash
lycophron init monkeys
Expand Down Expand Up @@ -173,7 +173,7 @@ This command validates the current project. I.e. it checks whether the applicati

**new-template**

This command generates a CSV file from the default template, containing all the required headers. The template can either be generated with all the fields or by explicitely adding custom fields on top of the required ones.
This command generates a CSV file from the default template, containing all the required headers. The template can either be generated with all the fields or by explicitly adding custom fields on top of the required ones.

`new-template --file` : creates the output file in the given path and name.
`new-template --all` : creates a template using all fields (required and custom fields).
Expand Down
2 changes: 1 addition & 1 deletion src/lycophron/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DatabaseNotFound(DatabaseError):


class DatabaseResourceNotModified(DatabaseError):
message = "Datbase resource not modified."
message = "Database resource not modified."


class RecordError(LycophronError):
Expand Down
2 changes: 1 addition & 1 deletion src/lycophron/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def store_references(self, record_id: str, references: list[dict]) -> None:
target_record_id=ref["target_record_id"],
source_field=ref["source_field"],
target_field=ref["target_field"],
bidirectional=str(ref["bidirectional"]),
bidirectional=ref["bidirectional"],
)
self.session.add(reference)

Expand Down
2 changes: 1 addition & 1 deletion src/lycophron/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def init_celery_app():
app.conf.max_memory_per_child = 100000
app.conf.update(imports=["lycophron.tasks.tasks"])
app.conf.beat_schedule = {
"record-dispathcer": {
"record-dispatcher": {
"task": "lycophron.tasks.tasks.record_dispatcher",
"schedule": 5,
"args": (20,),
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import pytest

from lycophron.cli import lycophron


@pytest.fixture(autouse=True)
def reset_singleton():
Expand All @@ -23,3 +25,16 @@ def reset_singleton():

# Restore original instances after test
SingletonMeta._instances = original_instances


def init(runner, token="", project_name=None):
# Skip the token prompt by providing an empty string token by default.
cli_args = ["init", "--token", token]
if project_name:
cli_args.append(project_name)
result = runner.invoke(lycophron, cli_args)

assert result.exit_code == 0
assert "Project initialized in directory" in result.output

return result
40 changes: 16 additions & 24 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"""Test Lycophron CLI commands."""

import csv
import json
import os
import sqlite3
import tempfile
from pathlib import Path

from click.testing import CliRunner
from conftest import init

from lycophron.cli import lycophron

Expand All @@ -21,10 +23,7 @@ def test_init_command_with_name():
runner = CliRunner()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
result = runner.invoke(lycophron, ["init", "testproject"])

assert result.exit_code == 0
assert "Project initialized in directory" in result.output
init(runner, project_name="testproject")

# Verify project structure
project_dir = Path(tmpdir) / "testproject"
Expand All @@ -39,11 +38,7 @@ def test_init_command_default_directory():
runner = CliRunner()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
# Skip the token prompt by providing an empty token
result = runner.invoke(lycophron, ["init", "--token", ""])

assert result.exit_code == 0
assert "Project initialized in directory" in result.output
init(runner)

# Verify project structure
assert (Path(tmpdir) / "files").exists()
Expand All @@ -56,10 +51,7 @@ def test_init_command_with_token():
runner = CliRunner()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
result = runner.invoke(lycophron, ["init", "--token", "test_token123"])

assert result.exit_code == 0
assert "Project initialized in directory" in result.output
init(runner, token="test_token123")

# Verify token in config
config_path = Path(tmpdir) / "lycophron.cfg"
Expand All @@ -77,7 +69,7 @@ def test_new_template_default():
os.chdir(tmpdir)

# Initialize project first
runner.invoke(lycophron, ["init"])
init(runner)

# Generate template
result = runner.invoke(lycophron, ["new-template"])
Expand Down Expand Up @@ -105,7 +97,7 @@ def test_new_template_with_options():
os.chdir(tmpdir)

# Initialize project first
runner.invoke(lycophron, ["init"])
init(runner)

# Generate template with options
custom_path = os.path.join(tmpdir, "custom_template.csv")
Expand Down Expand Up @@ -146,7 +138,7 @@ def test_new_template_minimal():
os.chdir(tmpdir)

# Initialize project first
runner.invoke(lycophron, ["init"])
init(runner)

# Generate minimal template
result = runner.invoke(lycophron, ["new-template", "--minimal"])
Expand Down Expand Up @@ -178,7 +170,7 @@ def test_load_command():
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)

# Create a simple CSV file with required fields
csv_path = os.path.join(tmpdir, "test_data.csv")
Expand Down Expand Up @@ -225,7 +217,7 @@ def test_load_db_objects():
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)

# Create test file
files_dir = Path(tmpdir) / "files"
Expand Down Expand Up @@ -292,7 +284,7 @@ def test_load_db_objects():
assert record["id"] == "record1"

# Verify input_metadata
metadata = eval(record["input_metadata"])
metadata = json.loads(record["input_metadata"])
assert metadata["metadata"]["title"] == "Test Record"
assert metadata["metadata"]["publication_date"] == "2023-01-01"
assert metadata["metadata"]["resource_type"]["id"] == "image"
Expand Down Expand Up @@ -335,7 +327,7 @@ def test_load_multiple_records():
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)

# Create CSV file with multiple records
csv_path = os.path.join(tmpdir, "test_multi.csv")
Expand Down Expand Up @@ -414,13 +406,13 @@ def test_load_multiple_records():
# Verify first record metadata
cursor.execute("SELECT * FROM record WHERE id = ?", ("record1",))
record1 = cursor.fetchone()
metadata1 = eval(record1["input_metadata"])
metadata1 = json.loads(record1["input_metadata"])
assert metadata1["metadata"]["title"] == "First Record"

# Verify second record metadata
cursor.execute("SELECT * FROM record WHERE id = ?", ("record2",))
record2 = cursor.fetchone()
metadata2 = eval(record2["input_metadata"])
metadata2 = json.loads(record2["input_metadata"])
assert metadata2["metadata"]["title"] == "Second Record"
assert metadata2["metadata"]["resource_type"]["id"] == "publication"
assert (
Expand All @@ -438,7 +430,7 @@ def test_load_update_record():
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)

# Create initial CSV file
csv_path = os.path.join(tmpdir, "initial.csv")
Expand Down Expand Up @@ -539,7 +531,7 @@ def test_load_update_record():

cursor.execute("SELECT * FROM record WHERE id = ?", ("record1",))
record = cursor.fetchone()
metadata = eval(record["input_metadata"])
metadata = json.loads(record["input_metadata"])

# Check updated fields
assert metadata["metadata"]["title"] == "Updated Title"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from unittest.mock import MagicMock, patch

from click.testing import CliRunner
from conftest import init

from lycophron.app import LycophronApp
from lycophron.cli import lycophron
from lycophron.models import Record, RecordStatus, Reference
from lycophron.template import LazyReference, TemplateEngine

Expand Down Expand Up @@ -79,7 +79,7 @@ def test_bidirectional_references():
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)

# Create test records with bidirectional references
app = LycophronApp()
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_bidirectional_references():
assert len(specimen_refs) == 1
assert specimen_refs[0].target_record_id == "figure1"
assert specimen_refs[0].target_field == "doi"
assert specimen_refs[0].bidirectional == "True"
assert specimen_refs[0].bidirectional


def test_reference_parsing_without_schema():
Expand Down Expand Up @@ -305,7 +305,7 @@ def test_two_phase_processing(mock_publish, mock_upload, mock_update, mock_creat
os.chdir(tmpdir)

# Initialize project
runner.invoke(lycophron, ["init"])
init(runner)
app = LycophronApp()

# Mock draft creation to set upload_id
Expand Down