Skip to content

Commit

Permalink
[BugFix] - Fix tests for release (#6372)
Browse files Browse the repository at this point in the history
* Fix user service

* fix module import

* proper Chart(...) mock

* Fix SEC rss

* improve test on to_chart() method

* Fix form 13F example filing

* remove broken example

* Add lxml dep to SEC

* fix default

* fix: treasury_prices default date, last business day´

* fix: linting

* fix: rebuild

* ^

---------

Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
  • Loading branch information
3 people authored May 7, 2024
1 parent 101990d commit e12aac1
Show file tree
Hide file tree
Showing 22 changed files with 460 additions and 601 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
types: [python]
files: '^openbb_platform/.*\.py$'
exclude: 'tests/.*\.py|openbb_platform/test_.*\.py'
args: ["--config=pyproject.toml"]
args: ["--config=ruff.toml"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
Expand Down
2 changes: 1 addition & 1 deletion openbb_platform/core/openbb_core/app/model/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Preferences(BaseModel):
)
plot_pywry_height: PositiveInt = 762
plot_pywry_width: PositiveInt = 1400
request_timeout: PositiveInt = 15
request_timeout: PositiveInt = 60
show_warnings: bool = True
table_style: Literal["dark", "light"] = "dark"
user_styles_directory: str = str(Path.home() / "OpenBBUserData" / "styles" / "user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TreasuryPricesQueryParams(QueryParams):

date: Optional[dateType] = Field(
description=QUERY_DESCRIPTIONS.get("date", "")
+ " No date will return the current posted data.",
+ " Defaults to the last business day.",
default=None,
)

Expand Down
3 changes: 2 additions & 1 deletion openbb_platform/core/tests/app/service/test_user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_update_default():
# Update the default settings
updated_settings = UserService.update_default(other_settings)

assert updated_settings.defaults.model_dump() == defaults_test.model_dump()
assert "test" in updated_settings.defaults.model_dump()["routes"]
assert updated_settings.defaults.model_dump()["routes"]["test"] == {"test": "test"}


def test_merge_dicts():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
+ " long_period=365, short_period=30, window=30, trading_periods=365)",
],
),
APIEx(
description="Note that the mock data displayed here is insufficient."
+ " It must contain multiple symbols, with the benchmark, and be daily data at least 1 year in length.",
parameters={"benchmark": "SPY", "data": APIEx.mock_data("timeseries")},
),
],
)
async def relative_rotation(
Expand Down
32 changes: 15 additions & 17 deletions openbb_platform/obbject_extensions/charting/tests/test_charting.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self):
self.provider = "mock_provider"
self.extra = "mock_extra"
self.warnings = "mock_warnings"
self.chart = MagicMock()

def to_dataframe(self):
"""Mock to_dataframe."""
Expand Down Expand Up @@ -108,8 +109,8 @@ def test_functions(mock_get_charting_functions):
mock_get_charting_functions.assert_called_once()


@patch("openbb_charting.core.backend.get_backend")
@patch("openbb_charting.core.backend.create_backend")
@patch("openbb_charting.get_backend")
@patch("openbb_charting.create_backend")
def test_handle_backend(mock_create_backend, mock_get_backend, obbject):
"""Test _handle_backend method."""
# Act -> _handle backend is called in the constructor
Expand All @@ -136,7 +137,8 @@ def test_get_chart_function(mock_charting_router):


@patch("openbb_charting.Charting._get_chart_function")
def test_show(mock_get_chart_function, obbject):
@patch("openbb_charting.Chart")
def test_show(_, mock_get_chart_function, obbject):
"""Test show method."""
# Arrange
mock_function = MagicMock()
Expand All @@ -151,28 +153,24 @@ def test_show(mock_get_chart_function, obbject):
# Assert
mock_get_chart_function.assert_called_once()
mock_function.assert_called_once()
mock_fig.show.assert_called_once()


@patch("openbb_charting.to_chart")
def test_to_chart(mock_to_chart, obbject):
@patch("openbb_charting.Charting._prepare_data_as_df")
@patch("openbb_charting.Charting._get_chart_function")
@patch("openbb_charting.Chart")
def test_to_chart(_, mock_get_chart_function, mock_prepare_data_as_df, obbject):
"""Test to_chart method."""
# Arrange
mock_prepare_data_as_df.return_value = (mock_dataframe, True)
mock_function = MagicMock()
mock_get_chart_function.return_value = mock_function
mock_fig = MagicMock()
mock_to_chart.return_value = (mock_fig, {"content": "mock_content"})
mock_function.return_value = (mock_fig, {"content": "mock_content"})
obj = Charting(obbject)

# Act
obj.to_chart()

# Assert
assert obj._obbject.chart.fig == mock_fig
mock_to_chart.assert_called_once_with(
mock_dataframe,
indicators=None,
symbol="",
candles=True,
volume=True,
prepost=False,
volume_ticks_x=7,
)
mock_get_chart_function.assert_called_once()
mock_function.assert_called_once()
Loading

0 comments on commit e12aac1

Please sign in to comment.