Skip to content

Commit

Permalink
fix tests to work without docker enabled as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
asampat3090 committed Jun 27, 2018
1 parent 36475f0 commit 56576d5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
Expand Up @@ -34,7 +34,7 @@ def to_bytes(val):
EnvironmentRequirementsCreateError, EnvironmentImageNotFound,
EnvironmentContainerNotFound, PathDoesNotExist, EnvironmentDoesNotExist,
EnvironmentExecutionError)
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation
from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None
Expand All @@ -60,7 +60,8 @@ def setup_method(self):
f.write(to_bytes(str("RUN echo " + self.random_text)))

def teardown_method(self):
self.docker_environment_driver.remove(self.image_name, force=True)
if not check_docker_inactive(test_datmo_dir):
self.docker_environment_driver.remove(self.image_name, force=True)

def test_instantiation(self):
assert self.docker_environment_driver != None
Expand Down
13 changes: 7 additions & 6 deletions datmo/core/controller/environment/tests/test_environment.py
Expand Up @@ -34,7 +34,7 @@ def to_bytes(val):
EntityNotFound, RequiredArgumentMissing, TooManyArgumentsFound,
FileAlreadyExistsError, UnstagedChanges, EnvironmentDoesNotExist,
ProjectNotInitialized, EnvironmentExecutionError)
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation
from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None
Expand All @@ -49,11 +49,12 @@ def setup_method(self):
self.environment_ids = []

def teardown_method(self):
if self.project_controller.is_initialized:
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception
if not check_docker_inactive(test_datmo_dir):
if self.project_controller.is_initialized:
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception

def __setup(self):
self.project_controller.init("test_setup", "test description")
Expand Down
16 changes: 9 additions & 7 deletions datmo/core/controller/tests/test_project.py
Expand Up @@ -36,7 +36,7 @@ def to_bytes(val):
from datmo.core.entity.snapshot import Snapshot
from datmo.core.entity.task import Task
from datmo.core.util.exceptions import ValidationFailed
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation
from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None
Expand All @@ -51,12 +51,13 @@ def setup_method(self):
self.environment_ids = []

def teardown_method(self):
self.project_controller = ProjectController()
if self.project_controller.is_initialized:
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception
if not check_docker_inactive(test_datmo_dir):
self.project_controller = ProjectController()
if self.project_controller.is_initialized:
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception

def test_init_failure_none(self):
# Test failed case
Expand Down Expand Up @@ -230,6 +231,7 @@ def test_status_basic(self):
assert ascending_unstaged_task_list
assert updated_first_task in ascending_unstaged_task_list

@pytest_docker_environment_failed_instantiation(test_datmo_dir)
def test_status_snapshot_task(self):
self.project_controller.init("test4", "test description")
self.snapshot_controller = SnapshotController()
Expand Down
13 changes: 7 additions & 6 deletions datmo/core/controller/tests/test_snapshot.py
Expand Up @@ -32,7 +32,7 @@ def to_bytes(val):
EntityNotFound, SessionDoesNotExist, RequiredArgumentMissing,
TaskNotComplete, InvalidArgumentType, ProjectNotInitialized,
InvalidProjectPath, DoesNotExist)
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation
from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None
Expand All @@ -46,11 +46,12 @@ def setup_method(self):
self.environment_ids = []

def teardown_method(self):
self.__setup()
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception
if not check_docker_inactive(test_datmo_dir):
self.__setup()
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception

def __setup(self):
Config().set_home(self.temp_dir)
Expand Down
13 changes: 7 additions & 6 deletions datmo/core/controller/tests/test_task.py
Expand Up @@ -31,7 +31,7 @@ def to_bytes(val):
from datmo.core.util.exceptions import EntityNotFound, TaskRunError, \
InvalidArgumentType, RequiredArgumentMissing, ProjectNotInitialized, \
InvalidProjectPath, TooManyArgumentsFound, DoesNotExist
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation
from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
tempfile.tempdir = "/tmp" if not platform.system() == "Windows" else None
Expand All @@ -44,11 +44,12 @@ def setup_method(self):
self.environment_ids = []

def teardown_method(self):
self.__setup()
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception
if not check_docker_inactive(test_datmo_dir):
self.__setup()
self.environment_controller = EnvironmentController()
for env_id in list(set(self.environment_ids)):
if not self.environment_controller.delete(env_id):
raise Exception

def __setup(self):
Config().set_home(self.temp_dir)
Expand Down

0 comments on commit 56576d5

Please sign in to comment.