Skip to content

Commit 3591285

Browse files
Added tests for generate.py
1 parent d7cbe67 commit 3591285

File tree

4 files changed

+83
-50
lines changed

4 files changed

+83
-50
lines changed

tests/test_files/group.xml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,29 @@
44
<x>0</x>
55
<y>0</y>
66
<width>255</width>
7-
<height>620</height>
8-
<widget type="embedded" version="2.0.0">
9-
<name>pmac.autohome</name>
10-
<width>205</width>
11-
<height>120</height>
12-
<file>../../techui-support/bob/motor_embed.bob</file>
13-
<macros>
14-
<P>BL01T-MO-MAP-01:STAGE</P>
15-
<M/>
16-
</macros>
17-
<x>0</x>
18-
<y>0</y>
19-
</widget>
7+
<height>320</height>
208
<widget type="embedded" version="2.0.0">
219
<name>X</name>
2210
<width>205</width>
2311
<height>120</height>
24-
<file>../../techui-support/bob/motor_embed.bob</file>
12+
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
2513
<macros>
2614
<P>BL01T-MO-MAP-01:STAGE</P>
2715
<M>X</M>
2816
</macros>
2917
<x>0</x>
30-
<y>150</y>
18+
<y>0</y>
3119
</widget>
3220
<widget type="embedded" version="2.0.0">
3321
<name>A</name>
3422
<width>205</width>
3523
<height>120</height>
36-
<file>../../techui-support/bob/motor_embed.bob</file>
24+
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
3725
<macros>
3826
<P>BL01T-MO-MAP-01:STAGE</P>
3927
<M>A</M>
4028
</macros>
4129
<x>0</x>
42-
<y>300</y>
43-
</widget>
44-
<widget type="action_button" version="2.0.0">
45-
<name>pmac.GeoBrick</name>
46-
<width>100</width>
47-
<height>40</height>
48-
<pv_name>BL01T-MO-BRICK-01:None</pv_name>
49-
<text>BL01T-MO-BRICK-01</text>
50-
<actions>
51-
<action type="open_display">
52-
<description>Open Display</description>
53-
<macros>
54-
<P>BL01T-MO-BRICK-01</P>
55-
<M>None</M>
56-
</macros>
57-
<file>../../techui-support/bob/pmacController.bob</file>
58-
<target>tab</target>
59-
</action>
60-
</actions>
61-
<x>0</x>
62-
<y>450</y>
30+
<y>150</y>
6331
</widget>
6432
</widget>

tests/test_files/screen.bob

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<display version="2.0.0">
3+
<name>motor</name>
4+
<widget type="group" version="2.0.0">
5+
<name>motor</name>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>255</width>
9+
<height>320</height>
10+
<widget type="embedded" version="2.0.0">
11+
<name>X</name>
12+
<width>205</width>
13+
<height>120</height>
14+
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
15+
<macros>
16+
<P>BL01T-MO-MAP-01:STAGE</P>
17+
<M>X</M>
18+
</macros>
19+
<x>0</x>
20+
<y>0</y>
21+
</widget>
22+
<widget type="embedded" version="2.0.0">
23+
<name>A</name>
24+
<width>205</width>
25+
<height>120</height>
26+
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
27+
<macros>
28+
<P>BL01T-MO-MAP-01:STAGE</P>
29+
<M>A</M>
30+
</macros>
31+
<x>0</x>
32+
<y>150</y>
33+
</widget>
34+
</widget>
35+
</display>

tests/test_files/widget.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" ?>
2+
<widget type="embedded" version="2.0.0">
3+
<name>X</name>
4+
<x>0</x>
5+
<y>0</y>
6+
<width>205</width>
7+
<height>120</height>
8+
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
9+
<macros>
10+
<P>BL01T-MO-MAP-01:STAGE</P>
11+
<M>X</M>
12+
</macros>
13+
</widget>

tests/test_generate.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,43 @@
33
import pytest
44

55
from techui_builder.builder import Builder
6-
7-
# from techui_builder.generate import Generator
6+
from techui_builder.generate import Generator
87

98

109
@pytest.fixture
11-
def gb():
12-
b = Builder(Path("example/create_gui.yaml)"))
10+
def gen():
11+
b = Builder(Path("example/create_gui.yaml"))
1312
b._services_dir = Path(f"./example/{b.beamline.dom}-services")
1413
b._write_directory = Path("example/")
1514
b._extract_entities(
1615
ioc_yaml=Path(f"{b._services_dir}/services/bl01t-mo-ioc-01/config/ioc.yaml"),
1716
) # TODO: Change from hardcoded index
18-
return b
17+
gen = Generator(
18+
b.entities["BL01T-MO-MAP-01:STAGE"], b.components[4].name, Path("./")
19+
)
20+
return gen
21+
22+
23+
def test_create_widget(gen: Generator):
24+
with open("./tests/test_files/widget.xml") as f:
25+
control = f.read()
26+
assert str(gen._create_widget(gen.screen_components[1])) == control
27+
28+
29+
def test_write_screen(gen: Generator):
30+
gen.build_groups()
31+
gen.write_screen(Path("./"))
32+
with open("./motor.bob") as f:
33+
expected = f.read()
34+
35+
with open("./tests/test_files/screen.bob") as f:
36+
control = f.read()
37+
38+
assert expected == control
1939

2040

21-
# def test_build_groups(gb: Builder):
22-
# generator = Generator(
23-
# gb.entities, gb._gui_map, gb.components[4].name
24-
# ) # TODO: remove hardcoded index
25-
# generator.build_groups()
26-
# with open("./tests/test_files/group.xml") as f:
27-
# control = f.read()
28-
# assert str(generator.group) == control
41+
def test_build_groups(gen: Generator):
42+
gen.build_groups()
43+
with open("./tests/test_files/group.xml") as f:
44+
control = f.read()
45+
assert str(gen.group) == control

0 commit comments

Comments
 (0)