Skip to content

Commit

Permalink
init tests and tests for Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rchan26 committed Apr 18, 2024
1 parent 3fd40f4 commit 907f485
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 9 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- develop
release:
types:
- published

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 3

jobs:
pre-commit:
name: Lint with pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: pre-commit/[email protected]

checks:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
needs: [pre-commit]
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]
runs-on: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: python -m pip install .[test]

- name: Test package
run: python -m pytest -ra --cov=batch_llm

- name: Upload coverage report
uses: codecov/[email protected]

# dist:
# name: Distribution build
# runs-on: ubuntu-latest
# needs: [pre-commit]

# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0

# - name: Build sdist and wheel
# run: pipx run build

# - uses: actions/upload-artifact@v4
# with:
# path: dist

# - name: Check products
# run: pipx run twine check dist/*

# - uses: pypa/[email protected]
# if: github.event_name == 'release' && github.event.action == 'published'
# with:
# # Remember to generate this and set it in "GitHub Secrets"
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ vertexai = {version = "^1.46.0", extras = ["gemini"]}
google-cloud-aiplatform = {version = "^1.46.0", extras = ["gemini"]}
google-generativeai = {version = "^0.4.1", extras = ["gemini"]}
pillow = "^10.3.0"
openai = "^1.19.0"
openai = {version = "^1.19.0", extras = ["azure_openai", "openai"]}


[tool.poetry.group.dev.dependencies]
black = "^24.3.0"
isort = "^5.13.2"
pre-commit = "^3.7.0"
ipykernel = "^6.29.4"
pytest = "^8.1.1"

[build-system]
requires = ["poetry-core"]
Expand Down
15 changes: 7 additions & 8 deletions src/batch_llm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def check_folder_exists(data_folder: str) -> tuple[str]:
Raises a ValueError if the data folder does not exist.
"""
# check if data folder exists
if not os.path.exists(data_folder):
raise ValueError(f"Data folder '{data_folder}' does not exist")
if not os.path.isdir(data_folder):
raise ValueError(
f"Data folder '{data_folder}' must be a valid path to a folder"
)

return True

Expand Down Expand Up @@ -85,8 +87,7 @@ def input_folder(self) -> str:
@input_folder.setter
def input_folder(self, value: str):
raise WriteFolderError(
"Cannot write to input folder on it's own. Use the 'set_and_create_subfolders' "
"method to set the input folder"
"Cannot set input folder on it's own. Set the 'data_folder' instead"
)

# ---- output folder (read only) ----
Expand All @@ -98,8 +99,7 @@ def output_folder(self) -> str:
@output_folder.setter
def output_folder(self, value: str):
raise WriteFolderError(
"Cannot write to output folder on it's own. Use the 'set_and_create_subfolders' "
"method to set the output folder"
"Cannot set output folder on it's own. Set the 'data_folder' instead"
)

# ---- media folder (read only) ----
Expand All @@ -111,8 +111,7 @@ def media_folder(self) -> str:
@media_folder.setter
def media_folder(self, value: str):
raise WriteFolderError(
"Cannot write to media folder on it's own. Use the 'set_and_create_subfolders' "
"method to set the media folder"
"Cannot set media folder on it's own. Set the 'data_folder' instead"
)

# ---- max queries ----
Expand Down
40 changes: 40 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
from pathlib import Path

import pytest


@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname)


@pytest.fixture()
def temporary_data_folders(tmp_path):
"""
Creates a temporary folder structure for testing.
Has the following structure:
tmp_path
├── data/
├── dummy_data/
├── test.txt
"""
# create data folders
data_dir = Path(tmp_path / "data").mkdir()
dummy_data_dir = Path(tmp_path / "dummy_data").mkdir()

# create a txt file in the folder
with open(Path(tmp_path / "test.txt"), "w") as f:
f.write("test line")

# store current working directory
cwd = os.getcwd()

# change to temporary directory
os.chdir(tmp_path)

yield data_dir, dummy_data_dir

# change back to original directory
os.chdir(cwd)
Empty file added tests/core/test_experiment.py
Empty file.
Empty file.
Loading

0 comments on commit 907f485

Please sign in to comment.