-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jobar8/jobar8/issue7
New Export to image file dialogue
- Loading branch information
Showing
4 changed files
with
105 additions
and
12 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
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
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
"""Tests for the shared.py module.""" | ||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import datashader as ds | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from attractor_explorer.shared import render_attractor | ||
from attractor_explorer.shared import render_attractor, save_image | ||
|
||
|
||
def test_render(): | ||
trajectory = pd.DataFrame(np.random.default_rng().random((30, 2)), columns=list('xy')) | ||
image = list(render_attractor(trajectory, plot_type='points', cmap=None, size=400)) | ||
assert isinstance(image[0], ds.tf.Image) | ||
|
||
|
||
@patch('attractor_explorer.shared.ds.tf.set_background') | ||
def test_save_image(mock_set_background): | ||
# Mocking the image object | ||
mock_img = MagicMock() | ||
mock_output_image = MagicMock() | ||
mock_set_background.return_value = mock_output_image | ||
mock_output_image.to_pil.return_value.save = MagicMock() | ||
|
||
output_path = 'test_output.png' | ||
color = 'blue' | ||
|
||
save_image(mock_img, output_path, color) | ||
mock_set_background.assert_called_once_with(mock_img, color=color) | ||
mock_output_image.to_pil.return_value.save.assert_called_once_with(output_path, format='png') |