Skip to content

Added tests for generate.py #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 5 additions & 37 deletions tests/test_files/group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,29 @@
<x>0</x>
<y>0</y>
<width>255</width>
<height>620</height>
<widget type="embedded" version="2.0.0">
<name>pmac.autohome</name>
<width>205</width>
<height>120</height>
<file>../../techui-support/bob/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M/>
</macros>
<x>0</x>
<y>0</y>
</widget>
<height>320</height>
<widget type="embedded" version="2.0.0">
<name>X</name>
<width>205</width>
<height>120</height>
<file>../../techui-support/bob/motor_embed.bob</file>
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M>X</M>
</macros>
<x>0</x>
<y>150</y>
<y>0</y>
</widget>
<widget type="embedded" version="2.0.0">
<name>A</name>
<width>205</width>
<height>120</height>
<file>../../techui-support/bob/motor_embed.bob</file>
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M>A</M>
</macros>
<x>0</x>
<y>300</y>
</widget>
<widget type="action_button" version="2.0.0">
<name>pmac.GeoBrick</name>
<width>100</width>
<height>40</height>
<pv_name>BL01T-MO-BRICK-01:None</pv_name>
<text>BL01T-MO-BRICK-01</text>
<actions>
<action type="open_display">
<description>Open Display</description>
<macros>
<P>BL01T-MO-BRICK-01</P>
<M>None</M>
</macros>
<file>../../techui-support/bob/pmacController.bob</file>
<target>tab</target>
</action>
</actions>
<x>0</x>
<y>450</y>
<y>150</y>
</widget>
</widget>
35 changes: 35 additions & 0 deletions tests/test_files/screen.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<display version="2.0.0">
<name>motor</name>
<widget type="group" version="2.0.0">
<name>motor</name>
<x>0</x>
<y>0</y>
<width>255</width>
<height>320</height>
<widget type="embedded" version="2.0.0">
<name>X</name>
<width>205</width>
<height>120</height>
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M>X</M>
</macros>
<x>0</x>
<y>0</y>
</widget>
<widget type="embedded" version="2.0.0">
<name>A</name>
<width>205</width>
<height>120</height>
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M>A</M>
</macros>
<x>0</x>
<y>150</y>
</widget>
</widget>
</display>
13 changes: 13 additions & 0 deletions tests/test_files/widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<widget type="embedded" version="2.0.0">
<name>X</name>
<x>0</x>
<y>0</y>
<width>205</width>
<height>120</height>
<file>src/techui_support/bob/pmac/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MAP-01:STAGE</P>
<M>X</M>
</macros>
</widget>
43 changes: 30 additions & 13 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@
import pytest

from techui_builder.builder import Builder

# from techui_builder.generate import Generator
from techui_builder.generate import Generator


@pytest.fixture
def gb():
b = Builder(Path("example/create_gui.yaml)"))
def gen():
b = Builder(Path("example/create_gui.yaml"))
b._services_dir = Path(f"./example/{b.beamline.dom}-services")
b._write_directory = Path("example/")
b._extract_entities(
ioc_yaml=Path(f"{b._services_dir}/services/bl01t-mo-ioc-01/config/ioc.yaml"),
) # TODO: Change from hardcoded index
return b
gen = Generator(
b.entities["BL01T-MO-MAP-01:STAGE"], b.components[4].name, Path("./")
)
return gen


def test_create_widget(gen: Generator):
with open("./tests/test_files/widget.xml") as f:
control = f.read()
assert str(gen._create_widget(gen.screen_components[1])) == control


def test_write_screen(gen: Generator):
gen.build_groups()
gen.write_screen(Path("./"))
with open("./motor.bob") as f:
expected = f.read()

with open("./tests/test_files/screen.bob") as f:
control = f.read()

assert expected == control


# def test_build_groups(gb: Builder):
# generator = Generator(
# gb.entities, gb._gui_map, gb.components[4].name
# ) # TODO: remove hardcoded index
# generator.build_groups()
# with open("./tests/test_files/group.xml") as f:
# control = f.read()
# assert str(generator.group) == control
def test_build_groups(gen: Generator):
gen.build_groups()
with open("./tests/test_files/group.xml") as f:
control = f.read()
assert str(gen.group) == control
Loading