Skip to content

Commit

Permalink
Merge pull request #100 from quaternionmedia/pytest
Browse files Browse the repository at this point in the history
🧪 Pytest
  • Loading branch information
mrharpo authored Mar 21, 2023
2 parents fb3b860 + c002f5e commit 4b72ebd
Show file tree
Hide file tree
Showing 24 changed files with 296 additions and 201 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ⚗️ CI tests

on: [push, pull_request]

jobs:
api_tests:
name: 🐢 API tests
uses: ./.github/workflows/nox.yml
with:
args: coverage

lint:
name: 👖 Linter
uses: ./.github/workflows/nox.yml
with:
args: lint

format:
name: ⬛ Black Formatter
uses: ./.github/workflows/nox.yml
with:
args: blacken

# integration_tests:
# name: 🔏 Integration tests
# uses: ./.github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Application Test
name: 🦢 Cypress Tests

on:
push:
pull_request:

workflow_call:

jobs:
run_tests:
name: 🦢 Cypress
timeout-minutes: 15
runs-on: ubuntu-latest

Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/nox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 🛢️ nox

on:
workflow_call:
inputs:
args:
required: true
type: string

jobs:
run_nox:
name: 🛢️ nox
runs-on: ubuntu-latest

steps:
- name: 📰 Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: 🐍 Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: 🏗️ Setup testing environment
run: pip3 install -r tests/requirements-tests.txt

