From 269cd8302d4ff73bec6152bda6a2605f48b2e86b Mon Sep 17 00:00:00 2001 From: Jeremy Watt Date: Tue, 16 Jul 2024 19:17:23 -0700 Subject: [PATCH] requirements test --- .github/workflows/python-app.yml | 50 ++++++++++++++++++++++++++++++++ README.md | 2 +- requirements.test | 3 ++ tests/__init__.py | 5 ++++ tests/test_streamlit.py | 27 +++++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/python-app.yml create mode 100644 requirements.test create mode 100644 tests/__init__.py create mode 100644 tests/test_streamlit.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..7fcbe7e --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,50 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main"] + paths-ignore: + - '**/README.md' + - '**/CONTRIBUTING.md' + - '**LICENSE' + pull_request: + branches: [ "main" ] + paths-ignore: + - '**/README.md' + - '**/CONTRIBUTING.md' + - '**LICENSE' + +jobs: + ruff: + name: lint with ruff + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v2 + - uses: chartboost/ruff-action@v1 + with: + args: 'format --check' + config: .ruff.toml + test: + name: run pytest + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.test + pip install -r requirements.txt + - name: Run pytest + run: | + PYTHONPATH=. python3.10 -m pytest tests/test_streamlit.py diff --git a/README.md b/README.md index 3c5a8da..5e0a2dc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![HuggingFace Space](https://img.shields.io/badge/🤗-HuggingFace%20Space-cyan.svg)](https://huggingface.co/spaces/neonwatty/youtube_shorts_transcript_downloader) [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/jermwatt/youtube_transcript_downloader/blob/main/transcript_downloader_walkthrough.ipynb) -Youtube +Youtube [![Python application](https://github.com/neonwatty/youtube_shorts_transcript_downloader/actions/workflows/python-app.yml/badge.svg)](https://github.com/neonwatty/youtube_shorts_transcript_downloader/actions/workflows/python-app.yml/python-app.yml) diff --git a/requirements.test b/requirements.test new file mode 100644 index 0000000..864d269 --- /dev/null +++ b/requirements.test @@ -0,0 +1,3 @@ +pytest +pytest-subtests +ruff \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..bd9d568 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,5 @@ +import os + +cwd = os.getcwd() +CONTAINER_NAME = "youtube_shorts_transcript_downloader" +STREAMLIT_FILE = "youtube_shorts_transcript_downloader/app.py" diff --git a/tests/test_streamlit.py b/tests/test_streamlit.py new file mode 100644 index 0000000..90d214e --- /dev/null +++ b/tests/test_streamlit.py @@ -0,0 +1,27 @@ +import subprocess +import pytest +import time +from tests import STREAMLIT_FILE + + +@pytest.fixture(scope="module") +def start_streamlit_app(): + cmd = f"python -m streamlit run {STREAMLIT_FILE} --server.headless true" + process = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + time.sleep(5) + yield process + process.terminate() + process.wait() + + +def test_streamlit(subtests, start_streamlit_app): + with subtests.test(msg="streamlit up"): + assert start_streamlit_app.poll() is None, "Streamlit app failed to start" + + with subtests.test(msg="streamlit down"): + start_streamlit_app.terminate() + time.sleep(2) + assert start_streamlit_app.poll() is not None, "Streamlit app failed to stop" +