From 84e9a8e915259eac835179165cdcc2ab854cffff Mon Sep 17 00:00:00 2001 From: Dawid Makar Date: Wed, 13 Mar 2024 11:01:09 +0100 Subject: [PATCH] Revert "Make a Dwh class singleton instead of creating a child class" This reverts commit 7bef0339938787e3cb8007bb8a3e6c7b7eba792a. --- src/pyprediktorutilities/dwh.py | 10 +++++++++- tests/test_dwh.py | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pyprediktorutilities/dwh.py b/src/pyprediktorutilities/dwh.py index 0b86177..a353746 100644 --- a/src/pyprediktorutilities/dwh.py +++ b/src/pyprediktorutilities/dwh.py @@ -10,7 +10,7 @@ logger.addHandler(logging.NullHandler()) -class Dwh(metaclass=singleton_class.SingletonMeta): +class Dwh: """Access a PowerView Data Warehouse or other SQL databases. Args: @@ -304,3 +304,11 @@ def __disconnect(self) -> None: def __commit(self) -> None: """Commits any changes to the database.""" self.connection.commit() + + +class DwhSingleton(Dwh, metaclass=singleton_class.SingletonMeta): + pass + + +def get_dwh_instance(*args, **kwargs): + return DwhSingleton(*args, **kwargs) diff --git a/tests/test_dwh.py b/tests/test_dwh.py index 3669704..8630d83 100644 --- a/tests/test_dwh.py +++ b/tests/test_dwh.py @@ -6,7 +6,7 @@ import pandas as pd from unittest.mock import Mock -from pyprediktorutilities.dwh import Dwh +from pyprediktorutilities.dwh import Dwh, get_dwh_instance from pandas.testing import assert_frame_equal """ @@ -797,10 +797,10 @@ def test_dwh_singleton_can_be_created_only_once(monkeypatch): "pyprediktorutilities.dwh.pyodbc.connect", mock_pyodbc_connection ) - db = Dwh(grs(), grs(), grs(), grs(), driver_index) + db = get_dwh_instance(grs(), grs(), grs(), grs(), driver_index) db_instance_address = id(db) - db_2 = Dwh(grs(), grs(), grs(), grs(), driver_index) + db_2 = get_dwh_instance(grs(), grs(), grs(), grs(), driver_index) db_2_instance_address = id(db_2) assert db_instance_address == db_2_instance_address