Skip to content

Commit

Permalink
run tests one by one
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Sep 26, 2024
1 parent 5f9e1c9 commit f70ef33
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
82 changes: 67 additions & 15 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,92 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies

- name: Install linting tools
run: |
python -m pip install --upgrade pip
pip install flake8
pip install black
pip install isort
python -m pip install poetry
poetry install --no-root # This will install the project dependencies defined in pyproject.toml
pip install flake8 black isort
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --statistics
- name: Format code with Black
run: |
black . --exclude="" --check --verbose
- name: Sort imports with isort
run: |
isort . --profile=black --check-only --verbose
- name: Test with unittest
- name: Run tests for Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install dependencies and run tests (3.8)
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --no-root
poetry run python -m unittest discover tests
- name: Run tests for Python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9
- name: Install dependencies and run tests (3.9)
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --no-root
poetry run python -m unittest discover tests
- name: Run tests for Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies and run tests (3.10)
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --no-root
poetry run python -m unittest discover tests
- name: Run tests for Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies and run tests (3.11)
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --no-root
poetry run python -m unittest discover tests
- name: Run tests for Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies and run tests (3.12)
env:
API_KEY: ${{ secrets.API_KEY }}
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --no-root
poetry run python -m unittest discover tests
15 changes: 1 addition & 14 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Testing Synchronous and Asynchronous Extraction"""

import os
import random
import sys
import time
import unittest

from any_parser import AnyParser
Expand All @@ -16,11 +14,6 @@
class TestAnyParser(unittest.TestCase):
"""Testing Any Parser"""

@classmethod
def setUpClass(cls):
# Add a random delay between 0 and 10 seconds at the start of each test suite
time.sleep(random.uniform(0, 20))

def setUp(self):
# get secret API key
self.api_key = os.environ.get("API_KEY")
Expand All @@ -32,11 +25,9 @@ def setUp(self):

def test_sync_extract(self):
"""Synchronous Extraction"""
# Add a delay before making the API call
time.sleep(random.uniform(1, 5))
md_output, total_time = self.ap.extract(self.file_path)

# check for specific content in the markdown
md_output, total_time = self.ap.extract(self.file_path)
self.assertFalse(md_output.startswith("Error:"), total_time)
self.assertTrue(
md_output.startswith("STOXX INDEX METHODOLOGY GUIDE"),
Expand All @@ -50,16 +41,12 @@ def test_async_extract_and_fetch(self):
"""Asynchronous Extraction and Fetch"""

# check for error in sending extraction request
# Add a delay before making the API call
time.sleep(random.uniform(1, 5))
file_id = self.ap.async_extract(self.file_path)
self.assertFalse(file_id.startswith("Error:"), file_id)
self.assertFalse(file_id.startswith("Request error:"), file_id)
self.assertFalse(file_id.startswith("Upload error:"), file_id)

# check for specific content in extraction result
# Add another delay before fetching
time.sleep(random.uniform(1, 5))
md = self.ap.async_fetch(file_id=file_id)
self.assertFalse(md.startswith("Error:"), md)
self.assertTrue(
Expand Down

0 comments on commit f70ef33

Please sign in to comment.