BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
test_settings.py
1#!/usr/bin/env python3
2
3## Copyright (C) 2020 David Miguel Susano Pinto <carandraug@gmail.com>
4##
5## This file is part of Microscope.
6##
7## Microscope is free software: you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation, either version 3 of the License, or
10## (at your option) any later version.
11##
12## Microscope is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with Microscope. If not, see <http://www.gnu.org/licenses/>.
19
20"""Tests for the microscope devices settings.
21"""
22
23import enum
24import unittest
25
26import microscope.abc
27
28
29class EnumSetting(enum.Enum):
30 A = 0
31 B = 1
32 C = 2
33
34
36 """Very simple container with setter and getter methods"""
37
38 def __init__(self, val):
39 self.val = val
40
41 def set_val(self, val):
42 self.val = val
43
44 def get_val(self):
45 return self.val
46
47
48def create_enum_setting(default, with_getter=True, with_setter=True):
49 thing = ThingWithSomething(EnumSetting(default))
50 getter = thing.get_val if with_getter else None
51 setter = thing.set_val if with_setter else None
53 "foobar", "enum", get_func=getter, set_func=setter, values=EnumSetting
54 )
55 return setting, thing
56
57
58class TestEnumSetting(unittest.TestCase):
60 """For enums, get() returns the enum value not the enum instance"""
61 setting, thing = create_enum_setting(1)
62 self.assertIsInstance(setting.get(), int)
63
65 """For enums, set() sets an enum instance, not the enum value"""
66 setting, thing = create_enum_setting(1)
67 setting.set(2)
68 self.assertIsInstance(thing.val, EnumSetting)
69 self.assertEqual(thing.val, EnumSetting(2))
70
72 """get() works for write-only enum settings"""
73 setting, thing = create_enum_setting(1, with_getter=False)
74 self.assertEqual(EnumSetting(1), thing.val)
75 setting.set(2)
76 self.assertEqual(setting.get(), 2)
77 self.assertEqual(EnumSetting(2), thing.val)
78
79
80if __name__ == "__main__":
81 unittest.main()