From d0a5b7ed54a3fc89151fcf7b179336a71d22d3db Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 28 Sep 2021 23:49:22 +0200 Subject: [PATCH 1/7] mypy can be run via gitlab-runner gitlab-runner exec docker static --- .gitlab-ci.yml | 12 ++++++++++++ setup.cfg | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e51fbad --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,12 @@ +image: python:3.7 + +stages: + - static + - test + +static: + stage: static + before_script: + - pip install mypy + script: + - mypy techrec 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 From de43301785bf7b9275bf0ba7521b64c0def8c197 Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 28 Sep 2021 23:56:27 +0200 Subject: [PATCH 2/7] gitlab-runner test --- .gitlab-ci.yml | 10 +++++++++- requirements.txt | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e51fbad..35322c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,17 @@ stages: - static - test -static: +mypy: stage: static before_script: - pip install mypy script: - mypy techrec + +test: + stage: test + before_script: + - pip install nose + - pip install -r requirements.txt + script: + - nosetests diff --git a/requirements.txt b/requirements.txt index 228b3be..fab5f43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,5 @@ fastapi==0.62.0 h11==0.11.0 pydantic==1.7.3 starlette==0.13.6 -techrec @ file:///home/gordo/my/ror/techrec typing-extensions==3.7.4.3 uvicorn==0.13.1 From 993d91e5b8e94f015c21bc9804f679b35a96491f Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 29 Sep 2021 00:01:14 +0200 Subject: [PATCH 3/7] refactor requirements --- requirements.txt | 3 ++- setup.py | 14 ++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/requirements.txt b/requirements.txt index fab5f43..1090448 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +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==0.8.3 starlette==0.13.6 typing-extensions==3.7.4.3 uvicorn==0.13.1 diff --git a/setup.py b/setup.py index a63b06e..91f9232 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", From 193d77ae099f2432befd78d5a9ba656e4d97afa7 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 29 Sep 2021 00:04:25 +0200 Subject: [PATCH 4/7] upgrade sqlalchemy let's hope this works; installation should be much faster (wheel) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1090448..cd1f9bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ click==7.1.2 fastapi==0.62.0 h11==0.11.0 pydantic==1.7.3 -SQLAlchemy==0.8.3 +SQLAlchemy==1.4.25 starlette==0.13.6 typing-extensions==3.7.4.3 uvicorn==0.13.1 From d302596d73439957252ae8baccc5a9479594c55f Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 29 Sep 2021 00:30:31 +0200 Subject: [PATCH 5/7] =?UTF-8?q?nose=20=E2=86=92=20py.test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 5 +++-- setup.py | 3 --- techrec/test_forge.py | 13 ++++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35322c5..eccf0e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,8 @@ mypy: test: stage: test before_script: - - pip install nose + - pip install pytest - pip install -r requirements.txt + - mkdir output script: - - nosetests + - pytest diff --git a/setup.py b/setup.py index 91f9232..ef5d227 100644 --- a/setup.py +++ b/setup.py @@ -22,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/test_forge.py b/techrec/test_forge.py index a236a12..1f787c6 100644 --- a/techrec/test_forge.py +++ b/techrec/test_forge.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from nose.tools import raises, eq_ +from pytest import raises from .forge import ( get_files_and_intervals, @@ -21,6 +21,9 @@ 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) @@ -63,14 +66,14 @@ def test_timefile_toround(): # 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(): From c8bf2c20714538f107b0e8a2a0ced5a1d3c91451 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 29 Sep 2021 00:31:08 +0200 Subject: [PATCH 6/7] disable some checks if testing --- techrec/cli.py | 7 +++++-- techrec/server.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 From ef97c952d214cbe1030cf6448dd4592a7ac14ec8 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 29 Sep 2021 00:37:10 +0200 Subject: [PATCH 7/7] port tests to new async interface --- .gitlab-ci.yml | 4 ++-- techrec/test_forge.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eccf0e3..99dc3e9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,8 +14,8 @@ mypy: test: stage: test before_script: - - pip install pytest + - pip install pytest pytest-asyncio - pip install -r requirements.txt - - mkdir output + - mkdir techrec/output script: - pytest diff --git a/techrec/test_forge.py b/techrec/test_forge.py index 1f787c6..17be93a 100644 --- a/techrec/test_forge.py +++ b/techrec/test_forge.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta +import pytest from pytest import raises from .forge import ( @@ -21,8 +22,9 @@ get_config()["FFMPEG_PATH"] = "ffmpeg" get_config()["FFMPEG_OUT_CODEC"] = ["-acodec", "copy"] -def eq_(a,b): - assert a==b, "%r != %r" % (a,b) +def eq_(a, b): + assert a == b, "%r != %r" % (a, b) + def minutes(n): return timedelta(minutes=n) @@ -35,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 @@ -55,12 +58,14 @@ 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