Skip to content

Commit

Permalink
Add docstrings to most QuoteTableState tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
joce committed Nov 13, 2023
1 parent 42fa720 commit 3b97f25
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
84 changes: 81 additions & 3 deletions tests/appui/test_quote_table_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

@pytest.fixture
def fixture_qts() -> QuoteTableState:
"""
An instance of the QuoteTableState class, with a FakeYFinance instance to get the
quotes.
"""
yfin = FakeYFinance()
qts = QuoteTableState(yfin)
return qts
Expand All @@ -37,7 +41,7 @@ def fixture_qts() -> QuoteTableState:
@pytest.fixture
def duplicate_column(fixture_qts: QuoteTableState):
"""
Helper fixture for testing invalid column addition and insertion
Helper fixture for testing invalid column addition and insertion.
"""
return fixture_qts.quotes_columns[1].key

Expand All @@ -48,6 +52,11 @@ def duplicate_column(fixture_qts: QuoteTableState):


def test_load_regular_config(fixture_qts: QuoteTableState):
"""
Regular config loading.
This is expected to work.
"""

config: dict[str, Any] = {
QuoteTableState._COLUMNS: ["last", "change_percent"],
QuoteTableState._SORT_COLUMN: "last",
Expand All @@ -67,6 +76,12 @@ def test_load_regular_config(fixture_qts: QuoteTableState):


def test_load_empty_config(fixture_qts: QuoteTableState):
"""
Empty config loading.
This is expected to work.
The defaults should be used.
"""

config: dict[str, Any] = {}
fixture_qts.load_config(config)
assert (
Expand All @@ -80,6 +95,12 @@ def test_load_empty_config(fixture_qts: QuoteTableState):


def test_load_config_invalid_columns(fixture_qts: QuoteTableState):
"""
Config loading with an invalid column.
This is expected to work.
The invalid column should be ignored.
"""

config: dict[str, Any] = {
QuoteTableState._COLUMNS: ["truly_not_a_column", "last"],
}
Expand All @@ -88,14 +109,26 @@ def test_load_config_invalid_columns(fixture_qts: QuoteTableState):


def test_load_config_duplicate_columns(fixture_qts: QuoteTableState):
"""
Config loading with an a column defined more than once.
This is expected to work.
The duplicated columns should be ignored.
"""

config: dict[str, Any] = {
QuoteTableState._COLUMNS: ["last", "last", "last"],
}
fixture_qts.load_config(config)
assert fixture_qts.column_keys == [QuoteTableState._TICKER_COLUMN_KEY, "last"]


def test_load_config_duplicate_mandatory_column(fixture_qts: QuoteTableState):
def test_load_config_duplicate_default_column(fixture_qts: QuoteTableState):
"""
Config loading with the default specified in the config.
This is expected to work.
The default column should be added again.
"""

config: dict[str, Any] = {
QuoteTableState._COLUMNS: [
"last",
Expand All @@ -114,6 +147,12 @@ def test_load_config_duplicate_mandatory_column(fixture_qts: QuoteTableState):


def test_load_config_invalid_sort_column(fixture_qts: QuoteTableState):
"""
Config loading an invalid sort column.
This is expected to work.
The default column should be used as sort column.
"""

config: dict[str, Any] = {
QuoteTableState._COLUMNS: ["last", "change_percent"],
QuoteTableState._SORT_COLUMN: "truly_not_a_column",
Expand All @@ -123,6 +162,12 @@ def test_load_config_invalid_sort_column(fixture_qts: QuoteTableState):


def test_load_config_invalid_sort_direction(fixture_qts: QuoteTableState):
"""
Config loading an invalid sort direction.
This is expected to work.
The default sort direction should be used.
"""

config: dict[str, Any] = {
QuoteTableState._SORT_DIRECTION: "amazing",
}
Expand All @@ -131,6 +176,12 @@ def test_load_config_invalid_sort_direction(fixture_qts: QuoteTableState):


def test_load_config_invalid_query_frequency(fixture_qts: QuoteTableState):
"""
Config loading an invalid quote querying frequency.
This is expected to work.
The default query frequency should be used.
"""

config: dict[str, Any] = {
QuoteTableState._QUERY_FREQUENCY: 0,
}
Expand All @@ -139,6 +190,12 @@ def test_load_config_invalid_query_frequency(fixture_qts: QuoteTableState):


def test_load_config_empty_quote_symbol(fixture_qts: QuoteTableState):
"""
Config loading a quote symbol that is an empty string.
This is expected to work.
The invalid quote symbol should be ignored.
"""

config: dict[str, Any] = {
QuoteTableState._QUOTES: ["AAPL", "F", "", "VT"],
}
Expand All @@ -147,6 +204,12 @@ def test_load_config_empty_quote_symbol(fixture_qts: QuoteTableState):


def test_load_config_duplicate_quote_symbol(fixture_qts: QuoteTableState):
"""
Config loading with quote symbols defined more than once.
This is expected to work.
The duplicated quote symbols should be ignored.
"""

config: dict[str, Any] = {
QuoteTableState._QUOTES: ["AAPL", "F", "F", "VT", "AAPL"],
}
Expand All @@ -159,7 +222,12 @@ def test_load_config_duplicate_quote_symbol(fixture_qts: QuoteTableState):
##############################################################################


def test_save_config_empty_dict(fixture_qts: QuoteTableState):
def test_save_config(fixture_qts: QuoteTableState):
"""
Regular config saving.
This is expected to work.
"""

config: dict[str, Any] = fixture_qts.save_config()

# The first column, "ticker", is not saved
Expand All @@ -171,6 +239,11 @@ def test_save_config_empty_dict(fixture_qts: QuoteTableState):


def test_save_config_takes_list_copies(fixture_qts: QuoteTableState):
"""
Make sure that saving a config takes a copy of lists.
This is expected to work.
"""

config: dict[str, Any] = fixture_qts.save_config()
config[QuoteTableState._COLUMNS][0] = "foo_foo"
config[QuoteTableState._QUOTES][0] = "ZZZZ"
Expand All @@ -179,6 +252,11 @@ def test_save_config_takes_list_copies(fixture_qts: QuoteTableState):


def test_round_trip_config(fixture_qts: QuoteTableState):
"""
Make sure that a round trip save and load works.
This is expected to work.
"""

config: dict[str, Any] = fixture_qts.save_config()

# The first column, "ticker", is not saved
Expand Down
2 changes: 1 addition & 1 deletion tests/appui/test_stockyardapp_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_load_config_invalid_lof_level(fixture_sas: StockyardAppState):
assert fixture_sas._log_level == StockyardAppState._DEFAULT_LOG_LEVEL


def test_save_config_empty_dict(fixture_sas: StockyardAppState):
def test_save_config(fixture_sas: StockyardAppState):
config: dict[str, Any] = fixture_sas.save_config()
assert [QuoteTableState._TICKER_COLUMN_KEY] + config[
StockyardAppState._QUOTE_TABLE
Expand Down

0 comments on commit 3b97f25

Please sign in to comment.