-
Notifications
You must be signed in to change notification settings - Fork 10
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 #34 from sbesson/set_helpers
render set: helper refactoring
- Loading branch information
Showing
2 changed files
with
113 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# | ||
# Copyright (C) 2015-2018 University of Dundee & Open Microscopy Environment. | ||
# All rights reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
|
||
from omero.cli import CLI, NonZeroReturnCode | ||
from omero_cli_render import RenderControl | ||
|
||
import pytest | ||
import uuid | ||
import yaml | ||
|
||
|
||
def write_yaml(d, tmpdir): | ||
f = tmpdir.join(str(uuid.uuid4()) + ".yml") | ||
f.write(yaml.dump(d, explicit_start=True, width=80, indent=4, | ||
default_flow_style=False)) | ||
return str(f) | ||
|
||
|
||
class TestLoadRenderingSettings: | ||
def setup_method(self): | ||
self.cli = CLI() | ||
self.cli.register("render", RenderControl, "TEST") | ||
self.render = self.cli.controls['render'] | ||
|
||
def test_none(self): | ||
with pytest.raises(NonZeroReturnCode): | ||
self.render._load_rendering_settings(None) | ||
|
||
def test_non_existing_file(self): | ||
with pytest.raises(NonZeroReturnCode) as e: | ||
self.render._load_rendering_settings(str(uuid.uuid4()) + '.yml') | ||
assert e.value.rv == 103 | ||
|
||
def test_no_channels(self, tmpdir): | ||
d = {'version': 1} | ||
f = write_yaml(d, tmpdir) | ||
with pytest.raises(NonZeroReturnCode) as e: | ||
self.render._load_rendering_settings(f) | ||
assert e.value.rv == 104 | ||
|
||
def test_bad_version(self, tmpdir): | ||
d = {'channels': {1: {'label': 'foo'}}} | ||
f = write_yaml(d, tmpdir) | ||
with pytest.raises(NonZeroReturnCode) as e: | ||
self.render._load_rendering_settings(f) | ||
assert e.value.rv == 124 | ||
|
||
|
||
class TestReadChannels: | ||
def setup_method(self): | ||
self.cli = CLI() | ||
self.cli.register("render", RenderControl, "TEST") | ||
self.render = self.cli.controls['render'] | ||
|
||
def test_non_integer_channel(self): | ||
d = {'channels': {'GFP': {'label': 'foo'}}} | ||
with pytest.raises(NonZeroReturnCode) as e: | ||
self.render._read_channels(d) | ||
assert e.value.rv == 105 | ||
|
||
@pytest.mark.parametrize('key', ['min', 'max', 'start', 'end']) | ||
def test_float_keys(self, key): | ||
d = {'channels': {1: {key: 'foo'}}} | ||
with pytest.raises(NonZeroReturnCode) as e: | ||
self.render._read_channels(d) | ||
assert e.value.rv == 105 |