Skip to content

Commit

Permalink
Modified some mongo dict defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ga84jog committed Oct 23, 2024
1 parent 05d052e commit 90024fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
- driver: nvidia
count: 1
capabilities: [gpu]
volumes:
- ..:/workdir:cached
depends_on:
- mongodb
networks:
Expand Down
5 changes: 3 additions & 2 deletions src/storable/decorator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pymongo import MongoClient
from typing import Any, Dict, Tuple, List
from functools import wraps
Expand Down Expand Up @@ -202,7 +203,7 @@ def print_db(self):
print(f'{key}: {value}')
print("===== End Printing =====")

def db_exists(self, _db_name, host='localhost', port=27017):
def db_exists(self, _db_name, host=os.getenv("MONGODB_HOST"), port=None):
_db_name = MongoDict._sanitize_db_name(_db_name)
client = MongoClient(host, port)
try:
Expand All @@ -212,7 +213,7 @@ def db_exists(self, _db_name, host='localhost', port=27017):
finally:
client.close()

def delete_db(self, _db_name, host='localhost', port=27017):
def delete_db(self, _db_name, host=os.getenv("MONGODB_HOST"), port=None):
# Delete the specified database
_db_name = MongoDict._sanitize_db_name(_db_name)
client = MongoClient(host, port)
Expand Down
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datasets
import ray
import os
from pathlib import Path
from tests.tsettings import *
from typing import Dict
from utils.IO import *
Expand All @@ -25,9 +26,15 @@ def pytest_configure(config) -> None:
os.environ["DEBUG"] = "0"

if SEMITEMP_DIR.is_dir() and not config.getoption("--no-cleanup"):
shutil.rmtree(str(SEMITEMP_DIR))
for item in SEMITEMP_DIR.iterdir():
if item.name != '.gitignore':
if item.is_file():
item.unlink()
elif item.is_dir():
shutil.rmtree(str(item))

for task_name in TASK_NAMES:
print(Path.cwd())
tests_io(f"Loading preproceesing data for task {task_name}...", end="\r")
datasets.load_data(chunksize=75835,
source_path=TEST_DATA_DEMO,
Expand Down Expand Up @@ -152,4 +159,9 @@ def discretizer_listfiles() -> None:
def pytest_unconfigure(config) -> None:
os.environ["DEBUG"] = "0"
if SEMITEMP_DIR.is_dir() and not config.getoption("--no-cleanup"):
shutil.rmtree(str(SEMITEMP_DIR))
for item in SEMITEMP_DIR.iterdir():
if item.name != '.gitignore':
if item.is_file():
item.unlink()
elif item.is_dir():
shutil.rmtree(str(item))
2 changes: 1 addition & 1 deletion tests/test_datasets/test_trackers/test_mongo_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_db_name_handling():
tests_io("Starting test_db_sanitization_and_collection_handling", level=0)

# Test with a long path
db_path = Path(TEMP_DIR, "workspaces/pymimic3/tests/data/semitemp/processed/DECOMP_progress")
db_path = Path(TEMP_DIR, "workdir/tests/data/semitemp/processed/DECOMP_progress")
db = MongoDict(db_path)
assert db._db_name == 'db_paces_pymimic3_tests_data_semitemp_processed_DECOMP_progress'

Expand Down

0 comments on commit 90024fc

Please sign in to comment.