-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests and use the label part in PandA
- Loading branch information
Tom
authored and
Tom
committed
Jul 28, 2017
1 parent
fc4a297
commit c9ae6ed
Showing
5 changed files
with
88 additions
and
4 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,25 @@ | ||
import unittest | ||
|
||
from malcolm.core import call_with_params | ||
from malcolm.modules.builtin.parts import GroupPart | ||
|
||
|
||
class TestGroupPart(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.o = call_with_params( | ||
GroupPart, name="things", description="A group of things") | ||
self.setter = list(self.o.create_attribute_models())[0][2] | ||
|
||
def test_init(self): | ||
assert self.o.name == "things" | ||
assert self.o.attr.value == "expanded" | ||
assert self.o.attr.meta.description == "A group of things" | ||
assert self.o.attr.meta.tags == ("widget:group", "config") | ||
|
||
def test_setter(self): | ||
assert self.o.attr.value == "expanded" | ||
self.setter("collapsed") | ||
assert self.o.attr.value == "collapsed" | ||
with self.assertRaises(ValueError): | ||
self.setter("anything else") |
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,22 @@ | ||
import unittest | ||
|
||
from malcolm.core import call_with_params | ||
from malcolm.modules.builtin.parts import IconPart | ||
|
||
|
||
class TestIconPart(unittest.TestCase): | ||
|
||
def setUp(self): | ||
svg_name = "/tmp/test_icon.svg" | ||
self.svg_text = '<svg><rect width="300" height="100"/></svg>' | ||
with open(svg_name, "w") as f: | ||
f.write(self.svg_text) | ||
self.o = call_with_params( | ||
IconPart, svg=svg_name) | ||
list(self.o.create_attribute_models()) | ||
|
||
def test_init(self): | ||
assert self.o.name == "icon" | ||
assert self.o.attr.value == self.svg_text | ||
assert self.o.attr.meta.description == "SVG icon for Block" | ||
assert self.o.attr.meta.tags == ("widget:icon",) |
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,32 @@ | ||
import unittest | ||
from mock import MagicMock | ||
|
||
from malcolm.core import call_with_params, Controller, Process | ||
from malcolm.modules.builtin.parts import LabelPart | ||
|
||
|
||
class TestLabelPart(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.o = call_with_params( | ||
LabelPart, initialValue="My label", group="mygroup") | ||
self.p = Process("proc") | ||
self.c = Controller(self.p, "mri", [self.o]) | ||
self.p.add_controller("mri", self.c) | ||
self.p.start() | ||
self.b = self.c.block_view() | ||
|
||
def tearDown(self): | ||
self.p.stop(1) | ||
|
||
def test_init(self): | ||
assert self.o.name == "label" | ||
assert self.o.attr.value == "My label" | ||
assert self.o.attr.meta.tags == ( | ||
"widget:textinput", "config", "group:mygroup") | ||
assert self.b.meta.label == "My label" | ||
|
||
def test_setter(self): | ||
self.b.label.put_value("My label2") | ||
assert self.b.label.value == "My label2" | ||
assert self.b.meta.label == "My label2" |
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