Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repr to dbs to help debug with orion db test #958

Merged
merged 4 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/orion/core/io/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(
self._conn = None
self.initiate_connection()

def __repr__(self) -> str:
return f"{type(self).__qualname__}(host={self.host})"

@property
@abstractmethod
def is_connected(self):
Expand Down
3 changes: 3 additions & 0 deletions src/orion/core/io/database/ephemeraldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class EphemeralDB(Database):

"""

def __repr__(self) -> str:
return f"{type(self).__qualname__}()"

@property
def is_connected(self):
"""Return true, always."""
Expand Down
8 changes: 8 additions & 0 deletions src/orion/core/io/database/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def __init__(
authSource=name,
)

def __repr__(self) -> str:
name = type(self).__qualname__
args = ", ".join(
f"{name}={getattr(self, name)}"
for name in ["host", "name", "port", "username", "password", "options"]
)
return f"{name}({args})"

def __getstate__(self):
state = {}
for key in ["host", "name", "port", "username", "password", "options"]:
Expand Down
3 changes: 3 additions & 0 deletions src/orion/core/io/database/pickleddb.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def __init__(self, host="", timeout=60, *args, **kwargs):
if os.path.dirname(host):
os.makedirs(os.path.dirname(host), exist_ok=True)

def __repr__(self) -> str:
return f"{type(self).__qualname__}(host={self.host}, timeout={self.timeout})"

@property
def is_connected(self):
"""Return true, always."""
Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/core/database/test_ephemeraldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def collection(document, db_type):
# TESTS SET


def test_repr(orion_db: EphemeralDB):
assert str(orion_db) == f"EphemeralDB()"


@pytest.mark.usefixtures("clean_db")
class TestIndex(object):
"""Test index for :meth:`orion.core.io.database.ephemeraldb.EphemeralCollection`."""
Expand Down
7 changes: 7 additions & 0 deletions tests/unittests/core/database/test_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,10 @@ def test_non_converted_errors(self, orion_db, test_collection):

with pytest.raises(pymongo.errors.OperationFailure):
orion_db.read_and_write("test_collection", query, config_to_add)


def test_repr(orion_db: MongoDB):
assert str(orion_db) == (
f"MongoDB(host=localhost, name=orion_test, port=27017, username=user, "
f"password=pass, options={orion_db.options})"
)
6 changes: 6 additions & 0 deletions tests/unittests/core/database/test_pickleddb.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,9 @@ def _get_fs(path):
monkeypatch.setattr("orion.core.io.database.pickleddb._get_fs", _get_fs)

assert isinstance(_create_lock("/whatever/the/path/is"), file_lock_class)


def test_repr(orion_db: PickledDB):
assert (
str(orion_db) == f"PickledDB(host={orion_db.host}, timeout={orion_db.timeout})"
)