BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
test_settings.py
1#!/usr/bin/env python3
2
3
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()