Skip to content

Commit ffb4ceb

Browse files
committed
merge branch v5
2 parents f85f79b + 0482570 commit ffb4ceb

56 files changed

Lines changed: 9477 additions & 9502 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-unit-platform.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

cookiecutter/poetry.lock

Lines changed: 159 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openbb_platform/core/openbb_core/app/model/system_settings.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,24 @@ def create_json(path: Path, template: dict | None = None) -> None:
7272
"""Create an empty JSON file."""
7373
path.write_text(json.dumps(obj=template or {}, indent=4), encoding="utf-8")
7474

75-
# TODO: Figure out why this works only opposite to what the docs say
76-
# https://docs.pydantic.dev/latest/concepts/validators/#model-validators
77-
# based on docs first argument should be self, but it works only with cls
78-
@model_validator(mode="after") # type: ignore
79-
@classmethod
80-
def create_openbb_directory(cls, values: "SystemSettings") -> "SystemSettings":
75+
@model_validator(mode="after")
76+
def create_openbb_directory(self) -> "SystemSettings":
8177
"""Create the OpenBB directory if it doesn't exist."""
82-
obb_dir = Path(values.openbb_directory).resolve()
83-
user_settings = Path(values.user_settings_path).resolve()
84-
system_settings = Path(values.system_settings_path).resolve()
78+
obb_dir = Path(self.openbb_directory).resolve()
79+
user_settings = Path(self.user_settings_path).resolve()
80+
system_settings = Path(self.system_settings_path).resolve()
8581
obb_dir.mkdir(parents=True, exist_ok=True)
8682

