Replaces global sample dataset with a function to provide fresh dataframes in tests, preventing unintended data sharing between test cases. Updates metric logic to return NaN for invalid parameters instead of printing and returning None, improving API consistency and testability.
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from tests.config import get_sample_data
|
|
from tests.context import pandas_ta_classic as pandas_ta
|
|
|
|
from unittest import TestCase
|
|
from pandas import DataFrame
|
|
|
|
|
|
class TestPerformaceExtension(TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.data = get_sample_data()
|
|
cls.islong = cls.data["close"] > pandas_ta.sma(cls.data["close"], length=50)
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
del cls.data
|
|
del cls.islong
|
|
|
|
def setUp(self): pass
|
|
def tearDown(self): pass
|
|
|
|
|
|
def test_log_return_ext(self):
|
|
self.data.ta.log_return(append=True)
|
|
self.assertIsInstance(self.data, DataFrame)
|
|
self.assertEqual(self.data.columns[-1], "LOGRET_1")
|
|
|
|
def test_cum_log_return_ext(self):
|
|
self.data.ta.log_return(append=True, cumulative=True)
|
|
self.assertIsInstance(self.data, DataFrame)
|
|
self.assertEqual(self.data.columns[-1], "CUMLOGRET_1")
|
|
|
|
def test_percent_return_ext(self):
|
|
self.data.ta.percent_return(append=True)
|
|
self.assertIsInstance(self.data, DataFrame)
|
|
self.assertEqual(self.data.columns[-1], "PCTRET_1")
|
|
|
|
def test_cum_percent_return_ext(self):
|
|
self.data.ta.percent_return(append=True, cumulative=True)
|
|
self.assertIsInstance(self.data, DataFrame)
|
|
self.assertEqual(self.data.columns[-1], "CUMPCTRET_1")
|