Forráskód Böngészése

Merge branch 'v2-ci' into v2

boyska 2 éve
szülő
commit
23144cafa7
7 módosított fájl, 56 hozzáadás és 31 törlés
  1. 21 0
      .gitlab-ci.yml
  2. 2 2
      requirements.txt
  3. 5 0
      setup.cfg
  4. 2 15
      setup.py
  5. 5 2
      techrec/cli.py
  6. 2 1
      techrec/server.py
  7. 19 11
      techrec/test_forge.py

+ 21 - 0
.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

+ 2 - 2
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

+ 5 - 0
setup.cfg

@@ -1,3 +1,8 @@
 [flake8]
 max-line-length=89
 ignore=D
+
+[mypy]
+show_error_codes = True
+python_version = 3.7
+pretty = True

+ 2 - 15
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"],
 )

+ 5 - 2
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(":"):

+ 2 - 1
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
 

+ 19 - 11
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():