-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add behaviour tests for showing and saving datasets
Three scenarios were added, testing showing a dataset, saving a dataset, and bulk saving datasets (`save_datasets`). Signed-off-by: Martin Raspaud <martin.raspaud@smhi.se>
- Loading branch information
Showing
2 changed files
with
117 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,24 @@ | ||
# Created by a001673 at 2015-12-07 | ||
Feature: Simple and intuitive saving | ||
|
||
Visualization of the data is important and should be an easy one-line, like eg | ||
show(my_dataset). In a similar way, saving the data to disk should be simple, | ||
for example save(dataset, filename), with sensible defaults provided depending | ||
on the filename extension (eg. geotiff for .tif, netcdf for .nc). Saving | ||
several datasets at once would be nice to have. | ||
|
||
Scenario: 1-step showing dataset | ||
Given a dataset is available | ||
When the show command is called | ||
Then an image should pop up | ||
|
||
Scenario: 1-step saving dataset | ||
Given a dataset is available | ||
When the save_dataset command is called | ||
Then a file should be saved on disk | ||
|
||
Scenario: 1-step saving all datasets | ||
Given a bunch of datasets are available | ||
When the save_datasets command is called | ||
Then a bunch of files should be saved on disk | ||
|
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,93 @@ | ||
from behave import * | ||
from mock import patch | ||
|
||
use_step_matcher("re") | ||
|
||
|
||
@given("a dataset is available") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
from mpop.scene import Scene | ||
from datetime import datetime | ||
from mpop.projectable import Projectable | ||
scn = Scene(platform_name="Suomi-NPP", sensor="viirs", | ||
start_time=datetime(2015, 3, 11, 11, 20), | ||
end_time=datetime(2015, 3, 11, 11, 26)) | ||
scn["MyDataset"] = Projectable([[1, 2], [3, 4]]) | ||
context.scene = scn | ||
|
||
|
||
@when("the show command is called") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
with patch('trollimage.image.Image.show') as mock_show: | ||
context.scene.show("MyDataset") | ||
mock_show.assert_called_once_with() | ||
|
||
|
||
@then("an image should pop up") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
pass | ||
|
||
|
||
@when("the save_dataset command is called") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
context.filename = "/tmp/test_dataset.png" | ||
context.scene.save_dataset("MyDataset", context.filename) | ||
|
||
|
||
@then("a file should be saved on disk") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
import os | ||
assert(os.path.exists(context.filename)) | ||
os.remove(context.filename) | ||
|
||
|
||
@given("a bunch of datasets are available") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
from mpop.scene import Scene | ||
from datetime import datetime | ||
from mpop.projectable import Projectable | ||
scn = Scene(platform_name="Suomi-NPP", sensor="viirs", | ||
start_time=datetime(2015, 3, 11, 11, 20), | ||
end_time=datetime(2015, 3, 11, 11, 26)) | ||
scn["MyDataset"] = Projectable([[1, 2], [3, 4]]) | ||
scn["MyDataset2"] = Projectable([[5, 6], [7, 8]]) | ||
context.scene = scn | ||
|
||
|
||
|
||
@when("the save_datasets command is called") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
context.scene.save_datasets(writer="simple_image", file_pattern="{name}.png") | ||
|
||
|
||
|
||
@then("a bunch of files should be saved on disk") | ||
def step_impl(context): | ||
""" | ||
:type context: behave.runner.Context | ||
""" | ||
import os | ||
for filename in ["MyDataset.png", "MyDataset2.png"]: | ||
assert(os.path.exists(filename)) | ||
os.remove(filename) |