Tests : controllers (#1290)

* Updating tests : cryptocurrency/due_diligence

* Updating tests : etf

* Updating tests : crypto

* Updating tests : cryptocurrency/due_diligence

* Updating tests : cryptocurrency/due_diligence/controller

* Updating tests : alternative/controller

* Updating tests : cryptocurrency/controller

* Updating tests : cryptocurrency/nft/controller

* Updating tests : cryptocurrency/due_diligence/controller

* Updating tests : cryptocurrency/onchain/controller

* Updating tests : alternative/controller

* Updating tests : cryptocurrency/due_diligence/controller

* Updating tests : cryptocurrency/controller

* Updating tests : alternative/covid/controller

* Updating tests : alternative/controller

* Updating tests : cryptocurrency/nft/controller

* Updating tests : cryptocurrency/onchain/controller

* Updating tests : cryptocurrency/overview/controller

* Updating tests : portfolio/portfolio_optimization

* Updating tests : portfolio/portfolio_analysis/controller

* Updating tests : portfolio/portfolio_optimization/controller

* Updating tests : portfolio/controller

* Updating tests : cryptocurrency/controller

* Updating tests : controllers

* Updating code : black

* Revert "Updating code : black"

This reverts commit b555c332a1.
This commit is contained in:
Chavithra
2022-01-30 18:24:50 +01:00
committed by GitHub
parent c2ba724b66
commit 51f43879d3
56 changed files with 9849 additions and 80 deletions

View File

@@ -0,0 +1,252 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.alternative.covid import covid_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.alternative.covid.covid_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.CovidController.switch",
return_value=["quit"],
)
result_menu = covid_controller.CovidController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.alternative.covid.covid_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=covid_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = covid_controller.CovidController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.alternative.covid.covid_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=covid_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.CovidController.switch",
new=mock_switch,
)
result_menu = covid_controller.CovidController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = covid_controller.CovidController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "alternative", "covid", "country US"],
),
],
)
def test_switch(an_input, expected_queue):
controller = covid_controller.CovidController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = covid_controller.CovidController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "alternative", "covid", "country US"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "alternative", "covid", "country US", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = covid_controller.CovidController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_country",
["US"],
"",
[],
dict(),
),
(
"call_rates",
[],
"covid_view.display_covid_stat",
[],
dict(),
),
(
"call_deaths",
[],
"covid_view.display_covid_stat",
[],
dict(),
),
(
"call_cases",
[],
"covid_view.display_covid_stat",
[],
dict(),
),
(
"call_slopes",
[],
"covid_view.display_country_slopes",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.alternative.covid.covid_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = covid_controller.CovidController(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = covid_controller.CovidController(queue=None)
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,11 @@
slopes get countries with highest slope in cases
country select country for data
Country: US
ov get overview (cases and deaths) for selected country
deaths get deaths for selected country
cases get cases for selected country
rates get death/cases rate for selected country

View File

@@ -0,0 +1,224 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.alternative import alt_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.alternative.alt_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.AlternativeDataController.switch",
return_value=["quit"],
)
result_menu = alt_controller.AlternativeDataController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.alternative.alt_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=alt_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = alt_controller.AlternativeDataController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.alternative.alt_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=alt_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.AlternativeDataController.switch",
new=mock_switch,
)
result_menu = alt_controller.AlternativeDataController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = alt_controller.AlternativeDataController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "reset", "alternative"],
),
],
)
def test_switch(an_input, expected_queue):
controller = alt_controller.AlternativeDataController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = alt_controller.AlternativeDataController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "help"]),
("call_home", [], ["quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "reset", "alternative"],
),
(
"call_reset",
["help"],
["quit", "reset", "alternative", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = alt_controller.AlternativeDataController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_covid",
[],
"AlternativeDataController.load_class",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.alternative.alt_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = alt_controller.AlternativeDataController(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = alt_controller.AlternativeDataController(queue=None)
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,3 @@
> covid COVID menu, e.g.: cases, deaths, rates

File diff suppressed because it is too large Load Diff

View File

@@ -1,39 +0,0 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.26.0
method: GET
uri: https://api.glassnode.com/v1/metrics/addresses/active_count?api_key=REPLACE_ME&a=BTC&i=24h&s=1605675600&u=1637211600
response:
body:
string: "<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body>\r\n<center><h1>401
Authorization Required</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Origin:
- https://studio.glassnode.com
Access-Control-Expose-Headers:
- X-Glassnode-Code
Connection:
- keep-alive
Content-Length:
- '172'
Content-Type:
- text/html
Date:
- Thu, 18 Nov 2021 16:47:40 GMT
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
status:
code: 401
message: Unauthorized
version: 1

View File

@@ -1,35 +1,448 @@
""" crpytocurrency/due_diligence/dd_controller.py tests """
import unittest
# IMPORTATION STANDARD
import os
import vcr
# IMPORTATION THIRDPARTY
import pandas as pd
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.cryptocurrency.due_diligence import dd_controller
from tests.helpers.helpers import check_print
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
pytest.skip(allow_module_level=True)
COIN_MAP_DF = pd.Series(
data={
"CoinGecko": "bitcoin",
"CoinPaprika": "btc-bitcoin",
"Binance": "BTC",
"Coinbase": "BTC",
}
)
CURRENT_COIN = "bitcoin"
SYMBOL = "BTC"
BINANCE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL = (
"BTC",
[
"USDT",
"TUSD",
"USDC",
"BUSD",
"NGN",
"RUB",
"TRY",
"EUR",
"GBP",
"UAH",
"BIDR",
"AUD",
"DAI",
"BRL",
"USDP",
],
)
COINBASE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL = (
"BTC",
["GBP", "USD", "EUR", "USDC", "UST", "USDT"],
)
class TestDDController(unittest.TestCase):
def setUp(self):
self.cont = dd_controller.DueDiligenceController(source="cp", symbol="BTC")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.cryptocurrency.due_diligence.dd_controller"
@check_print(assert_in="Due Diligence:")
def test_help(self):
self.cont.call_help(None)
@check_print(assert_in="Moving back to")
def test_q(self):
self.cont.call_quit(None)
def test_quit(self):
self.assertTrue(self.cont.call_quit(None))
@vcr.use_cassette(
"tests/gamestonk_terminal/cryptocurrency/due_diligence/cassettes/test_dd_controller/test_dd_controller.yaml",
record_mode="once",
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.DueDiligenceController.switch",
return_value=["quit"],
)
@check_print(assert_in="glassnode")
def test_active(self):
self.cont.call_active(None)
result_menu = dd_controller.DueDiligenceController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.cryptocurrency.due_diligence.dd_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=dd_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = dd_controller.DueDiligenceController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.cryptocurrency.due_diligence.dd_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=dd_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.DueDiligenceController.switch",
new=mock_switch,
)
result_menu = dd_controller.DueDiligenceController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = dd_controller.DueDiligenceController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "crypto", "dd"],
),
],
)
def test_switch(an_input, expected_queue):
controller = dd_controller.DueDiligenceController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = dd_controller.DueDiligenceController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "crypto", "dd"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "crypto", "dd", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = dd_controller.DueDiligenceController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_nonzero",
[],
"glassnode_view.display_non_zero_addresses",
[],
dict(),
),
(
"call_active",
[],
"glassnode_view.display_active_addresses",
[],
dict(),
),
(
"call_change",
["binance"],
"glassnode_view.display_exchange_net_position_change",
[],
dict(),
),
(
"call_eb",
[],
"glassnode_view.display_exchange_balances",
[],
dict(),
),
(
"call_oi",
[],
"coinglass_view.display_open_interest",
[],
dict(),
),
(
"call_info",
[],
"pycoingecko_view.display_info",
[],
dict(),
),
(
"call_market",
[],
"pycoingecko_view.display_market",
[],
dict(),
),
(
"call_web",
[],
"pycoingecko_view.display_web",
[],
dict(),
),
(
"call_dev",
[],
"pycoingecko_view.display_dev",
[],
dict(),
),
(
"call_ath",
[],
"pycoingecko_view.display_ath",
[],
dict(),
),
(
"call_atl",
[],
"pycoingecko_view.display_atl",
[],
dict(),
),
(
"call_score",
[],
"pycoingecko_view.display_score",
[],
dict(),
),
(
"call_bc",
[],
"pycoingecko_view.display_bc",
[],
dict(),
),
(
"call_book",
[],
"binance_view.display_order_book",
[],
dict(),
),
(
"call_cbbook",
[],
"coinbase_view.display_order_book",
[],
dict(),
),
(
"call_balance",
[],
"binance_view.display_balance",
[],
dict(),
),
(
"call_trades",
[],
"coinbase_view.display_trades",
[],
dict(),
),
(
"call_stats",
[],
"coinbase_view.display_stats",
[],
dict(),
),
(
"call_ps",
[],
"coinpaprika_view.display_price_supply",
[],
dict(),
),
(
"call_basic",
[],
"coinpaprika_view.display_basic",
[],
dict(),
),
(
"call_mkt",
[],
"coinpaprika_view.display_markets",
[],
dict(),
),
(
"call_ex",
[],
"coinpaprika_view.display_exchanges",
[],
dict(),
),
(
"call_events",
[],
"coinpaprika_view.display_events",
[],
dict(),
),
(
"call_twitter",
[],
"coinpaprika_view.display_twitter",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.cryptocurrency.due_diligence.dd_controller"
# MOCK SHOW_AVAILABLE_PAIRS_FOR_GIVEN_SYMBOL
mocker.patch(
target=f"{path_controller}.binance_model.show_available_pairs_for_given_symbol",
return_value=BINANCE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL,
)
# MOCK SHOW_AVAILABLE_PAIRS_FOR_GIVEN_SYMBOL
mocker.patch(
target=f"{path_controller}.coinbase_model.show_available_pairs_for_given_symbol",
return_value=COINBASE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL,
)
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = dd_controller.DueDiligenceController()
controller.coin_map_df = COIN_MAP_DF
controller.current_coin = CURRENT_COIN
controller.symbol = SYMBOL
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = dd_controller.DueDiligenceController()
controller.coin_map_df = COIN_MAP_DF
controller.current_coin = CURRENT_COIN
controller.symbol = SYMBOL
getattr(controller, tested_func)(other_args)
@pytest.mark.vcr
@pytest.mark.record_stdout
def test_call_load():
controller = dd_controller.DueDiligenceController()
other_args = [SYMBOL]
controller.call_load(other_args=other_args)

View File

@@ -0,0 +1,11 @@
# IMPORTATION STANDARD
# IMPORTATION THIRDPARTY
# IMPORTATION INTERNAL
from gamestonk_terminal.helper_classes import ModelsNamespace as _models
from gamestonk_terminal.cryptocurrency.due_diligence import due_diligence_api
def test_models():
assert isinstance(due_diligence_api.models, _models)

View File

@@ -0,0 +1,3 @@
Loaded bitcoin from source cg

View File

@@ -0,0 +1,38 @@
load load a specific cryptocurrency for analysis
Coin: None
Source: ?
Glassnode
active active addresses
nonzero addresses with non-zero balances
change 30d change of supply held on exchange wallets
eb total balance held on exchanges (in percentage and units)
Coinglass
oi open interest per exchange
CoinPaprika
basic basic information about loaded coin
ps price and supply related metrics for loaded coin
mkt all markets for loaded coin
ex all exchanges where loaded coin is listed
twitter tweets for loaded coin
events events related to loaded coin
CoinGecko
info basic information about loaded coin
market market stats about loaded coin
ath all time high related stats for loaded coin
atl all time low related stats for loaded coin
web found websites for loaded coin e.g forum, homepage
social social portals urls for loaded coin, e.g reddit, twitter
score different kind of scores for loaded coin, e.g developer score, sentiment score
dev github, bitbucket coin development statistics
bc links to blockchain explorers for loaded coin
Binance
binbook show order book
balance show coin balance
Coinbase
cbbook show order book
trades show last trades
stats show coin stats

View File

@@ -0,0 +1,252 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.cryptocurrency.nft import nft_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.cryptocurrency.nft.nft_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.NFTController.switch",
return_value=["quit"],
)
result_menu = nft_controller.NFTController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.cryptocurrency.nft.nft_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=nft_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = nft_controller.NFTController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.cryptocurrency.nft.nft_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=nft_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.NFTController.switch",
new=mock_switch,
)
result_menu = nft_controller.NFTController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = nft_controller.NFTController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "crypto", "nft"],
),
],
)
def test_switch(an_input, expected_queue):
controller = nft_controller.NFTController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = nft_controller.NFTController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "crypto", "nft"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "crypto", "nft", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = nft_controller.NFTController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_stats",
["mutant-ape-yacht-club"],
"opensea_view.display_collection_stats",
[],
dict(),
),
(
"call_today",
[],
"nftcalendar_view.display_nft_today_drops",
[],
dict(),
),
(
"call_upcoming",
[],
"nftcalendar_view.display_nft_upcoming_drops",
[],
dict(),
),
(
"call_ongoing",
[],
"nftcalendar_view.display_nft_ongoing_drops",
[],
dict(),
),
(
"call_newest",
[],
"nftcalendar_view.display_nft_newest_drops",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.cryptocurrency.nft.nft_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = nft_controller.NFTController(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = nft_controller.NFTController(queue=None)
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,9 @@
[Nftcalendar.io]
today today's NFT drops
upcoming upcoming NFT drops
ongoing Ongoing NFT drops
newest Recently NFTs added
[Opensea.io]
stats check open sea collection stats

View File

@@ -0,0 +1,382 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.cryptocurrency.onchain import onchain_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.cryptocurrency.onchain.onchain_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.OnchainController.switch",
return_value=["quit"],
)
result_menu = onchain_controller.OnchainController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.cryptocurrency.onchain.onchain_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=onchain_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = onchain_controller.OnchainController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.cryptocurrency.onchain.onchain_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=onchain_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.OnchainController.switch",
new=mock_switch,
)
result_menu = onchain_controller.OnchainController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = onchain_controller.OnchainController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "crypto", "onchain"],
),
],
)
def test_switch(an_input, expected_queue):
controller = onchain_controller.OnchainController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = onchain_controller.OnchainController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "crypto", "onchain"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "crypto", "onchain", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = onchain_controller.OnchainController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_btcct",
[],
"blockchain_view.display_btc_confirmed_transactions",
[],
dict(),
),
(
"call_btccp",
[],
"blockchain_view.display_btc_circulating_supply",
[],
dict(),
),
(
"call_hr",
["BTC"],
"display_hashrate",
[],
dict(),
),
(
"call_gwei",
[],
"ethgasstation_view.display_gwei_fees",
[],
dict(),
),
(
"call_whales",
[],
"whale_alert_view.display_whales_transactions",
[],
dict(),
),
(
"call_address",
["0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", "-t"],
"",
[],
dict(),
),
(
"call_address",
["MOCK_WRONG_ADDRESS", "-t"],
"",
[],
dict(),
),
(
"call_balance",
[],
"ethplorer_view.display_address_info",
[],
dict(),
),
(
"call_hist",
[],
"ethplorer_view.display_address_history",
[],
dict(),
),
(
"call_holders",
[],
"ethplorer_view.display_top_token_holders",
[],
dict(),
),
(
"call_top",
[],
"ethplorer_view.display_top_tokens",
[],
dict(),
),
(
"call_info",
[],
"ethplorer_view.display_token_info",
[],
dict(),
),
(
"call_th",
[],
"ethplorer_view.display_token_history",
[],
dict(),
),
(
"call_tx",
[],
"ethplorer_view.display_tx_info",
[],
dict(),
),
(
"call_prices",
[],
"ethplorer_view.display_token_historical_prices",
[],
dict(),
),
(
"call_lt",
[],
"bitquery_view.display_dex_trades",
[],
dict(),
),
(
"call_dvcp",
["BTC"],
"bitquery_view.display_daily_volume_for_given_pair",
[],
dict(),
),
(
"call_tv",
["BTC"],
"bitquery_view.display_dex_volume_for_token",
[],
dict(),
),
(
"call_ueat",
[],
"bitquery_view.display_ethereum_unique_senders",
[],
dict(),
),
(
"call_ttcp",
["Balancer"],
"bitquery_view.display_most_traded_pairs",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.cryptocurrency.onchain.onchain_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = onchain_controller.OnchainController(queue=None)
controller.address = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
controller.address_type = "token"
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = onchain_controller.OnchainController(queue=None)
controller.address = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
controller.address_type = "token"
getattr(controller, tested_func)(other_args)
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func",
[
"call_balance",
"call_hist",
"call_holders",
"call_info",
"call_th",
"call_tx",
"call_prices",
],
)
def test_call_func_no_address(tested_func):
controller = onchain_controller.OnchainController(queue=None)
controller.address = ""
getattr(controller, tested_func)([])

