Skip to content

Commit c4bf483

Browse files
committed
Add validation tests
1 parent 7d27b89 commit c4bf483

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from techui_builder.builder import Builder, JsonMap
77
from techui_builder.generate import Generator
8+
from techui_builder.validator import Validator
89

910

1011
@pytest.fixture
@@ -46,3 +47,11 @@ def generator():
4647
g = Generator(synoptic_dir)
4748

4849
return g
50+
51+
52+
@pytest.fixture
53+
def validator():
54+
test_bobs = [Path("tests/test_files/motor-edited.bob")]
55+
v = Validator(test_bobs)
56+
57+
return v

tests/test_files/motor-edited.bob

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--Saved on 1970-01-01 00:00:01 by TESTER-->
3+
<display version="2.0.0">
4+
<name>motor</name>
5+
<widget type="group" version="2.0.0">
6+
<name>motor</name>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>255</width>
10+
<height>470</height>
11+
<widget type="embedded" version="2.0.0">
12+
<name>X</name>
13+
<width>205</width>
14+
<height>120</height>
15+
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
16+
<macros>
17+
<P>BL01T-MO-MOTOR-01</P>
18+
<M>X</M>
19+
</macros>
20+
<x>0</x>
21+
<y>0</y>
22+
</widget>
23+
</widget>
24+
</display>

tests/test_files/motor.bob

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<name>X</name>
1212
<width>205</width>
1313
<height>120</height>
14-
<file>../../../../src/techui-support/bob/pmac/motor_embed.bob</file>
14+
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
1515
<macros>
1616
<P>BL01T-MO-MOTOR-01</P>
1717
<M>X</M>
@@ -23,7 +23,7 @@
2323
<name>A</name>
2424
<width>205</width>
2525
<height>120</height>
26-
<file>../../../../src/techui-support/bob/pmac/motor_embed.bob</file>
26+
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
2727
<macros>
2828
<P>BL01T-MO-MOTOR-01</P>
2929
<M>A</M>
@@ -43,7 +43,7 @@
4343
<macros>
4444
<P>BL01T-MO-BRICK-01</P>
4545
</macros>
46-
<file>../../../../src/techui-support/bob/pmac/pmacController.bob</file>
46+
<file>example/t01-services/synoptic/techui-support/bob/pmac/pmacController.bob</file>
4747
<target>tab</target>
4848
</action>
4949
</actions>

tests/test_files/motor_bad.bob

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<name>X</name>
1010
<width>205</width>
1111
<height>120</height>
12-
<file>../../../../src/techui-support/bob/pmac/motor_embed.bob</file>
12+
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
1313
<macros>
1414
<P>BL01T-MO-MOTOR-01</P>
1515
<M>X</M>
@@ -21,7 +21,7 @@
2121
<name>A</name>
2222
<width>205</width>
2323
<height>120</height>
24-
<file>../../../../src/techui-support/bob/pmac/motor_embed.bob</file>
24+
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
2525
<macros>
2626
<P>BL01T-MO-MOTOR-01</P>
2727
<M>A</M>
@@ -41,7 +41,7 @@
4141
<macros>
4242
<P>BL01T-MO-BRICK-01</P>
4343
</macros>
44-
<file>../../../../src/techui-support/bob/pmac/pmacController.bob</file>
44+
<file>example/t01-services/synoptic/techui-support/bob/pmac/pmacController.bob</file>
4545
<target>tab</target>
4646
</action>
4747
</actions>

tests/test_validator.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from pathlib import Path
2+
from unittest.mock import Mock, patch
3+
4+
from lxml.etree import Element, SubElement, _ElementTree, tostring
5+
from lxml.objectify import fromstring
6+
from phoebusgen.widget import EmbeddedDisplay
7+
8+
9+
def test_validator_check_bobs(validator):
10+
validator._check_bob = Mock()
11+
12+
validator.check_bobs()
13+
14+
validator._check_bob.assert_called()
15+
16+
17+
def test_validator_check_bob(validator):
18+
validator._check_bob(validator.bobs[0])
19+
20+
assert len(validator.validate.keys()) > 0
21+
assert list(validator.validate.keys())[0] == "motor-edited"
22+
23+
24+
def test_validator_read_bob(validator):
25+
with patch("techui_builder.validator.read_bob") as mock_read_bob:
26+
# We need to set the spec of the first Mock so it knows
27+
# it has a getroot() function
28+
mock_read_bob.return_value = (Mock(spec=_ElementTree), Mock())
29+
30+
validator._read_bob(validator.bobs[0])
31+
32+
33+
# TODO: Clean up this test... (make fixture for mock xml?)
34+
def test_validator_validate_bob(validator):
35+
# You cannot set a text tag of an ObjectifiedElement,
36+
# so we need to make an etree.Element and convert it ...
37+
mock_root_element = Element("root")
38+
mock_widget_element = SubElement(mock_root_element, "widget")
39+
mock_name_element = SubElement(mock_widget_element, "name")
40+
mock_name_element.text = "motor"
41+
mock_width_element = SubElement(mock_widget_element, "width")
42+
mock_width_element.text = "205"
43+
mock_height_element = SubElement(mock_widget_element, "height")
44+
mock_height_element.text = "120"
45+
mock_file_element = SubElement(mock_widget_element, "file")
46+
mock_file_element.text = (
47+
"example/t01-services/synoptic/techui_supportbob/pmac/motor_embed.bob"
48+
)
49+
# ... which requires this horror
50+
mock_element = fromstring(tostring(mock_root_element))
51+
# mock_element = ObjectifiedElement(mock_widget_element)
52+
# mock_name_element.text = "motor"
53+
validator._read_bob = Mock(
54+
return_value=(
55+
Mock(),
56+
{"motor": (mock_element)},
57+
)
58+
)
59+
validator.validate = {"motor-edited": Path("tests/test_files/motor-edited.bob")}
60+
test_pwidget = EmbeddedDisplay(
61+
"motor",
62+
"example/t01-services/synoptic/techui_supportbob/pmac/motor_embed.bob",
63+
0,
64+
0,
65+
205,
66+
120,
67+
)
68+
69+
validator.validate_bob("motor-edited", "motor", [test_pwidget])

0 commit comments

Comments
 (0)