Skip to content

Commit

Permalink
Revert "Make a Dwh class singleton instead of creating a child class"
Browse files Browse the repository at this point in the history
This reverts commit 7bef033.
  • Loading branch information
Dawid Makar committed Mar 13, 2024
1 parent 7bef033 commit 84e9a8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/pyprediktorutilities/dwh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions tests/test_dwh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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

0 comments on commit 84e9a8e

Please sign in to comment.