8783
if not user_settings.exists():
88-
cls.create_json(
84+
self.create_json(
8985
user_settings,
9086
{"credentials": {}, "preferences": {}, "defaults": {"commands": {}}},
9187
)
9288

9389
if not system_settings.exists():
94-
cls.create_json(system_settings, {})
90+
self.create_json(system_settings, {})
9591

96-
return values
92+
return self
9793

9894
@field_validator("logging_handlers")
9995
@classmethod

openbb_platform/core/tests/app/model/test_system_settings.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44
from pathlib import Path
55

66
import pytest
7-
from pydantic import BaseModel, ConfigDict
87

98
from openbb_core.app.model.system_settings import SystemSettings
109

1110

12-
class MockSystemSettings(BaseModel):
13-
"""Mock SystemSettings."""
14-
15-
model_config = ConfigDict(extra="allow", populate_by_name=True)
16-
17-
1811
def test_system_settings():
1912
"""Test the SystemSettings class."""
2013
sys = SystemSettings()
@@ -29,74 +22,78 @@ def test_system_settings_repr():
2922
assert "openbb_directory" in result
3023

3124

32-
def test_create_openbb_directory_directory_and_files_not_exist(tmpdir):
25+
def test_create_openbb_directory_directory_and_files_not_exist(tmpdir, monkeypatch):
3326
"""Test the create_openbb_directory method."""
3427
# Arrange
35-
values = MockSystemSettings(
36-
**{
37-
"openbb_directory": str(tmpdir.join("openbb")),
38-
"user_settings_path": str(tmpdir.join("user_settings.json")),
39-
"system_settings_path": str(tmpdir.join("system_settings.json")),
40-
}
28+
obb_dir = str(tmpdir.join("openbb"))
29+
user_settings = str(tmpdir.join("user_settings.json"))
30+
system_settings = str(tmpdir.join("system_settings.json"))
31+
32+
monkeypatch.setenv("OPENBB_DIRECTORY", obb_dir)
33+
monkeypatch.setenv("USER_SETTINGS_PATH", user_settings)
34+
monkeypatch.setenv("SYSTEM_SETTINGS_PATH", system_settings)
35+
36+
# Act - The validator runs automatically during instantiation
37+
sys = SystemSettings(
38+
openbb_directory=obb_dir,
39+
user_settings_path=user_settings,
40+
system_settings_path=system_settings,
4141
)
4242

43-
# Act
44-
SystemSettings.create_openbb_directory(values) # type: ignore[operator]
45-
4643
# Assert
47-
assert os.path.exists(values.openbb_directory) # type: ignore[attr-defined]
48-
assert os.path.exists(values.user_settings_path) # type: ignore[attr-defined]
49-
assert os.path.exists(values.system_settings_path) # type: ignore[attr-defined]
44+
assert os.path.exists(sys.openbb_directory)
45+
assert os.path.exists(sys.user_settings_path)
46+
assert os.path.exists(sys.system_settings_path)
5047

5148

5249
def test_create_openbb_directory_directory_exists_user_settings_missing(tmpdir):
5350
"""Test the create_openbb_directory method."""
5451
# Arrange
55-
values = MockSystemSettings(
56-
**{
57-
"openbb_directory": str(tmpdir.join("openbb")),
58-
"user_settings_path": str(tmpdir.join("user_settings.json")),
59-
"system_settings_path": str(tmpdir.join("system_settings.json")),
60-
}
61-
)
52+
obb_dir = str(tmpdir.join("openbb"))
53+
user_settings = str(tmpdir.join("user_settings.json"))
54+
system_settings = str(tmpdir.join("system_settings.json"))
6255

6356
# Create the openbb directory
64-
Path(values.openbb_directory).mkdir(parents=True, exist_ok=True) # type: ignore[attr-defined]
57+
Path(obb_dir).mkdir(parents=True, exist_ok=True)
6558

66-
# Act
67-
SystemSettings.create_openbb_directory(values) # type: ignore[operator]
59+
# Act - The validator runs automatically during instantiation
60+
sys = SystemSettings(
61+
openbb_directory=obb_dir,
62+
user_settings_path=user_settings,
63+
system_settings_path=system_settings,
64+
)
6865

6966
# Assert
70-
assert os.path.exists(values.openbb_directory) # type: ignore[attr-defined]
71-
assert os.path.exists(values.user_settings_path) # type: ignore[attr-defined]
72-
assert os.path.exists(values.system_settings_path) # type: ignore[attr-defined]
67+
assert os.path.exists(sys.openbb_directory)
68+
assert os.path.exists(sys.user_settings_path)
69+
assert os.path.exists(sys.system_settings_path)
7370

7471

7572
def test_create_openbb_directory_directory_exists_system_settings_missing(tmpdir):
7673
"""Test the create_openbb_directory method."""
7774
# Arrange
78-
values = MockSystemSettings(
79-
**{
80-
"openbb_directory": str(tmpdir.join("openbb")),
81-
"user_settings_path": str(tmpdir.join("user_settings.json")),
82-
"system_settings_path": str(tmpdir.join("system_settings.json")),
83-
}
84-
)
75+
obb_dir = str(tmpdir.join("openbb"))
76+
user_settings = str(tmpdir.join("user_settings.json"))
77+
system_settings = str(tmpdir.join("system_settings.json"))
8578

8679
# Create the openbb directory
87-
Path(values.openbb_directory).mkdir(parents=True, exist_ok=True) # type: ignore[attr-defined]
80+
Path(obb_dir).mkdir(parents=True, exist_ok=True)
8881

8982
# Create the user_settings.json file
90-
with open(values.user_settings_path, "w") as f: # type: ignore[attr-defined]
83+
with open(user_settings, "w") as f:
9184
f.write("{}")
9285

93-
# Act
94-
SystemSettings.create_openbb_directory(values) # type: ignore[operator]
86+
# Act - The validator runs automatically during instantiation
87+
sys = SystemSettings(
88+
openbb_directory=obb_dir,
89+
user_settings_path=user_settings,
90+
system_settings_path=system_settings,
91+
)
9592

9693
# Assert
97-
assert os.path.exists(values.openbb_directory) # type: ignore[attr-defined]
98-
assert os.path.exists(values.user_settings_path) # type: ignore[attr-defined]
99-
assert os.path.exists(values.system_settings_path) # type: ignore[attr-defined]
94+
assert os.path.exists(sys.openbb_directory)
95+
assert os.path.exists(sys.user_settings_path)
96+
assert os.path.exists(sys.system_settings_path)
10097

10198

10299
@pytest.mark.parametrize(

openbb_platform/core/tests/app/static/package_builder/test_docstring_generator_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class MyData:
9595
MyData.__qualname__ = "MyData"
9696

9797
out = DocstringGenerator.get_field_type(
98-
Union[list[MyData], None], is_required=False
98+
Union[list[MyData], None], # noqa: UP007 — explicit form is the point
99+
is_required=False,
99100
)
100101
# Container preserved, dotted prefix stripped.
101102
assert "list[MyData]" in out

0 commit comments

Comments
 (0)