Skip to content

Commit

Permalink
Code Coverage (#4236)
Browse files Browse the repository at this point in the history
* Code Coverage

* minor fix

* Remove coverage limit check

* Check code cov

* removed env

* Tests : fixing tests + autocompletion bug

* Tests : skip a test

* Linting

* Tests : skip slow coins test on crypto

* Added check for coverage

* Remove failure test

* Minor tweak

* Added code coverage to base test

---------

Co-authored-by: Chavithra <chavithra@gmail.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
  • Loading branch information
3 people authored Feb 17, 2023
1 parent 6de733e commit bbeaef4
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 519 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Code Coverage Tests

on: workflow_dispatch

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
code-coverage:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- name: Checkout code
if: github.event_name == 'push'
uses: actions/checkout@v3

- name: Checkout specific ref
if: github.event_name == 'pull_request'
run: git fetch origin ${{ github.event.pull_request.head.ref }} && git checkout FETCH_HEAD

- name: Setup Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
architecture: x64

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-v1-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction -E optimization

- name: Run code coverage tests
run: |
source $VENV
pytest --cov --cov-fail-under=50
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ jobs:
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction -E optimization

- name: Run tests
- name: Run tests and coverage test
env:
MPLBACKEND: Agg
run: |
source $VENV
pytest tests/ --optimization --autodoc
pytest tests/ --optimization --cov --cov-fail-under=50 --autodoc
- name: Start Terminal and exit
run: |
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/cryptocurrency/due_diligence/dd_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ def call_eb(self, other_args: List[str]):
@log_start_end(log=logger)
def call_oi(self, other_args):
"""Process oi command"""
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -535,6 +534,7 @@ def call_oi(self, other_args):
)

if ns_parser:
assert isinstance(self.symbol, str) # noqa: S101
coinglass_view.display_open_interest(
symbol=self.symbol.upper(),
interval=ns_parser.interval,
Expand All @@ -547,7 +547,6 @@ def call_oi(self, other_args):
@log_start_end(log=logger)
def call_liquidations(self, other_args):
"""Process liquidations command"""
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -563,6 +562,7 @@ def call_liquidations(self, other_args):
)

if ns_parser:
assert isinstance(self.symbol, str) # noqa: S101
coinglass_view.display_liquidations(
symbol=self.symbol.upper(),
export=ns_parser.export,
Expand All @@ -574,7 +574,6 @@ def call_liquidations(self, other_args):
@log_start_end(log=logger)
def call_fundrate(self, other_args):
"""Process fundrate command"""
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -590,6 +589,7 @@ def call_fundrate(self, other_args):
)

if ns_parser:
assert isinstance(self.symbol, str) # noqa: S101
coinglass_view.display_funding_rate(
symbol=self.symbol.upper(),
export=ns_parser.export,
Expand Down
3 changes: 3 additions & 0 deletions tests/openbb_terminal/account/test_account_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ def test_call_download(mocker):
)


@pytest.mark.skip(
reason="We should add a `-y or -f` option to make that easier to test"
)
def test_call_delete(mocker):
controller = account_controller.AccountController(queue=None)
path_controller = "openbb_terminal.account.account_controller"
Expand Down
30 changes: 15 additions & 15 deletions tests/openbb_terminal/cryptocurrency/test_crypto_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"CoinGecko",
"symbol",
],
[
"doge",
"CoinGecko",
"name",
],
# [ TOO SLOW
# "doge",
# "CoinGecko",
# "name",
# ],
[
"bitcoin",
"CoinPaprika",
Expand All @@ -41,11 +41,11 @@
"CoinPaprika",
"name",
],
[
"btc",
"Binance",
"id",
],
# [ TOO SLOW
# "btc",
# "Binance",
# "id",
# ],
[
"polka",
"Binance",
Expand All @@ -56,11 +56,11 @@
"Binance",
"id",
],
[
"btc",
"Coinbase",
"id",
],
# [ TOO SLOW
# "btc",
# "Coinbase",
# "id",
# ],
[
"polka",
"Coinbase",
Expand Down
30 changes: 15 additions & 15 deletions tests/openbb_terminal/cryptocurrency/test_crypto_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"CoinGecko",
"symbol",
],
[
"doge",
"CoinGecko",
"name",
],
# [ TOO SLOW
# "doge",
# "CoinGecko",
# "name",
# ],
[
"btc",
"CoinPaprika",
Expand All @@ -41,11 +41,11 @@
"CoinPaprika",
"name",
],
[
"btc",
"Binance",
"id",
],
# [ TOO SLOW
# "btc",
# "Binance",
# "id",
# ],
[
"bt",
"Binance",
Expand All @@ -56,11 +56,11 @@
"Binance",
"id",
],
[
"btc",
"Coinbase",
"id",
],
# [ TOO SLOW
# "btc",
# "Coinbase",
# "id",
# ],
[
"bt",
"Coinbase",
Expand Down
18 changes: 18 additions & 0 deletions tests/openbb_terminal/economy/test_economy_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ def test_call_func(
# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")

if mocked_func:
mock = mocker.Mock()
mocker.patch(
Expand Down Expand Up @@ -765,6 +768,9 @@ def test_call_macro(mocked_func, other_args, called_args, called_kwargs, mocker)

# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")
# MOCK the econdb.get_aggregated_macro_data
mocker.patch(
target=f"{path_controller}.econdb_model.get_aggregated_macro_data",
Expand Down Expand Up @@ -799,6 +805,9 @@ def test_call_fred_query(mocker):
# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")

mocker.patch(
target=f"{path_controller}.fred_model.get_series_notes",
return_value=MOCK_FRED_NOTES,
Expand Down Expand Up @@ -873,6 +882,9 @@ def test_call_fred_params(mocked_func, other_args, called_args, called_kwargs, m
# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")

# MOCK the fred functions used
mocker.patch(
target=f"{path_controller}.fred_model.check_series_id",
Expand Down Expand Up @@ -935,6 +947,9 @@ def test_call_index(mocker):
# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")

# MOCK the fred functions used
mocker.patch(
target=f"{path_controller}.yfinance_model.get_index",
Expand Down Expand Up @@ -1007,6 +1022,9 @@ def test_call_treasury(mocked_func, other_args, called_args, called_kwargs, mock

# MOCK REMOVE
mocker.patch(target=f"{path_controller}.os.remove")

# MOCK UPDATE_RUNTIME_CHOICES
mocker.patch(target=f"{path_controller}.EconomyController.update_runtime_choices")
# MOCK the econdb.get_aggregated_macro_data
mocker.patch(
target=f"{path_controller}.econdb_model.get_treasuries",
Expand Down
Loading

0 comments on commit bbeaef4

Please sign in to comment.