-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from contextlib import contextmanager | ||
from os.path import isfile, join | ||
import shutil | ||
import tempfile | ||
|
||
from numpy.testing import assert_allclose | ||
|
||
from ensemble.ctf.editor import ALPHA_DEFAULT, COLOR_DEFAULT, create_function | ||
from ensemble.ctf.manager import CTF_EXTENSION, CtfManager | ||
|
||
|
||
@contextmanager | ||
def temp_directory(): | ||
tempdir = tempfile.mkdtemp(suffix='', prefix='tmp', dir=None) | ||
try: | ||
yield tempdir | ||
finally: | ||
shutil.rmtree(tempdir) | ||
|
||
|
||
def sample_function_parts(): | ||
return create_function(COLOR_DEFAULT), create_function(ALPHA_DEFAULT) | ||
|
||
|
||
def test_ctf_manager_add(): | ||
name = 'test_function' | ||
color_func, alpha_func = sample_function_parts() | ||
|
||
with temp_directory() as root_dir: | ||
manager = CtfManager.from_directory(root_dir) | ||
manager.add(name, color_func, alpha_func) | ||
|
||
assert isfile(join(root_dir, name + CTF_EXTENSION)) | ||
|
||
|
||
def test_ctf_manager_get(): | ||
color_func, alpha_func = sample_function_parts() | ||
|
||
with temp_directory() as root_dir: | ||
manager = CtfManager.from_directory(root_dir) | ||
manager.add('test', color_func, alpha_func) | ||
|
||
ret_color, ret_alpha = manager.get('test') | ||
assert_allclose(ret_color.values(), COLOR_DEFAULT) | ||
assert_allclose(ret_alpha.values(), ALPHA_DEFAULT) | ||
|
||
|
||
def test_ctf_manager_load(): | ||
color_func, alpha_func = sample_function_parts() | ||
|
||
with temp_directory() as root_dir: | ||
manager = CtfManager.from_directory(root_dir) | ||
manager.add('test', color_func, alpha_func) | ||
|
||
del manager | ||
manager = CtfManager.from_directory(root_dir) | ||
manager.get('test') |