diff --git a/.github/workflows/run_test.yaml b/.github/workflows/run_test.yaml new file mode 100644 index 000000000..ade495826 --- /dev/null +++ b/.github/workflows/run_test.yaml @@ -0,0 +1,31 @@ +name: ombott-test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + sudo apt-get install memcached libmemcached-tools + python -m pip install --upgrade pip + python3 -m pip install -r requirements.txt + python3 -m pip install -r test-requirements.txt + python3 -m pip install ombott + - name: build + run: | + python3 setup.py install + - name: Test with pytest + run: | + python3 -m pytest --cov=py4web --cov-report html:cov.html -v -s tests/ diff --git a/test-requirements.txt b/test-requirements.txt index d7c1c07af..ff6c77c91 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,4 @@ pytest pytest-cov mechanize==0.4.5 +python-memcached diff --git a/tests/test_main.py b/tests/test_main.py index 5b38768ad..df3d766ee 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,23 +1,25 @@ import os -import sys import unittest import tempfile -import time import signal -from multiprocessing import Process -from unittest.mock import patch from py4web.core import cli +from click.testing import CliRunner -def patched_cli(): +def run_cli(): dirpath = tempfile.mkdtemp() dir = os.path.join(dirpath, "apps") - testargs = ["py4web", 'setup', dir] - with patch.object(sys, "argv", testargs): - cli() - testargs = ["py4web", "run", "-d", "demo", dir] - with patch.object(sys, "argv", testargs): - cli() + runner = CliRunner() + + testargs = ['setup', dir] + res = runner.invoke(cli, testargs, input='y') + if res.exception: + raise res.exception + + testargs = ["run", "-d", "demo", dir] + res = runner.invoke(cli, testargs) + if res.exception: + raise res.exception class MainTest(unittest.TestCase): @@ -31,6 +33,6 @@ def handler(signum, frame): signal.signal(signal.SIGALRM, handler) signal.alarm(10) try: - patched_cli() + run_cli() except MyException: pass