-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for functions from a specific python file are grouped together in the same structure under unit tests, larger workflow tests are add in e2e testing
- Loading branch information
1 parent
c4b8df7
commit 6b1e773
Showing
7 changed files
with
192 additions
and
225 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,54 @@ | ||
####################################################### | ||
# Unit tests for ../pipeline/base.py | ||
####################################################### | ||
|
||
import os | ||
import tempfile | ||
|
||
from scportrait.pipeline._base import Logable, ProcessingStep | ||
|
||
|
||
def test_logable_init(): | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
logable = Logable(directory=temp_dir, debug=False) | ||
assert not logable.debug | ||
|
||
|
||
def test_logable_log(): | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
logable = Logable(directory=temp_dir, debug=True) | ||
logable.log("Testing") | ||
|
||
log_path = os.path.join(temp_dir, logable.DEFAULT_LOG_NAME) | ||
assert os.path.isfile(log_path) | ||
|
||
with open(log_path) as f: | ||
log_content = f.read() | ||
assert "Testing" in log_content | ||
|
||
|
||
def test_processing_step_init(): | ||
config = {"setting1": "value1"} | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
processing_step = ProcessingStep(config, f"{temp_dir}/test_step", temp_dir, debug=True) | ||
|
||
assert processing_step.debug | ||
assert config == processing_step.config | ||
|
||
|
||
def test_processing_step_register_parameter(): | ||
config = {"setting1": "value1"} | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
processing_step = ProcessingStep(config, f"{temp_dir}/test_step", temp_dir) | ||
|
||
# Test registering a new parameter | ||
processing_step.register_parameter("setting2", "value2") | ||
assert "setting2" in processing_step.config | ||
assert "value2" == processing_step.config["setting2"] | ||
|
||
|
||
def test_processing_step_get_directory(): | ||
config = {"setting1": "value1"} | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
processing_step = ProcessingStep(config, f"{temp_dir}/test_step", temp_dir) | ||
assert f"{temp_dir}/test_step" == processing_step.get_directory() |
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
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,11 @@ | ||
####################################################### | ||
# Unit tests for ../pipeline/_utils/helper.py | ||
####################################################### | ||
|
||
from scportrait.pipeline._utils.helper import flatten | ||
|
||
|
||
def test_flatten(): | ||
nested_list = [[1, 2, 3], [4, 5], [6, 7, 8, 9]] | ||
expected_output = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
assert flatten(nested_list) == expected_output |
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,34 @@ | ||
####################################################### | ||
# Unit tests for ../plotting/vis.py | ||
####################################################### | ||
import os | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from scportrait.plotting.vis import plot_image, visualize_class | ||
|
||
|
||
def test_visualize_class(): | ||
class_ids = [1, 2] | ||
seg_map = np.array([[0, 1, 0], [1, 2, 1], [2, 0, 1]]) | ||
rng = np.random.default_rng() | ||
background = rng.random((3, 3)) * 255 | ||
# Since this function does not return anything, we just check if it produces any exceptions | ||
try: | ||
visualize_class(class_ids, seg_map, background) | ||
except (ValueError, TypeError) as e: | ||
pytest.fail(f"visualize_class raised exception: {str(e)}") | ||
|
||
|
||
def test_plot_image(tmpdir): | ||
rng = np.random.default_rng() | ||
array = rng.random((10, 10)) | ||
save_name = tmpdir.join("test_plot_image") | ||
|
||
# Since this function does not return anything, we just check if it produces any exceptions | ||
try: | ||
plot_image(array, size=(5, 5), save_name=save_name) | ||
except (OSError, ValueError, TypeError) as e: | ||
pytest.fail(f"plot_image raised exception: {str(e)}") | ||
assert os.path.isfile(str(save_name) + ".png") |
Oops, something went wrong.