Skip to content

Commit

Permalink
Patch _override_tempdir globally
Browse files Browse the repository at this point in the history
I think that was effectively what was done prior to 28f0210
  • Loading branch information
mvdbeek committed Mar 1, 2022
1 parent 5bb1095 commit 598c2dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
20 changes: 5 additions & 15 deletions test/unit/config/test_config_dataset_storage.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import os.path

import pytest

from galaxy import config
from galaxy.config import BaseAppConfiguration


@pytest.fixture
def mock_config_file(monkeypatch):
# Patch this; otherwise tempfile.tempdir will be set, which is a global variable that
# defines the value of the default `dir` argument to the functions in Python's
# tempfile module - which breaks multiple tests.
monkeypatch.setattr(config.GalaxyAppConfiguration, '_override_tempdir', lambda a, b: None)


def test_object_store_store_by_set(mock_config_file, monkeypatch):
def test_object_store_store_by_set():
# object_store_store_by set by admin
appconfig = config.GalaxyAppConfiguration(object_store_store_by='id')
assert appconfig.object_store_store_by == 'id'


def test_uuid_1(mock_config_file, monkeypatch):
def test_uuid_1():
# object_store_store_by not set
# file_path set by admin to `objects` (no need for the dir to exist)
appconfig = config.GalaxyAppConfiguration(file_path='objects')

assert appconfig.object_store_store_by == 'uuid'


def test_uuid_2(mock_config_file, monkeypatch):
def test_uuid_2(monkeypatch):
# object_store_store_by not set
# file_path not set, `files` dir doesn't exist
monkeypatch.setattr(BaseAppConfiguration, '_path_exists', lambda self, path: False)
Expand All @@ -37,15 +27,15 @@ def test_uuid_2(mock_config_file, monkeypatch):
assert appconfig.object_store_store_by == 'uuid'


def test_id_1(mock_config_file, monkeypatch):
def test_id_1():
# object_store_store_by not set
# file_path set by admin to `not_objects` (no need for the dir to exist)
appconfig = config.GalaxyAppConfiguration(file_path='not_objects')

assert appconfig.object_store_store_by == 'id'


def test_id_2(mock_config_file, monkeypatch):
def test_id_2(monkeypatch):
# object_store_store_by not set
# file_path not set, `files` dir exists
monkeypatch.setattr(BaseAppConfiguration, '_path_exists', lambda self, path: True if os.path.basename(path) == 'files' else False)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging
from unittest import mock

import pytest

log = logging.getLogger(__name__)


@pytest.fixture(scope="session", autouse=True)
def default_session_fixture(request):
"""
:type request: _pytest.python.SubRequest
:return:
"""
log.info("Patching galaxy.config.GalaxyAppConfiguration._override_tempdir")
patched = mock.patch('galaxy.config.GalaxyAppConfiguration._override_tempdir', lambda a, b: None)
patched.__enter__()

def unpatch():
patched.__exit__()
log.info("Patching complete. Unpatching")

request.addfinalizer(unpatch)
2 changes: 0 additions & 2 deletions test/unit/webapps/test_config_values.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from collections import namedtuple
from datetime import timedelta
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -226,7 +225,6 @@ def get_expected_object_store_store_by(self, value):
return 'uuid'


@patch('galaxy.config.GalaxyAppConfiguration._override_tempdir', lambda a, b: None)
def get_config_data():
configuration = config.GalaxyAppConfiguration()
ev = ExpectedValues(configuration)
Expand Down

0 comments on commit 598c2dc

Please sign in to comment.