1
|
|
|
import unittest |
2
|
|
|
|
3
|
|
|
from coalib.bearlib.abstractions.SectionCreatable import SectionCreatable |
4
|
|
|
from coalib.settings.Section import Section, Setting |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestObject(SectionCreatable): |
8
|
|
|
|
9
|
|
|
def __init__(self, |
10
|
|
|
setting_one: int, |
11
|
|
|
raw_setting, |
12
|
|
|
setting_two: bool=False, |
13
|
|
|
setting_three: list=[1, 2], |
14
|
|
|
opt_raw_set=5): |
15
|
|
|
SectionCreatable.__init__(self) |
16
|
|
|
assert isinstance(setting_one, int) |
17
|
|
|
assert isinstance(raw_setting, Setting) |
18
|
|
|
assert isinstance(setting_two, bool) |
19
|
|
|
assert isinstance(setting_three, list) |
20
|
|
|
assert isinstance(opt_raw_set, Setting) or isinstance(opt_raw_set, int) |
21
|
|
|
|
22
|
|
|
self.setting_one = setting_one |
23
|
|
|
self.raw_setting = raw_setting |
24
|
|
|
self.setting_two = setting_two |
25
|
|
|
self.setting_three = setting_three |
26
|
|
|
self.opt_raw_set = opt_raw_set |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
class SectionCreatableTest(unittest.TestCase): |
30
|
|
|
|
31
|
|
|
def test_api(self): |
32
|
|
|
uut = SectionCreatable() |
33
|
|
|
self.assertEqual(uut.get_non_optional_settings(), {}) |
34
|
|
|
self.assertEqual(uut.get_optional_settings(), {}) |
35
|
|
|
|
36
|
|
|
def test_needed_settings(self): |
37
|
|
|
self.assertEqual(sorted(list(TestObject.get_non_optional_settings())), |
38
|
|
|
sorted(["setting_one", "raw_setting"])) |
39
|
|
|
self.assertEqual( |
40
|
|
|
sorted(list(TestObject.get_optional_settings())), |
41
|
|
|
sorted(["setting_two", "setting_three", "opt_raw_set"])) |
42
|
|
|
|
43
|
|
|
def test_from_section(self): |
44
|
|
|
section = Section("name") |
45
|
|
|
section.append(Setting("setting_one", " 5")) |
46
|
|
|
section.append(Setting("raw_setting", " 5s")) |
47
|
|
|
uut = TestObject.from_section(section) |
48
|
|
|
self.assertEqual(uut.setting_one, 5) |
49
|
|
|
self.assertEqual(str(uut.raw_setting), "5s") |
50
|
|
|
self.assertEqual(uut.setting_two, False) |
51
|
|
|
self.assertEqual(uut.setting_three, [1, 2]) |
52
|
|
|
self.assertEqual(str(uut.opt_raw_set), "5") |
53
|
|
|
|
54
|
|
|
section.append(Setting("setting_three", "2, 4")) |
55
|
|
|
section.append(Setting("opt_raw_set", "tst ,")) |
56
|
|
|
uut = TestObject.from_section(section) |
57
|
|
|
self.assertEqual(uut.setting_one, 5) |
58
|
|
|
self.assertEqual(str(uut.raw_setting), "5s") |
59
|
|
|
self.assertEqual(uut.setting_two, False) |
60
|
|
|
self.assertEqual(uut.setting_three, ["2", "4"]) |
61
|
|
|
self.assertEqual(str(uut.opt_raw_set), "tst ,") |
62
|
|
|
|