diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 67c0a3f..be71e3f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -14,6 +14,8 @@ services: - driver: nvidia count: 1 capabilities: [gpu] + volumes: + - ..:/workdir:cached depends_on: - mongodb networks: diff --git a/src/storable/decorator.py b/src/storable/decorator.py index 7c585d6..5487778 100644 --- a/src/storable/decorator.py +++ b/src/storable/decorator.py @@ -1,3 +1,4 @@ +import os from pymongo import MongoClient from typing import Any, Dict, Tuple, List from functools import wraps @@ -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: @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index fa7a916..70557c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 * @@ -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, @@ -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)) diff --git a/tests/test_datasets/test_trackers/test_mongo_dict.py b/tests/test_datasets/test_trackers/test_mongo_dict.py index 78105f1..d14b868 100644 --- a/tests/test_datasets/test_trackers/test_mongo_dict.py +++ b/tests/test_datasets/test_trackers/test_mongo_dict.py @@ -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'