diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..99dc3e9 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +image: python:3.7 + +stages: + - static + - test + +mypy: + stage: static + before_script: + - pip install mypy + script: + - mypy techrec + +test: + stage: test + before_script: + - pip install pytest pytest-asyncio + - pip install -r requirements.txt + - mkdir techrec/output + script: + - pytest diff --git a/requirements.txt b/requirements.txt index 228b3be..cd1f9bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -SQLAlchemy==0.8.3 aiofiles==0.6.0 +aiohttp==3.7.4 click==7.1.2 fastapi==0.62.0 h11==0.11.0 pydantic==1.7.3 +SQLAlchemy==1.4.25 starlette==0.13.6 -techrec @ file:///home/gordo/my/ror/techrec typing-extensions==3.7.4.3 uvicorn==0.13.1 diff --git a/setup.cfg b/setup.cfg index c0f3a9a..945c1df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,8 @@ [flake8] max-line-length=89 ignore=D + +[mypy] +show_error_codes = True +python_version = 3.7 +pretty = True diff --git a/setup.py b/setup.py index a63b06e..ef5d227 100644 --- a/setup.py +++ b/setup.py @@ -2,18 +2,8 @@ from distutils.core import setup -REQUIREMENTS = [ - "SQLAlchemy==0.8.3", - "aiofiles==0.6.0", - "aiohttp==3.7.4", - "click==7.1.2", - "fastapi==0.62.0", - "h11==0.11.0", - "pydantic==1.7.3", - "starlette==0.13.6", - "typing-extensions==3.7.4.3", - "uvicorn==0.13.1", -] +with open("requirements.txt") as buf: + REQUIREMENTS = [line.strip() for line in buf if line.strip()] setup( name="techrec", @@ -32,7 +22,4 @@ setup( zip_safe=False, install_package_data=True, package_data={"techrec": ["static/**/*", "pages/*.html"]}, - test_suite="nose.collector", - setup_requires=["nose>=1.0"], - tests_requires=["nose>=1.0"], ) diff --git a/techrec/cli.py b/techrec/cli.py index 49dc81d..bb231c1 100644 --- a/techrec/cli.py +++ b/techrec/cli.py @@ -78,8 +78,11 @@ class DateTimeAction(Action): code_dir = os.path.dirname(os.path.realpath(__file__)) -def common_pre(): - prechecks = [pre_check_user, pre_check_permissions, pre_check_ffmpeg] +def common_pre(nochecks=False): + if nochecks: + prechecks = [] + else: + prechecks = [pre_check_user, pre_check_permissions, pre_check_ffmpeg] configs = ["default_config.py"] if "TECHREC_CONFIG" in os.environ: for conf in os.environ["TECHREC_CONFIG"].split(":"): diff --git a/techrec/server.py b/techrec/server.py index f0b14ab..7218b8c 100644 --- a/techrec/server.py +++ b/techrec/server.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import sys import logging import time import os @@ -20,7 +21,7 @@ from .forge import create_mp3, Validator logger = logging.getLogger("server") -common_pre() +common_pre(nochecks=('pytest' in sys.argv[0])) app = FastAPI() db = None diff --git a/techrec/test_forge.py b/techrec/test_forge.py index a236a12..17be93a 100644 --- a/techrec/test_forge.py +++ b/techrec/test_forge.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta -from nose.tools import raises, eq_ +import pytest +from pytest import raises from .forge import ( get_files_and_intervals, @@ -21,6 +22,10 @@ get_config()["FFMPEG_PATH"] = "ffmpeg" get_config()["FFMPEG_OUT_CODEC"] = ["-acodec", "copy"] +def eq_(a, b): + assert a == b, "%r != %r" % (a, b) + + def minutes(n): return timedelta(minutes=n) @@ -32,8 +37,9 @@ def seconds(n): # timefile -def test_timefile_exact(): - eq_(get_timefile_exact(eight), "2014-05/30/2014-05-30-20-00-00.mp3") +@pytest.mark.asyncio +async def test_timefile_exact(): + eq_(await get_timefile_exact(eight), "2014-05/30/2014-05-30-20-00-00.mp3") # Rounding @@ -52,25 +58,27 @@ def test_rounding_value(): # Rounding + timefile -def test_timefile_alreadyround(): - eq_(get_timefile(eight), "2014-05/30/2014-05-30-20-00-00.mp3") +@pytest.mark.asyncio +async def test_timefile_alreadyround(): + eq_(await get_timefile(eight), "2014-05/30/2014-05-30-20-00-00.mp3") -def test_timefile_toround(): - eq_(get_timefile(eight + minutes(20)), "2014-05/30/2014-05-30-20-00-00.mp3") +@pytest.mark.asyncio +async def test_timefile_toround(): + eq_(await get_timefile(eight + minutes(20)), "2014-05/30/2014-05-30-20-00-00.mp3") # Intervals -@raises(ValueError) def test_intervals_same(): - tuple(get_files_and_intervals(eight, eight)) + with raises(ValueError): + tuple(get_files_and_intervals(eight, eight)) -@raises(ValueError) def test_intervals_before(): - tuple(get_files_and_intervals(nine, eight)) + with raises(ValueError): + tuple(get_files_and_intervals(nine, eight)) def test_intervals_full_1():