Skip to content

Commit 4b72ebd

Browse files
authored
Merge pull request #100 from quaternionmedia/pytest
🧪 Pytest
2 parents fb3b860 + c002f5e commit 4b72ebd

24 files changed

+296
-201
lines changed

.github/workflows/CI.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: ⚗️ CI tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
api_tests:
7+
name: 🐢 API tests
8+
uses: ./.github/workflows/nox.yml
9+
with:
10+
args: coverage
11+
12+
lint:
13+
name: 👖 Linter
14+
uses: ./.github/workflows/nox.yml
15+
with:
16+
args: lint
17+
18+
format:
19+
name: ⬛ Black Formatter
20+
uses: ./.github/workflows/nox.yml
21+
with:
22+
args: blacken
23+
24+
# integration_tests:
25+
# name: 🔏 Integration tests
26+
# uses: ./.github/workflows/cypress.yml

.github/workflows/app_test.yml .github/workflows/cypress.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Application Test
1+
name: 🦢 Cypress Tests
22

33
on:
4-
push:
5-
pull_request:
6-
4+
workflow_call:
5+
76
jobs:
87
run_tests:
8+
name: 🦢 Cypress
99
timeout-minutes: 15
1010
runs-on: ubuntu-latest
1111

.github/workflows/nox.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 🛢️ nox
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
args:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
run_nox:
12+
name: 🛢️ nox
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: 📰 Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
submodules: recursive
20+
21+
- name: 🐍 Setup Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: 3.11
25+
26+
- name: 🏗️ Setup testing environment
27+
run: pip3 install -r tests/requirements-tests.txt
28+
29+
- name: 🧪 Run nox test suite
30+
run: nox -f tests/noxfile.py -s ${{ inputs.args }}

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ output/*
4848
alfred/output/*
4949
alfred/data
5050
alfred/site
51+
alfred.egg*
5152

5253
*.mp3
5354
*.mp4
5455
*.png
5556
*.pdf
56-
*.txt
5757
*.json
5858
*.jpg
5959
*.edl
@@ -67,4 +67,6 @@ alfred/site
6767
instrumented/
6868
website/coverage/
6969
website/cypress-coverage/
70-
test/
70+
tests/.nox/
71+
tests/.benchmarks/
72+
tests/reports/

.vscode/launch.json

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Alfred",
9+
"type": "python",
10+
"request": "launch",
11+
"module": "uvicorn",
12+
"cwd": "${workspaceFolder}/alfred",
13+
"args": ["main:app", "--host", "0.0.0.0", "--port", "9000", "--reload"],
14+
"env": {
15+
"CELERY_BROKER": "mongodb://localhost:27017/celery",
16+
"CELERY_BACKEND": "mongodb://localhost:27017/celery",
17+
"DB_URL": "mongodb://localhost:27017",
18+
"DB_NAME": "alfred",
19+
"GOOGLE_APPLICATION_CREDENTIALS": "/cred.json",
20+
"ALFRED_SECRET_KEY": "ALFRED_SECRET_KEY"
21+
},
22+
"jinja": false,
23+
"justMyCode": false
24+
},
25+
{
26+
"name": "Otto",
27+
"type": "python",
28+
"request": "launch",
29+
"module": "uvicorn",
30+
"cwd": "${workspaceFolder}/alfred/otto/",
31+
"args": [
32+
"otto.preview:previewAPI",
33+
"--host",
34+
"0.0.0.0",
35+
"--port",
36+
"9000",
37+
"--reload"
38+
],
39+
"jinja": false,
40+
"justMyCode": false
41+
},
42+
{
43+
"name": "Alfred Tests",
44+
"type": "python",
45+
"request": "launch",
46+
"module": "pytest",
47+
"cwd": "${workspaceFolder}",
48+
"args": ["-v"],
49+
"jinja": false,
50+
"justMyCode": false
51+
},
52+
{
53+
"name": "Otto Tests",
54+
"type": "python",
55+
"request": "launch",
56+
"module": "pytest",
57+
"cwd": "${workspaceFolder}/alfred/otto/",
58+
"args": ["-v"],
59+
"jinja": false,
60+
"justMyCode": true
61+
}
62+
]
63+
}

Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@ RUN pip3 install -e /alfred/alfred/otto/
1010
COPY /setup.py /alfred/
1111
RUN pip3 install -e /alfred/
1212

13-
COPY alfred/otto/fonts/* /usr/share/fonts/truetype/
14-
RUN fc-cache -fv
15-
1613
ENTRYPOINT ["python3.10", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80", "--reload"]

al

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ git
1919
i | install
2020
init
2121
l | log
22+
n | nox
2223
p | production
2324
reload
2425
r | restart
@@ -78,7 +79,6 @@ elif [ $1 = "init" ]; then
7879
mkdir -p $(dirname $0)/alfred/data
7980
mkdir -p $(dirname $0)/alfred/site
8081
echo "installing dependencies"
81-
# make install
8282
docker compose run website yarn install
8383

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

165165
elif [ $1 = "t" -o $1 = "test" -o $1 = "cy" ]; then
166166
shift
167-
docker compose -f test_cy.yml up --exit-code-from cy
167+
docker compose -f test_cy.yml up --exit-code-from cy "$@"
168+
169+
elif [ $1 = "pt" -o $1 = "pytest" -o $1 = "py" ]; then
170+
shift
171+
docker compose -f pytest.yml up --exit-code-from pytest "$@"
172+
173+
elif [ $1 = "n" -o $1 = "nox" ]; then
174+
shift
175+
nox -f tests/noxfile.py "$@"
168176

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

173181
else
174182
echo "Unknown command: $1"

alfred/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.3'
1+
__version__ = '0.2.0'

alfred/core/routes/preview.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77

88
previewAPI = APIRouter()
99

10+
1011
@previewAPI.post('/')
1112
async def previewFrame(t: float, render: Render):
1213
"""# Preview frame
1314
Generates a frame of a given `edl` at time `t`, with `width` and `height`.
14-
15+
1516
Returns the name of a file on this server when available, or a relevant error message"""
1617
print('previewing', render.edl, 'at frame', t)
17-
try:
18-
# active_clips = [c for c in render.edl.clips if t >= (c.start or 0) + (c.offset or 0)]
19-
# print('generating active clips', active_clips, t)
20-
video = generateEdl(Edl(clips=render.edl.clips), moviesize=(render.width, render.height))
21-
frame_name = join('data', timestr() + '.jpg')
22-
print('saving frame', video)
23-
video.save_frame(frame_name, t=t, withmask=False)
24-
return frame_name
25-
except Exception as e:
26-
print('error previewing frame', e)
27-
raise HTTPException(status_code=500, detail='error previewing frame')
18+
# print('generating active clips', active_clips, t)
19+
# active_clips = [c for c in render.edl.clips if t >= (c.start or 0) + (c.offset or 0)]
20+
video = generateEdl(
21+
Edl(clips=render.edl.clips), moviesize=(render.width, render.height)
22+
)
23+
frame_name = join('data', timestr() + '.jpg')
24+
print(f'saving frame {t} as: {frame_name}', video)
25+
video.save_frame(frame_name, t=t, withmask=False)
26+
return frame_name

alfred/docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _version import __version__
1+
from alfred._version import __version__
22

33
title = """Alfred API"""
44

alfred/main.py

+34-27
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
from fastapi import FastAPI, Depends
2-
from typing import Optional
32
from fastapi.middleware.gzip import GZipMiddleware
43
from starlette.staticfiles import StaticFiles
54
from beanie import init_beanie
65

76
from subprocess import run as bash
87

9-
from core.routes import authAPI
10-
from core.routes import videoAPI
11-
from core.routes import issueAPI
12-
from core.routes import adminAPI
13-
from core.routes import fontAPI
14-
from core.routes import ProjectAPI
15-
from core.routes import RenderAPI
16-
from core.routes import previewAPI
17-
from otto.main import app as ottoApi
18-
from core.utils import get_db
19-
from core.utils.db import deOid
20-
from core.routes.users import (
8+
from alfred.core.routes import authAPI
9+
from alfred.core.routes import videoAPI
10+
from alfred.core.routes import issueAPI
11+
from alfred.core.routes import adminAPI
12+
from alfred.core.routes import fontAPI
13+
from alfred.core.routes import ProjectAPI
14+
from alfred.core.routes import RenderAPI
15+
from alfred.core.routes import previewAPI
16+
17+
# from otto.main import app as ottoApi
18+
from alfred.core.utils import get_db
19+
20+
# from alfred.core.utils.db import deOid
21+
from alfred.core.routes.users import (
2122
fastapi_users,
2223
current_active_user,
2324
current_active_superuser,
2425
)
25-
from core.models.users import UserRead, UserUpdate
26-
from core.utils.db import User
27-
from seed import seed
28-
import docs
26+
from alfred.core.models.users import UserRead, UserUpdate
27+
from alfred.core.utils.db import User
28+
from alfred import docs
2929

3030

3131
app = FastAPI(
@@ -39,16 +39,6 @@
3939
app.add_middleware(GZipMiddleware)
4040

4141

42-
@app.on_event("startup")
43-
async def on_startup():
44-
await init_beanie(
45-
database=get_db(),
46-
document_models=[
47-
User,
48-
],
49-
)
50-
51-
5242
@app.on_event('startup')
5343
async def seedDb():
5444
db = get_db()
@@ -127,6 +117,23 @@ async def checkFonts():
127117
# if request does not match the above api, try to return a StaticFiles match
128118
app.mount('/', StaticFiles(directory='dist', html=True), name='static')
129119

120+
121+
@app.on_event("startup")
122+
async def on_startup():
123+
await init_beanie(
124+
database=get_db(),
125+
document_models=[
126+
User,
127+
renders.schema,
128+
renders.create_schema,
129+
renders.update_schema,
130+
projects.schema,
131+
projects.create_schema,
132+
projects.update_schema,
133+
],
134+
)
135+
136+
130137
if __name__ == '__main__':
131138
from uvicorn import run
132139

alfred/seed.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"name": "makeColor",
1919
"duration": 7.2,
2020
"start": 17.1,
21-
"data": {"preserve": {"color": [255, 255, 255], "opacity": 1}},
21+
"data": {"preserve": {"color": "#FFFFFF"}},
2222
}
2323
},
2424
{
@@ -66,7 +66,7 @@
6666
},
6767
"position": [
6868
"center",
69-
{"floor": {"*": [0.1, {"var": "height"}]}},
69+
{"floor": {"*": [0.2, {"var": "height"}]}},
7070
],
7171
"opacity": 1,
7272
"fxs": {
@@ -227,7 +227,7 @@
227227
},
228228
"position": [
229229
"center",
230-
{"floor": {"*": [0.14, {"var": "height"}]}},
230+
{"floor": {"*": [0.25, {"var": "height"}]}},
231231
],
232232
"opacity": 1,
233233
"fxs": {
@@ -387,7 +387,7 @@
387387
},
388388
"position": [
389389
"center",
390-
{"floor": {"*": [0.1, {"var": "height"}]}},
390+
{"floor": {"*": [0.2, {"var": "height"}]}},
391391
],
392392
"opacity": 1,
393393
"fxs": {

alfred/testapi.py

-20
This file was deleted.

0 commit comments

Comments
 (0)