Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45314: add workflow for pytest #30

Merged
merged 15 commits into from
Jul 24, 2024
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
41 changes: 41 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Run PyTest

on: [push, pull_request]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this run the action twice on a push to a branch that's already in a PR?


jobs:
run_pytest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Editable mode install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to consider separating the install of dependencies from the editable install of the package.

run: |
python -m pip install uv
uv pip install --system pytest pytest-cov pytest-html
uv pip install --system -e .
- name: Test with pytest
run: |
pytest --cov=./ --cov-report=html --html=pytest_report.html --self-contained-html

- name: Upload test report
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to using codecov as discussed. I've added the secret to the repo.

Example code at https://github.com/lsst/daf_butler/blob/main/.github/workflows/build.yaml#L92-L98

uses: actions/upload-artifact@v4
with:
name: pytest_report
path: pytest_report.html

- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage_report
path: htmlcov

7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config.log
*.pyc
*_wrap.cc
*Lib.py
*.egg-info

# Built by sconsUtils
version.py
Expand All @@ -16,10 +17,16 @@ bin/
# Pytest
tests/.tests
pytest_session.txt
pytest_report.html
htmlcov
.cache/
.pytest_cache
.coverage
.pre-commit-config.yaml
.flake8
.isort.cfg
.mypy.ini

# environment
.venv
.vscode
6 changes: 3 additions & 3 deletions Dockerfile.pqserver
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.11
RUN pip install flask gunicorn sqlalchemy psycopg2
WORKDIR /consdb-pq
COPY python/lsst/consdb/pqserver.py python/lsst/consdb/utils.py /consdb-pq/
WORKDIR /
COPY python/lsst/consdb/__init__.py python/lsst/consdb/pqserver.py python/lsst/consdb/utils.py /consdb-pq/
# Environment variables that must be set:
# DB_HOST DB_PASS DB_USER DB_NAME or POSTGRES_URL

# Expose the port.
EXPOSE 8080

ENTRYPOINT [ "gunicorn", "-b", "0.0.0.0:8080", "-w", "2", "pqserver:app" ]
ENTRYPOINT [ "gunicorn", "-b", "0.0.0.0:8080", "-w", "2", "consdb-pq.pqserver:app" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of surprised that this works with a hyphen in the name. If it doesn't, changing to just consdb should be fine, too.


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "consdb"
description = "consdb provides support for the Consolidated Database for the `Vera C. Rubin Observatory <https://lsst.org>`_."
license = { text = "GPL" }
dependencies = ["flask", "requests"]
dependencies = ["flask", "requests", "sqlalchemy"]
readme = "README.rst"
urls = { documentation = "https://consdb.lsst.io", source_code = "https://github.com/lsst-dm/consdb"}
dynamic = ["version"]
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/consdb/pqserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sqlalchemy
import sqlalchemy.dialects.postgresql
from flask import Flask, request
from utils import setup_logging, setup_postgres
from .utils import setup_logging, setup_postgres

OBS_TYPE_LIST = ["exposure", "visit1", "ccdexposure", "ccdvisit1"]
DTYPE_LIST = ["bool", "int", "float", "str"]
Expand Down
7 changes: 3 additions & 4 deletions tests/test_pqserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def db(tmpdir, scope="module"):
@pytest.fixture
def app(db, scope="module"):
os.environ["POSTGRES_URL"] = f"sqlite:///{db}"
import pqserver
from lsst.consdb import pqserver

return pqserver.app

Expand Down Expand Up @@ -198,16 +198,14 @@ def test_flexible_metadata(client):
assert result["required_keys"] == ["values"]

response = client.post(
"/consdb/insert/latiss",
"/consdb/insert/latiss/exposure/obs/2024032100003",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little weird to have this be different from the values, but perhaps that's an even better test.

json={
"table": "exposure",
"values": {
"exposure_name": "AT_O_20240327_000002",
"controller": "O",
"day_obs": 20240327,
"seq_num": 2,
},
"obs_id": 2024032700002,
},
)
_assert_http_status(response, 200)
Expand All @@ -216,6 +214,7 @@ def test_flexible_metadata(client):
"message": "Data inserted",
"table": "cdb_latiss.exposure",
"instrument": "latiss",
"obs_id": 2024032100003,
}

response = client.post("/consdb/query", json={"query": "SELECT * FROM exposure ORDER BY day_obs;"})
Expand Down
Loading