Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abhidg committed Oct 29, 2024
1 parent dd0ca3e commit b31fefe
Show file tree
Hide file tree
Showing 9 changed files with 1,027 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
run: make install-uv
- name: Lint and test
run: make
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests: lint install
uv run pytest tests

install-uv:
curl -LsSf https://astral.sh/uv/0.4.27/install.sh | sh

install:
uv sync --all-extras --dev

lint:
uvx ruff check src
uvx ruff check tests

.PHONY: install-uv install lint tests
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ scripts.arcmapper = "arcmapper:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[dependency-groups]
dev = [
"pytest>=8.3.3",
]
1 change: 0 additions & 1 deletion src/arcmapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
import webbrowser

import pandas as pd
from waitress import serve
from .app import app
from .arc import read_arc_schema
Expand Down
4 changes: 3 additions & 1 deletion src/arcmapper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ def upload_data_dictionary(
col_description,
):
ok = dbc.Alert("Upload successful", color="success")
err = lambda msg: dbc.Alert(msg, color="danger")

def err(msg): return dbc.Alert(msg, color="danger")

if ctx.triggered_id == "upload-btn" and upload_contents is not None:
try:
df = read_upload_data(upload_contents, filename)
Expand Down
883 changes: 883 additions & 0 deletions tests/data/ARCH.csv

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions tests/test_arc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"Module to read ARC schema"

from pathlib import Path

from arcmapper.arc import arc_schema_url, read_arc_schema


def test_arc_schema_url():
assert arc_schema_url("1.0.0") == "https://github.com/ISARICResearch/DataPlatform/raw/refs/heads/main/ARCH/ARCH1.0.0/ARCH.csv"


def test_read_arc_schema():
arc = read_arc_schema(str(Path(__file__).parent / 'data' / 'ARCH.csv'))
print(arc)
19 changes: 19 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"Utility functions for arcmapper"
from pathlib import Path

import pandas as pd

from arcmapper.util import read_data, read_csv_with_encoding_detection, parse_redcap_response

def test_read_data():
arc_path = str(Path(__file__).parent / 'data' / 'ARCH.csv')
assert isinstance(read_data(arc_path), pd.DataFrame)

def test_read_csv_with_encoding_detection():
"Reads CSV file with encoding detection"

arc_path = str(Path(__file__).parent / 'data' / 'ARCH.csv')
assert isinstance(read_csv_with_encoding_detection(arc_path), pd.DataFrame)

def test_parse_redcap_response():
assert parse_redcap_response("1, male | 2, female") == [("1", "male"), ("2", "female")]
61 changes: 61 additions & 0 deletions uv.lock

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

0 comments on commit b31fefe

Please sign in to comment.