Skip to content

Commit

Permalink
Merge pull request #14 from LiaoU3/codecov
Browse files Browse the repository at this point in the history
Add code coverage test when PR submitted
  • Loading branch information
LiaoU3 authored Jul 21, 2024
2 parents 7a56e69 + 277231f commit 9b90980
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit =
tests/*
46 changes: 46 additions & 0 deletions .github/workflows/code_coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Code Coverage

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install coverage
- name: Run tests with coverage
run: |
coverage erase
coverage run -m unittest discover -s tests
result=$(coverage report -m)
result_with_backticks="\`\`\`\n$result"
echo "$result_with_backticks" > coverage_report.txt
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
filePath: coverage_report.txt
3 changes: 3 additions & 0 deletions tests/test_future_market_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def setUp(self):
close_dates = ["2024-04-17"] # Assume 2024/04-17 is close
fmt.init_close_date_set(close_dates)

def tearDown(self):
fmt.close_date_set = set()

def test__third_wednesday(self):
third_wednesday = fmt._third_wednesday(2024, 4)
self.assertEqual(third_wednesday, datetime(2024, 4, 17).date())
Expand Down
3 changes: 3 additions & 0 deletions tests/test_market_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def setUp(self):
close_dates = ["2024-04-04", "2024-04-05"]
mt.init_close_date_set(close_dates)

def tearDown(self):
mt.close_date_set = set()

def test_init_close_date_set(self):
self.assertTrue(
datetime(2024, 4, 4).date() in mt.close_date_set
Expand Down

0 comments on commit 9b90980

Please sign in to comment.