diff --git a/tests/test_algorithm.py b/tests/test_algorithm.py index c93ea308..bc89e5f9 100644 --- a/tests/test_algorithm.py +++ b/tests/test_algorithm.py @@ -1081,10 +1081,10 @@ class TestBeforeTradingStart(TestCase): cls.trading_days[-1], 2, 50 ) - cls.minute_reader = BcolzMinuteBarReader(cls.tempdir.path) - cls.adj_reader = cls.create_adjustments_reader() + minute_reader = BcolzMinuteBarReader(cls.tempdir.path) + adj_reader = cls.create_adjustments_reader() - cls.daily_path = cls.tempdir.getpath("testdaily.bcolz") + daily_path = cls.tempdir.getpath("testdaily.bcolz") dfs = { 1: create_daily_df_for_asset(cls.env, cls.trading_days[0], cls.trading_days[-1]), @@ -1094,7 +1094,7 @@ class TestBeforeTradingStart(TestCase): cls.trading_days[-1]) } daily_writer = DailyBarWriterFromDataFrames(dfs) - daily_writer.write(cls.daily_path, cls.trading_days, dfs) + daily_writer.write(daily_path, cls.trading_days, dfs) cls.sim_params = SimulationParameters( period_start=cls.trading_days[1], @@ -1105,9 +1105,9 @@ class TestBeforeTradingStart(TestCase): cls.data_portal = DataPortal( env=cls.env, - equity_daily_reader=BcolzDailyBarReader(cls.daily_path), - equity_minute_reader=cls.minute_reader, - adjustment_reader=cls.adj_reader + equity_daily_reader=BcolzDailyBarReader(daily_path), + equity_minute_reader=minute_reader, + adjustment_reader=adj_reader ) @classmethod @@ -1147,6 +1147,8 @@ class TestBeforeTradingStart(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal + del cls.env cls.tempdir.cleanup() def test_data_in_bts_minute(self): @@ -1478,6 +1480,7 @@ class TestAlgoScript(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal del cls.env cls.tempdir.cleanup() teardown_logger(cls) @@ -1867,6 +1870,7 @@ class TestGetDatetime(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal del cls.env teardown_logger(cls) cls.tempdir.cleanup() @@ -1946,6 +1950,7 @@ class TestTradingControls(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal del cls.env cls.tempdir.cleanup() @@ -2362,6 +2367,7 @@ class TestAccountControls(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal del cls.env cls.tempdir.cleanup() @@ -2529,6 +2535,7 @@ class TestFutureFlip(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal cls.tempdir.cleanup() @skip @@ -2648,6 +2655,7 @@ class TestOrderCancelation(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal cls.tempdir.cleanup() @classmethod diff --git a/tests/test_api_shim.py b/tests/test_api_shim.py index 594a0a5a..b04fb09d 100644 --- a/tests/test_api_shim.py +++ b/tests/test_api_shim.py @@ -164,6 +164,11 @@ class TestAPIShim(TestCase): env=cls.env ) + @classmethod + def tearDownClass(cls): + del cls.adj_reader + cls.tempdir.cleanup() + @classmethod def build_daily_data(cls): path = cls.tempdir.getpath("testdaily.bcolz") @@ -217,10 +222,6 @@ class TestAPIShim(TestCase): return SQLiteAdjustmentReader(path) - @classmethod - def tearDownClass(cls): - cls.tempdir.cleanup() - def setUp(self): self.data_portal = DataPortal( self.env, @@ -229,6 +230,9 @@ class TestAPIShim(TestCase): adjustment_reader=self.adj_reader ) + def tearDown(self): + del self.data_portal + @classmethod def create_algo(cls, code, filename=None, sim_params=None): if sim_params is None: diff --git a/tests/test_bar_data.py b/tests/test_bar_data.py index bec4d34b..08ae9fdb 100644 --- a/tests/test_bar_data.py +++ b/tests/test_bar_data.py @@ -131,6 +131,8 @@ class TestMinuteBarData(TestBarDataBase): @classmethod def tearDownClass(cls): + del cls.data_portal + del cls.adjustments_reader cls.tempdir.cleanup() @classmethod @@ -564,6 +566,8 @@ class TestDailyBarData(TestBarDataBase): @classmethod def tearDownClass(cls): + del cls.data_portal + del cls.adjustments_reader cls.tempdir.cleanup() @classmethod diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index a0f6757b..2b2960f4 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -100,6 +100,7 @@ class TestBenchmark(TestCase): @classmethod def tearDownClass(cls): + del cls.data_portal del cls.env cls.tempdir.cleanup() diff --git a/tests/test_history.py b/tests/test_history.py index b205e34a..bb59ee03 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -108,11 +108,18 @@ class HistoryTestCaseBase(TestCase): cls.create_data() + @classmethod + def tearDownClass(cls): + del cls.adj_reader + cls.tempdir.cleanup() + def setUp(self): self.create_data_portal() - @classmethod - def create_data_portal(cls): + def tearDown(self): + del self.data_portal + + def create_data_portal(self): raise NotImplementedError() @classmethod @@ -169,10 +176,6 @@ class HistoryTestCaseBase(TestCase): } }) - @classmethod - def tearDownClass(cls): - cls.tempdir.cleanup() - @classmethod def create_adjustments_reader(cls): path = cls.tempdir.getpath("test_adjustments.db") @@ -470,12 +473,11 @@ MINUTE_FIELD_INFO = { class MinuteEquityHistoryTestCase(HistoryTestCaseBase): - @classmethod - def create_data_portal(cls): - cls.data_portal = DataPortal( - cls.env, - equity_minute_reader=BcolzMinuteBarReader(cls.tempdir.path), - adjustment_reader=cls.adj_reader + def create_data_portal(self): + self.data_portal = DataPortal( + self.env, + equity_minute_reader=BcolzMinuteBarReader(self.tempdir.path), + adjustment_reader=self.adj_reader ) @classmethod @@ -1016,15 +1018,14 @@ class MinuteEquityHistoryTestCase(HistoryTestCaseBase): class DailyEquityHistoryTestCase(HistoryTestCaseBase): - @classmethod - def create_data_portal(cls): - daily_path = cls.tempdir.getpath("testdaily.bcolz") + def create_data_portal(self): + daily_path = self.tempdir.getpath("testdaily.bcolz") - cls.data_portal = DataPortal( - cls.env, + self.data_portal = DataPortal( + self.env, equity_daily_reader=BcolzDailyBarReader(daily_path), - equity_minute_reader=BcolzMinuteBarReader(cls.tempdir.path), - adjustment_reader=cls.adj_reader + equity_minute_reader=BcolzMinuteBarReader(self.tempdir.path), + adjustment_reader=self.adj_reader ) @classmethod