View File

@@ -0,0 +1,32 @@
[Glassnode]
hr check blockchain hashrate over time (BTC or ETH)
[Blockchain]
btccp displays BTC circulating supply
btcct displays BTC confirmed transactions
[Eth Gas Station]
gwei check current eth gas fees
[Whale Alert]
whales check crypto wales transactions
[BitQuery]
lt last trades by dex or month
dvcp daily volume for crypto pair
tv token volume on DEXes
ueat unique ethereum addresses which made a transaction
ttcp top traded crypto pairs on given decentralized exchange
baas bid, ask prices, average spread for given crypto pair
Ethereum address:
Address type:
[Ethplorer] Ethereum:
address load ethereum address of token, account or transaction
top top ERC20 tokens[unvl]
balance check ethereum balance
hist ethereum balance history (transactions)[unvl][unvl]
info ERC20 token info
holders top ERC20 token holders
th ERC20 token history
prices ERC20 token historical prices[unvl][unvl]
tx ethereum blockchain transaction info[unvl]

View File

@@ -0,0 +1,452 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pandas as pd
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.cryptocurrency.overview import overview_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
GET_ALL_CONTRACT_PLATFORMS_DF = pd.DataFrame(
data={
"index": {
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6,
6: 7,
7: 8,
8: 9,
9: 10,
10: 11,
11: 12,
12: 13,
13: 14,
14: 15,
15: 16,
16: 17,
17: 18,
18: 19,
19: 20,
20: 21,
21: 22,
22: 23,
23: 24,
24: 25,
25: 26,
26: 27,
27: 28,
28: 29,
29: 30,
30: 31,
31: 32,
32: 33,
33: 34,
34: 35,
35: 36,
36: 37,
},
"platform_id": {
0: "btc-bitcoin",
1: "eos-eos",
2: "eth-ethereum",
3: "xrp-xrp",
4: "bch-bitcoin-cash",
5: "xem-nem",
6: "neo-neo",
7: "xlm-stellar",
8: "etc-ethereum-classic",
9: "qtum-qtum",
10: "zec-zcash",
11: "vet-vechain",
12: "bts-bitshares",
13: "waves-waves",
14: "nxt-nxt",
15: "act-achain",
16: "ubq-ubiq",
17: "xcp-counterparty",
18: "html-htmlcoin",
19: "etp-metaverse-etp",
20: "signa-signa",
21: "omni-omni",
22: "trx-tron",
23: "bnb-binance-coin",
24: "ardr-ardor",
25: "ht-huobi-token",
26: "blvr-believer",
27: "cake-pancakeswap",
28: "fsxu-flashx-ultra",
29: "chik-chickenkebab-finance",
30: "jgn-juggernaut7492",
31: "crx-cryptex",
32: "whirl-whirl-finance",
33: "eubi-eubi-token",
34: "swam-swapmatic-token",
35: "shells-shells",
36: "slx-solex-finance",
},
}
)
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.cryptocurrency.overview.overview_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.OverviewController.switch",
return_value=["quit"],
)
result_menu = overview_controller.OverviewController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.cryptocurrency.overview.overview_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=overview_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.OverviewController.switch",
new=mock_switch,
)
result_menu = overview_controller.OverviewController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = overview_controller.OverviewController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "crypto", "ov"],
),
],
)
def test_switch(an_input, expected_queue):
controller = overview_controller.OverviewController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = overview_controller.OverviewController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "crypto", "ov"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "crypto", "ov", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = overview_controller.OverviewController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_cgglobal",
[],
"pycoingecko_view.display_global_market_info",
[],
dict(),
),
(
"call_cgdefi",
[],
"pycoingecko_view.display_global_defi_info",
[],
dict(),
),
(
"call_cgstables",
[],
"pycoingecko_view.display_stablecoins",
[],
dict(),
),
(
"call_cgexchanges",
[],
"pycoingecko_view.display_exchanges",
[],
dict(),
),
(
"call_cgexrates",
[],
"pycoingecko_view.display_exchange_rates",
[],
dict(),
),
(
"call_cgplatforms",
[],
"pycoingecko_view.display_platforms",
[],
dict(),
),
(
"call_cgproducts",
[],
"pycoingecko_view.display_products",
[],
dict(),
),
(
"call_cgindexes",
[],
"pycoingecko_view.display_indexes",
[],
dict(),
),
(
"call_cgderivatives",
[],
"pycoingecko_view.display_derivatives",
[],
dict(),
),
(
"call_cgcategories",
[],
"pycoingecko_view.display_categories",
[],
dict(),
),
(
"call_cghold",
[],
"pycoingecko_view.display_holdings_overview",
[],
dict(),
),
(
"call_cpglobal",
[],
"coinpaprika_view.display_global_market",
[],
dict(),
),
(
"call_cpmarkets",
[],
"coinpaprika_view.display_all_coins_market_info",
[],
dict(),
),
(
"call_cpexmarkets",
["binance"],
"coinpaprika_view.display_exchange_markets",
[],
dict(),
),
(
"call_cpinfo",
[],
"coinpaprika_view.display_all_coins_info",
[],
dict(),
),
(
"call_cpexchanges",
[],
"coinpaprika_view.display_all_exchanges",
[],
dict(),
),
(
"call_cpplatforms",
[],
"coinpaprika_view.display_all_platforms",
[],
dict(),
),
(
"call_cpcontracts",
["eth-ethereum"],
"coinpaprika_view.display_contracts",
[],
dict(),
),
(
"call_cbpairs",
[],
"coinbase_view.display_trading_pairs",
[],
dict(),
),
(
"call_news",
[],
"cryptopanic_view.display_news",
[],
dict(),
),
(
"call_wf",
[],
"withdrawalfees_view.display_overall_withdrawal_fees",
[],
dict(),
),
(
"call_ewf",
[],
"withdrawalfees_view.display_overall_exchange_withdrawal_fees",
[],
dict(),
),
(
"call_btcrb",
[],
"display_btc_rainbow",
[],
dict(),
),
(
"call_altindex",
[],
"blockchaincenter_view.display_altcoin_index",
[],
dict(),
),
(
"call_ch",
[],
"rekt_view.display_crypto_hacks",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.cryptocurrency.overview.overview_controller"
# MOCK GET_ALL_CONTRACT_PLATFORMS
mocker.patch(
target=f"{path_controller}.get_all_contract_platforms",
return_value=GET_ALL_CONTRACT_PLATFORMS_DF,
)
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = overview_controller.OverviewController(queue=None)
controller.address = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
controller.address_type = "token"
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = overview_controller.OverviewController(queue=None)
controller.address = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"
controller.address_type = "token"
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,35 @@
[CoinGecko]
cgglobal global crypto market info
cgdefi global DeFi market info
cgstables stablecoins
cgexchanges top crypto exchanges
cgexrates coin exchange rates
cgplatforms crypto financial platforms
cgproducts crypto financial products
cgindexes crypto indexes
cgderivatives crypto derivatives
cgcategories crypto categories
cghold ethereum, bitcoin holdings overview statistics
[CoinPaprika]
cpglobal global crypto market info
cpinfo basic info about all coins available
cpmarkets market related info about all coins available
cpexchanges list all exchanges
cpexmarkets all available markets on given exchange
cpplatforms list blockchain platforms eg. ethereum, solana, kusama, terra
cpcontracts all smart contracts for given platform
[Coinbase]
cbpairs info about available trading pairs
[CryptoPanic]
news recent crypto news
[WithdrawalFees]
wf overall withdrawal fees
ewf overall exchange withdrawal fees
wfpe crypto withdrawal fees per exchange
[BlockchainCenter]
altindex display altcoin season index (if 75% of top 50 coins perform better than BTC)
btcrb display bitcoin rainbow price chart (logarithmic regression)
[Rekt]
ch lists major crypto-related hacks

View File

@@ -0,0 +1,16 @@
# IMPORTATION STANDARD
# IMPORTATION THIRDPARTY
# IMPORTATION INTERNAL
from gamestonk_terminal.helper_classes import ModelsNamespace as _models
from gamestonk_terminal.cryptocurrency import crypto_api
def test_models():
assert isinstance(crypto_api.defi.models, _models)
assert isinstance(crypto_api.disc.models, _models)
assert isinstance(crypto_api.dd.models, _models)
assert isinstance(crypto_api.nft.models, _models)
assert isinstance(crypto_api.onchain.models, _models)
assert isinstance(crypto_api.ov.models, _models)

View File

@@ -0,0 +1,354 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pandas as pd
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.cryptocurrency import crypto_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
COIN_MAP_DF = pd.Series(
data={
"CoinGecko": "bitcoin",
"CoinPaprika": "btc-bitcoin",
"Binance": "BTC",
"Coinbase": "BTC",
}
)
CURRENT_COIN = "bitcoin"
SYMBOL = "BTC"
BINANCE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL = (
"BTC",
[
"USDT",
"TUSD",
"USDC",
"BUSD",
"NGN",
"RUB",
"TRY",
"EUR",
"GBP",
"UAH",
"BIDR",
"AUD",
"DAI",
"BRL",
"USDP",
],
)
COINBASE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL = (
"BTC",
["GBP", "USD", "EUR", "USDC", "UST", "USDT"],
)
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.cryptocurrency.crypto_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.CryptoController.switch",
return_value=["quit"],
)
result_menu = crypto_controller.CryptoController(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.cryptocurrency.crypto_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=crypto_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = crypto_controller.CryptoController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.cryptocurrency.crypto_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=crypto_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.CryptoController.switch",
new=mock_switch,
)
result_menu = crypto_controller.CryptoController(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = crypto_controller.CryptoController(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "reset", "crypto"],
),
],
)
def test_switch(an_input, expected_queue):
controller = crypto_controller.CryptoController(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = crypto_controller.CryptoController(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "help"]),
("call_home", [], ["quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "reset", "crypto"],
),
(
"call_reset",
["help"],
["quit", "reset", "crypto", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = crypto_controller.CryptoController(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_prt",
["eth"],
"pycoingecko_view.display_coin_potential_returns",
[],
dict(),
),
(
"call_disc",
[],
"CryptoController.load_class",
[],
dict(),
),
(
"call_ov",
[],
"CryptoController.load_class",
[],
dict(),
),
(
"call_defi",
[],
"CryptoController.load_class",
[],
dict(),
),
(
"call_headlines",
[],
"finbrain_crypto_view.display_crypto_sentiment_analysis",
[],
dict(),
),
(
"call_dd",
[],
"CryptoController.load_class",
[],
dict(),
),
(
"call_onchain",
[],
"CryptoController.load_class",
[],
dict(),
),
(
"call_nft",
[],
"CryptoController.load_class",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.cryptocurrency.crypto_controller"
# MOCK SHOW_AVAILABLE_PAIRS_FOR_GIVEN_SYMBOL
mocker.patch(
target=f"{path_controller}.binance_model.show_available_pairs_for_given_symbol",
return_value=BINANCE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL,
)
# MOCK SHOW_AVAILABLE_PAIRS_FOR_GIVEN_SYMBOL
mocker.patch(
target=f"{path_controller}.coinbase_model.show_available_pairs_for_given_symbol",
return_value=COINBASE_SHOW_AVAILABLE_PAIRS_OF_GIVEN_SYMBOL,
)
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = crypto_controller.CryptoController(queue=None)
controller.coin_map_df = COIN_MAP_DF
controller.current_coin = CURRENT_COIN
controller.symbol = SYMBOL
controller.source = "bin"
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = crypto_controller.CryptoController(queue=None)
controller.coin_map_df = COIN_MAP_DF
controller.current_coin = CURRENT_COIN
controller.symbol = SYMBOL
controller.source = "bin"
getattr(controller, tested_func)(other_args)
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func",
[
"call_prt",
"call_chart",
"call_ta",
"call_dd",
"call_pred",
],
)
def test_call_func_no_current_coin(tested_func):
controller = crypto_controller.CryptoController(queue=None)
controller.current_coin = None
getattr(controller, tested_func)([])
@pytest.mark.vcr
@pytest.mark.record_stdout
def test_call_load():
controller = crypto_controller.CryptoController()
other_args = [SYMBOL]
controller.call_load(other_args=other_args)

View File

@@ -0,0 +1,7 @@
Loaded bitcoin against usd from CoinGecko source
Current Price: 38199.42 USD
Performance in interval (1day): [green]0.92%[/green]
Performance since 2021-01-29: [green]11.86%[/green]

View File

@@ -0,0 +1,21 @@
load load a specific cryptocurrency for analysis
find find coins
Coin:
Source:
headlines crypto sentiment from 15+ major news headlines [Finbrain][unvl]
chart view a candle chart for a specific cryptocurrency
prt potential returns tool - check how much upside if ETH reaches BTC market cap[/unvl]
> disc discover trending cryptocurrencies, e.g.: top gainers, losers, top sentiment
> ov overview of the cryptocurrencies, e.g.: market cap, DeFi, latest news, top exchanges, stables
> onchain information on different blockchains, e.g.: eth gas fees, whale alerts, DEXes info
> defi decentralized finance information, e.g.: dpi, llama, tvl, lending, borrow, funding
> nft non-fungible tokens, e.g.: today drops[unvl]
> dd due-diligence for loaded coin, e.g.: coin information, social media, market stats
> ta technical analysis for loaded coin, e.g.: ema, macd, rsi, adx, bbands, obv
> pred prediction techniques e.g.: regression, arima, rnn, lstm, conv1d, monte carlo
[/unvl]

View File

@@ -0,0 +1,11 @@
# IMPORTATION STANDARD
# IMPORTATION THIRDPARTY
# IMPORTATION INTERNAL
from gamestonk_terminal.helper_classes import ModelsNamespace as _models
from gamestonk_terminal.etf import etf_api
def test_models():
assert isinstance(etf_api.models, _models)

View File

@@ -0,0 +1,233 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.portfolio.portfolio_analysis import pa_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = "gamestonk_terminal.portfolio.portfolio_analysis.pa_controller"
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.PortfolioAnalysis.switch",
return_value=["quit"],
)
result_menu = pa_controller.PortfolioAnalysis(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = "gamestonk_terminal.portfolio.portfolio_analysis.pa_controller"
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=pa_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = pa_controller.PortfolioAnalysis(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = "gamestonk_terminal.portfolio.portfolio_analysis.pa_controller"
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=pa_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.PortfolioAnalysis.switch",
new=mock_switch,
)
result_menu = pa_controller.PortfolioAnalysis(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = pa_controller.PortfolioAnalysis(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "portfolio", "pa"],
),
],
)
def test_switch(an_input, expected_queue):
controller = pa_controller.PortfolioAnalysis(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = pa_controller.PortfolioAnalysis(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "portfolio", "pa"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "portfolio", "pa", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = pa_controller.PortfolioAnalysis(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_group",
[],
"",
[],
dict(),
),
(
"call_view",
[],
"",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.portfolio.portfolio_analysis.pa_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = pa_controller.PortfolioAnalysis(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = pa_controller.PortfolioAnalysis(queue=None)
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,8 @@
view view available portfolios
load load portfolio from a file
Portfolio:
group view holdings grouped by parameter

View File

@@ -0,0 +1,339 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.portfolio.portfolio_optimization import po_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"queue, expected",
[
(["load", "help"], []),
(["quit", "help"], ["help"]),
],
)
def test_menu_with_queue(expected, mocker, queue):
path_controller = (
"gamestonk_terminal.portfolio.portfolio_optimization.po_controller"
)
# MOCK SWITCH
mocker.patch(
target=f"{path_controller}.PortfolioOptimization.switch",
return_value=["quit"],
)
result_menu = po_controller.PortfolioOptimization(queue=queue).menu()
assert result_menu == expected
@pytest.mark.vcr(record_mode="none")
def test_menu_without_queue_completion(mocker):
path_controller = (
"gamestonk_terminal.portfolio.portfolio_optimization.po_controller"
)
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
mocker.patch(
target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session",
)
mocker.patch(
target="gamestonk_terminal.parent_classes.session.prompt",
return_value="quit",
)
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
mocker.patch.object(
target=po_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=True,
)
mocker.patch(
target=f"{path_controller}.session",
)
mocker.patch(
target=f"{path_controller}.session.prompt",
return_value="quit",
)
result_menu = po_controller.PortfolioOptimization(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"mock_input",
["help", "homee help", "home help", "mock"],
)
def test_menu_without_queue_sys_exit(mock_input, mocker):
path_controller = (
"gamestonk_terminal.portfolio.portfolio_optimization.po_controller"
)
# DISABLE AUTO-COMPLETION
mocker.patch.object(
target=po_controller.gtff,
attribute="USE_PROMPT_TOOLKIT",
new=False,
)
mocker.patch(
target=f"{path_controller}.session",
return_value=None,
)
# MOCK USER INPUT
mocker.patch("builtins.input", return_value=mock_input)
# MOCK SWITCH
class SystemExitSideEffect:
def __init__(self):
self.first_call = True
def __call__(self, *args, **kwargs):
if self.first_call:
self.first_call = False
raise SystemExit()
return ["quit"]
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
mocker.patch(
target=f"{path_controller}.PortfolioOptimization.switch",
new=mock_switch,
)
result_menu = po_controller.PortfolioOptimization(queue=None).menu()
assert result_menu == []
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_print_help():
controller = po_controller.PortfolioOptimization(queue=None)
controller.print_help()
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"an_input, expected_queue",
[
("", []),
("/help", ["home", "help"]),
("help/help", ["help", "help"]),
("q", ["quit"]),
("h", []),
(
"r",
["quit", "quit", "reset", "portfolio", "po"],
),
],
)
def test_switch(an_input, expected_queue):
controller = po_controller.PortfolioOptimization(queue=None)
queue = controller.switch(an_input=an_input)
assert queue == expected_queue
@pytest.mark.vcr(record_mode="none")
def test_call_cls(mocker):
mocker.patch("os.system")
controller = po_controller.PortfolioOptimization(queue=None)
controller.call_cls([])
assert controller.queue == []
os.system.assert_called_once_with("cls||clear")
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"func, queue, expected_queue",
[
(
"call_exit",
[],
["quit", "quit", "quit"],
),
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
("call_home", [], ["quit", "quit"]),
("call_help", [], []),
("call_quit", [], ["quit"]),
("call_quit", ["help"], ["quit", "help"]),
(
"call_reset",
[],
["quit", "quit", "reset", "portfolio", "po"],
),
(
"call_reset",
["help"],
["quit", "quit", "reset", "portfolio", "po", "help"],
),
],
)
def test_call_func_expect_queue(expected_queue, func, queue):
controller = po_controller.PortfolioOptimization(queue=queue)
result = getattr(controller, func)([])
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_select",
[],
"PortfolioOptimization.add_stocks",
[],
dict(),
),
(
"call_add",
[],
"PortfolioOptimization.add_stocks",
[],
dict(),
),
(
"call_rmv",
[],
"PortfolioOptimization.rmv_stocks",
[],
dict(),
),
(
"call_equal",
[],
"optimizer_view.display_equal_weight",
[],
dict(),
),
(
"call_mktcap",
[],
"optimizer_view.display_property_weighting",
[],
dict(),
),
(
"call_dividend",
[],
"optimizer_view.display_property_weighting",
[],
dict(),
),
(
"call_property",
["--property=open"],
"optimizer_view.display_property_weighting",
[],
dict(),
),
(
"call_maxsharpe",
[],
"optimizer_view.display_max_sharpe",
[],
dict(),
),
(
"call_minvol",
[],
"optimizer_view.display_min_volatility",
[],
dict(),
),
(
"call_maxquadutil",
[],
"optimizer_view.display_max_quadratic_utility",
[],
dict(),
),
(
"call_effrisk",
[],
"optimizer_view.display_efficient_risk",
[],
dict(),
),
(
"call_effret",
[],
"optimizer_view.display_efficient_return",
[],
dict(),
),
(
"call_ef",
[],
"optimizer_view.display_ef",
[],
dict(),
),
(
"call_yolo",
[],
"",
[],
dict(),
),
(
"add_stocks",
[],
"",
[],
dict(),
),
(
"rmv_stocks",
[],
"",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = (
"gamestonk_terminal.portfolio.portfolio_optimization.po_controller"
)
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = po_controller.PortfolioOptimization(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = po_controller.PortfolioOptimization(queue=None)
getattr(controller, tested_func)(other_args)

View File

@@ -0,0 +1,22 @@
select select list of tickers to be optimized
add add tickers to the list of the tickers to be optimized
rmv remove tickers from the list of the tickers to be optimized
Tickers: None
Optimization:
equal equally weighted
mktcap weighted according to market cap (property marketCap)
dividend weighted according to dividend yield (property dividendYield)
property weight according to selected info property
Mean Variance Optimization:
maxsharpe optimizes for maximal Sharpe ratio (a.k.a the tangency portfolio
minvol optimizes for minimum volatility
maxquadutil maximises the quadratic utility, given some risk aversion
effret maximises return for a given target risk
effrisk minimises risk for a given target return
ef show the efficient frontier

View File

@@ -1,7 +1,16 @@
# IMPORTATION STANDARD
import os
# IMPORTATION THIRDPARTY
import pytest
# IMPORTATION INTERNAL
from gamestonk_terminal.portfolio import portfolio_controller
# pylint: disable=E1101
# pylint: disable=W0603
# pylint: disable=E1111
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
@@ -122,11 +131,7 @@ def test_print_help():
("h", []),
(
"r",
[
"quit",
"reset",
"portfolio",
],
["quit", "reset", "portfolio"],
),
],
)
@@ -165,21 +170,12 @@ def test_call_cls(mocker):
(
"call_reset",
[],
[
"quit",
"reset",
"portfolio",
],
["quit", "reset", "portfolio"],
),
(
"call_reset",
["help"],
[
"quit",
"reset",
"portfolio",
"help",
],
["quit", "reset", "portfolio", "help"],
),
],
)
@@ -189,3 +185,70 @@ def test_call_func_expect_queue(expected_queue, func, queue):
assert result is None
assert controller.queue == expected_queue
@pytest.mark.vcr(record_mode="none")
@pytest.mark.parametrize(
"tested_func, other_args, mocked_func, called_args, called_kwargs",
[
(
"call_bro",
[],
"PortfolioController.load_class",
[],
dict(),
),
(
"call_po",
[],
"PortfolioController.load_class",
[],
dict(),
),
(
"call_pa",
[],
"PortfolioController.load_class",
[],
dict(),
),
(
"call_save",
["MOCK_NAME.csv"],
"portfolio_model.save_df",
[],
dict(),
),
(
"call_show",
[],
"portfolio_view.show_df",
[],
dict(),
),
],
)
def test_call_func(
tested_func, mocked_func, other_args, called_args, called_kwargs, mocker
):
path_controller = "gamestonk_terminal.portfolio.portfolio_controller"
if mocked_func:
mock = mocker.Mock()
mocker.patch(
target=f"{path_controller}.{mocked_func}",
new=mock,
)
controller = portfolio_controller.PortfolioController(queue=None)
getattr(controller, tested_func)(other_args)
if called_args or called_kwargs:
mock.assert_called_once_with(*called_args, **called_kwargs)
else:
mock.assert_called_once()
else:
controller = portfolio_controller.PortfolioController(queue=None)
getattr(controller, tested_func)(other_args)