Skip to content

Commit

Permalink
improve automated test code coverage and github action
Browse files Browse the repository at this point in the history
  • Loading branch information
amor71 committed Jun 26, 2022
1 parent 6d46a97 commit 79ef6e4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Codecov Workflow

on: [push, pull_request]

env:
TEST_API_SECRET: ${{ secrets.TEST_API_SECRET }}
TEST_API_CLIENT_ID: ${{ secrets.TEST_API_CLIENT_ID }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -17,6 +21,6 @@ jobs:
- name: Install requirements
run: pip install -r finrashortdata/requirements/dev.txt
- name: Run tests and collect coverage
run: pytest --cov --co --cov-config=.coveragerc .
run: pytest --cov --cov-config=.coveragerc .
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion finrashortdata/equity.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def process(
max_records = min(max_records, limit)

print(
f"loading data (chunk_size={chunk_size}, max_records={max_records-offset})..."
f"loading data (chunk_size={chunk_size}, offset={offset}, max_records={max_records-offset})..."
)
with concurrent.futures.ThreadPoolExecutor() as executor:
loop = asyncio.get_event_loop()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest
from requests.exceptions import HTTPError

from finrashortdata import auth

Expand All @@ -21,6 +22,15 @@ def test_auth_positive() -> bool:
return True


def test_auth_negative() -> bool:
try:
auth("some in correct stuff", "lead to error")
except HTTPError:
return True

raise AssertionError("Excepted HTTPError")


def test_auth_no_type() -> bool:
try:
auth() # type: ignore
Expand Down
20 changes: 17 additions & 3 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ async def test_process_positive() -> bool:
)
token = auth(client_id, secret)
chunk, max_data = get_chunk_and_size(token)
_df: pd.DataFrame = await process(
token=token, offset=max_data - 10 * chunk
)
_df: pd.DataFrame = await process(token=token, offset=max_data - chunk)
print(_df)

return True


async def test_process_positive_limit() -> bool:
client_id = os.getenv("TEST_API_CLIENT_ID", None)
secret = os.getenv("TEST_API_SECRET", None)

if not client_id or not secret:
raise AssertionError(
"tests require env variables TEST_API_CLIENT_ID, TEST_API_SECRET"
)
token = auth(client_id, secret)
chunk, max_data = get_chunk_and_size(token)
_df: pd.DataFrame = await process(token=token, offset=0, limit=chunk)
print(_df)

return True

0 comments on commit 79ef6e4

Please sign in to comment.