- name: 🧪 Run nox test suite
run: nox -f tests/noxfile.py -s ${{ inputs.args }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ output/*
alfred/output/*
alfred/data
alfred/site
alfred.egg*

*.mp3
*.mp4
*.png
*.pdf
*.txt
*.json
*.jpg
*.edl
Expand All @@ -67,4 +67,6 @@ alfred/site
instrumented/
website/coverage/
website/cypress-coverage/
test/
tests/.nox/
tests/.benchmarks/
tests/reports/
63 changes: 63 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Alfred",
"type": "python",
"request": "launch",
"module": "uvicorn",
"cwd": "${workspaceFolder}/alfred",
"args": ["main:app", "--host", "0.0.0.0", "--port", "9000", "--reload"],
"env": {
"CELERY_BROKER": "mongodb://localhost:27017/celery",
"CELERY_BACKEND": "mongodb://localhost:27017/celery",
"DB_URL": "mongodb://localhost:27017",
"DB_NAME": "alfred",
"GOOGLE_APPLICATION_CREDENTIALS": "/cred.json",
"ALFRED_SECRET_KEY": "ALFRED_SECRET_KEY"
},
"jinja": false,
"justMyCode": false
},
{
"name": "Otto",
"type": "python",
"request": "launch",
"module": "uvicorn",
"cwd": "${workspaceFolder}/alfred/otto/",
"args": [
"otto.preview:previewAPI",
"--host",
"0.0.0.0",
"--port",
"9000",
"--reload"
],
"jinja": false,
"justMyCode": false
},
{
"name": "Alfred Tests",
"type": "python",
"request": "launch",
"module": "pytest",
"cwd": "${workspaceFolder}",
"args": ["-v"],
"jinja": false,
"justMyCode": false
},
{
"name": "Otto Tests",
"type": "python",
"request": "launch",
"module": "pytest",
"cwd": "${workspaceFolder}/alfred/otto/",
"args": ["-v"],
"jinja": false,
"justMyCode": true
}
]
}
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ RUN pip3 install -e /alfred/alfred/otto/
COPY /setup.py /alfred/
RUN pip3 install -e /alfred/

COPY alfred/otto/fonts/* /usr/share/fonts/truetype/
RUN fc-cache -fv

ENTRYPOINT ["python3.10", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--reload"]
14 changes: 11 additions & 3 deletions al
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ git
i | install
init
l | log
n | nox
p | production
reload
r | restart
Expand Down Expand Up @@ -78,7 +79,6 @@ elif [ $1 = "init" ]; then
mkdir -p $(dirname $0)/alfred/data
mkdir -p $(dirname $0)/alfred/site
echo "installing dependencies"
# make install
docker compose run website yarn install

# Installs the dependencies.
Expand Down Expand Up @@ -164,11 +164,19 @@ elif [ $1 = "docker" -o $1 = "dock" ]; then

elif [ $1 = "t" -o $1 = "test" -o $1 = "cy" ]; then
shift
docker compose -f test_cy.yml up --exit-code-from cy
docker compose -f test_cy.yml up --exit-code-from cy "$@"

elif [ $1 = "pt" -o $1 = "pytest" -o $1 = "py" ]; then
shift
docker compose -f pytest.yml up --exit-code-from pytest "$@"

elif [ $1 = "n" -o $1 = "nox" ]; then
shift
nox -f tests/noxfile.py "$@"

elif [ $1 = "bats" -o $1 = "bat" ]; then
shift
docker compose -f test_bats.yml up --build --exit-code-from bats
docker compose -f test_bats.yml up --build --exit-code-from bats "$@"

else
echo "Unknown command: $1"
Expand Down
2 changes: 1 addition & 1 deletion alfred/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.3'
__version__ = '0.2.0'
23 changes: 11 additions & 12 deletions alfred/core/routes/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@

previewAPI = APIRouter()


@previewAPI.post('/')
async def previewFrame(t: float, render: Render):
"""# Preview frame
Generates a frame of a given `edl` at time `t`, with `width` and `height`.
Returns the name of a file on this server when available, or a relevant error message"""
print('previewing', render.edl, 'at frame', t)
try:
# active_clips = [c for c in render.edl.clips if t >= (c.start or 0) + (c.offset or 0)]
# print('generating active clips', active_clips, t)
video = generateEdl(Edl(clips=render.edl.clips), moviesize=(render.width, render.height))
frame_name = join('data', timestr() + '.jpg')
print('saving frame', video)
video.save_frame(frame_name, t=t, withmask=False)
return frame_name
except Exception as e:
print('error previewing frame', e)
raise HTTPException(status_code=500, detail='error previewing frame')
# print('generating active clips', active_clips, t)
# active_clips = [c for c in render.edl.clips if t >= (c.start or 0) + (c.offset or 0)]
video = generateEdl(
Edl(clips=render.edl.clips), moviesize=(render.width, render.height)
)
frame_name = join('data', timestr() + '.jpg')
print(f'saving frame {t} as: {frame_name}', video)
video.save_frame(frame_name, t=t, withmask=False)
return frame_name
2 changes: 1 addition & 1 deletion alfred/docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _version import __version__
from alfred._version import __version__

title = """Alfred API"""

Expand Down
61 changes: 34 additions & 27 deletions alfred/main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from fastapi import FastAPI, Depends
from typing import Optional
from fastapi.middleware.gzip import GZipMiddleware
from starlette.staticfiles import StaticFiles
from beanie import init_beanie

from subprocess import run as bash

from core.routes import authAPI
from core.routes import videoAPI
from core.routes import issueAPI
from core.routes import adminAPI
from core.routes import fontAPI
from core.routes import ProjectAPI
from core.routes import RenderAPI
from core.routes import previewAPI
from otto.main import app as ottoApi
from core.utils import get_db
from core.utils.db import deOid
from core.routes.users import (
from alfred.core.routes import authAPI
from alfred.core.routes import videoAPI
from alfred.core.routes import issueAPI
from alfred.core.routes import adminAPI
from alfred.core.routes import fontAPI
from alfred.core.routes import ProjectAPI
from alfred.core.routes import RenderAPI
from alfred.core.routes import previewAPI

# from otto.main import app as ottoApi
from alfred.core.utils import get_db

# from alfred.core.utils.db import deOid
from alfred.core.routes.users import (
fastapi_users,
current_active_user,
current_active_superuser,
)
from core.models.users import UserRead, UserUpdate
from core.utils.db import User
from seed import seed
import docs
from alfred.core.models.users import UserRead, UserUpdate
from alfred.core.utils.db import User
from alfred import docs


app = FastAPI(
Expand All @@ -39,16 +39,6 @@
app.add_middleware(GZipMiddleware)


@app.on_event("startup")
async def on_startup():
await init_beanie(
database=get_db(),
document_models=[
User,
],
)


@app.on_event('startup')
async def seedDb():
db = get_db()
Expand Down Expand Up @@ -127,6 +117,23 @@ async def checkFonts():
# if request does not match the above api, try to return a StaticFiles match
app.mount('/', StaticFiles(directory='dist', html=True), name='static')


@app.on_event("startup")
async def on_startup():
await init_beanie(
database=get_db(),
document_models=[
User,
renders.schema,
renders.create_schema,
renders.update_schema,
projects.schema,
projects.create_schema,
projects.update_schema,
],
)


if __name__ == '__main__':
from uvicorn import run

Expand Down
8 changes: 4 additions & 4 deletions alfred/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name": "makeColor",
"duration": 7.2,
"start": 17.1,
"data": {"preserve": {"color": [255, 255, 255], "opacity": 1}},
"data": {"preserve": {"color": "#FFFFFF"}},
}
},
{
Expand Down Expand Up @@ -66,7 +66,7 @@
},
"position": [
"center",
{"floor": {"*": [0.1, {"var": "height"}]}},
{"floor": {"*": [0.2, {"var": "height"}]}},
],
"opacity": 1,
"fxs": {
Expand Down Expand Up @@ -227,7 +227,7 @@
},
"position": [
"center",
{"floor": {"*": [0.14, {"var": "height"}]}},
{"floor": {"*": [0.25, {"var": "height"}]}},
],
"opacity": 1,
"fxs": {
Expand Down Expand Up @@ -387,7 +387,7 @@
},
"position": [
"center",
{"floor": {"*": [0.1, {"var": "height"}]}},
{"floor": {"*": [0.2, {"var": "height"}]}},
],
"opacity": 1,
"fxs": {
Expand Down
20 changes: 0 additions & 20 deletions alfred/testapi.py

This file was deleted.

Loading

0 comments on commit 4b72ebd

Please sign in to comment.