Skip to content

Commit f84d753

Browse files
committed
fix tests
1 parent f787e8a commit f84d753

File tree

4 files changed

+109
-25
lines changed

4 files changed

+109
-25
lines changed

tests/indicators/conftest.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import pytest
21
import polars as pl
2+
import pytest
3+
34

45
@pytest.fixture
56
def sample_ohlcv_df():
@@ -8,24 +9,29 @@ def sample_ohlcv_df():
89
Values are monotonically increasing for easy/deterministic indicator output.
910
"""
1011
n = 120
11-
return pl.DataFrame({
12-
"open": [float(i) for i in range(n)],
13-
"high": [float(i) + 1 for i in range(n)],
14-
"low": [float(i) - 1 for i in range(n)],
15-
"close": [float(i) + 0.5 for i in range(n)],
16-
"volume": [100 + i for i in range(n)],
17-
})
12+
return pl.DataFrame(
13+
{
14+
"open": [float(i) for i in range(n)],
15+
"high": [float(i) + 1 for i in range(n)],
16+
"low": [float(i) - 1 for i in range(n)],
17+
"close": [float(i) + 0.5 for i in range(n)],
18+
"volume": [100 + i for i in range(n)],
19+
}
20+
)
21+
1822

1923
@pytest.fixture
2024
def small_ohlcv_df():
2125
"""
2226
Returns a polars DataFrame with 5 rows to trigger insufficient data paths.
2327
"""
2428
n = 5
25-
return pl.DataFrame({
26-
"open": [float(i) for i in range(n)],
27-
"high": [float(i) + 1 for i in range(n)],
28-
"low": [float(i) - 1 for i in range(n)],
29-
"close": [float(i) + 0.5 for i in range(n)],
30-
"volume": [100 + i for i in range(n)],
31-
})
29+
return pl.DataFrame(
30+
{
31+
"open": [float(i) for i in range(n)],
32+
"high": [float(i) + 1 for i in range(n)],
33+
"low": [float(i) - 1 for i in range(n)],
34+
"close": [float(i) + 0.5 for i in range(n)],
35+
"volume": [100 + i for i in range(n)],
36+
}
37+
)

tests/indicators/test_all_indicators.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import pytest
2-
import polars as pl
3-
import inspect
41
import importlib
2+
import inspect
53
import pkgutil
4+
5+
import polars as pl
6+
import pytest
7+
68
from project_x_py.indicators.base import BaseIndicator
79

10+
811
def _concrete_indicator_classes():
912
# Recursively discover all non-abstract subclasses of BaseIndicator in project_x_py.indicators.*
1013
import project_x_py.indicators
14+
1115
seen = set()
1216
result = []
1317

@@ -27,7 +31,9 @@ def onclass(cls):
2731
result.append(cls)
2832

2933
# Walk all modules in project_x_py.indicators package
30-
for finder, name, ispkg in pkgutil.walk_packages(project_x_py.indicators.__path__, project_x_py.indicators.__name__ + "."):
34+
for _, name, _ in pkgutil.walk_packages(
35+
project_x_py.indicators.__path__, project_x_py.indicators.__name__ + "."
36+
):
3137
try:
3238
mod = importlib.import_module(name)
3339
except Exception:
@@ -37,7 +43,10 @@ def onclass(cls):
3743
# Remove duplicates, sort by class name for determinism
3844
return sorted(set(result), key=lambda cls: cls.__name__)
3945

40-
@pytest.mark.parametrize("indicator_cls", _concrete_indicator_classes(), ids=lambda cls: cls.__name__)
46+
47+
@pytest.mark.parametrize(
48+
"indicator_cls", _concrete_indicator_classes(), ids=lambda cls: cls.__name__
49+
)
4150
def test_indicator_calculate_adds_new_column(indicator_cls, sample_ohlcv_df):
4251
"""
4352
For every indicator class: instantiate with default ctor, call .calculate() or __call__ on sample data.
@@ -53,17 +62,23 @@ def test_indicator_calculate_adds_new_column(indicator_cls, sample_ohlcv_df):
5362
except Exception:
5463
out_df = instance.calculate(sample_ohlcv_df)
5564

56-
assert isinstance(out_df, pl.DataFrame), f"{indicator_cls.__name__} output is not a polars.DataFrame"
65+
assert isinstance(out_df, pl.DataFrame), (
66+
f"{indicator_cls.__name__} output is not a polars.DataFrame"
67+
)
5768
assert out_df.height == sample_ohlcv_df.height, (
5869
f"{indicator_cls.__name__} output row count {out_df.height} != input {sample_ohlcv_df.height}"
5970
)
6071
new_cols = set(out_df.columns) - input_cols
6172
assert new_cols, f"{indicator_cls.__name__} did not add any new columns"
6273

74+
6375
def _get_new_column_names(indicator_cls, input_cols, df):
6476
return set(df.columns) - set(input_cols)
6577

66-
@pytest.mark.parametrize("indicator_cls", _concrete_indicator_classes(), ids=lambda cls: cls.__name__)
78+
79+
@pytest.mark.parametrize(
80+
"indicator_cls", _concrete_indicator_classes(), ids=lambda cls: cls.__name__
81+
)
6782
def test_indicator_caching_returns_same_object(indicator_cls, sample_ohlcv_df):
6883
"""
6984
Calling the indicator twice with the same df on the same instance should return the exact same DataFrame object (proves internal cache).
@@ -74,4 +89,4 @@ def test_indicator_caching_returns_same_object(indicator_cls, sample_ohlcv_df):
7489
out2 = instance(sample_ohlcv_df)
7590
assert out1 is out2, (
7691
f"{indicator_cls.__name__} did not return identical object on repeated call (cache broken?)"
77-
)
92+
)

tests/test_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Main test entry point for ProjectX client module tests."""
22

3-
import pytest
4-
53
from project_x_py import ProjectX
64

75
# This file serves as a main entry point for running client tests.

0 commit comments

Comments
 (0)