1- # from pathlib import Path
1+ from pathlib import Path
22
3- # import pytest
4-
5- # from techui_builder.builder import Builder
3+ import pytest
4+ import yaml
5+ from lxml import objectify
6+ from phoebusgen import widget as Widget
67
78from techui_builder .models import Entity
89
@@ -24,11 +25,155 @@ def test_generator_get_screen_dimensions(generator):
2425 assert y == 205
2526
2627
27- # def test_build_groups(gb: Builder):
28- # generator = Generator(
29- # gb.entities, gb._gui_map, gb.components[4].name
30- # ) # TODO: remove hardcoded index
31- # generator.build_groups()
32- # with open("./tests/test_files/group.xml") as f:
33- # control = f.read()
34- # assert str(generator.group) == control
28+ def test_generator_get_widget_dimensions (generator ):
29+ widget = Path ("tests/test_files/widget.xml" )
30+
31+ with open (widget ) as f :
32+ xml_content = f .read ()
33+
34+ height , width = generator ._get_widget_dimensions (xml_content )
35+ assert height == 800
36+ assert width == 1280
37+
38+
39+ def test_generator_get_widget_position (generator ):
40+ widget = Path ("tests/test_files/widget.xml" )
41+
42+ with open (widget ) as f :
43+ xml_content = f .read ()
44+
45+ y , x = generator ._get_widget_position (xml_content )
46+ assert x == 0
47+ assert y == 0
48+
49+
50+ def test_generator_get_group_dimensions (generator ):
51+ group = Path ("tests/test_files/widget_list.yaml" )
52+
53+ with open (group ) as f :
54+ widgets_list = yaml .safe_load (f .read ())
55+
56+ height , width = generator ._get_group_dimensions (widget_list = widgets_list )
57+ assert height == 620
58+ assert width == 255
59+
60+
61+ def test_generator_initialise_name_suffix (generator ):
62+ component = Entity (type = "test" , P = "TEST" , desc = None , M = "T1" , R = None )
63+
64+ name , suffix , suffix_label = generator ._initialise_name_suffix (component )
65+
66+ assert name == "T1"
67+ assert suffix == "T1"
68+ assert suffix_label == "M"
69+
70+
71+ def test_generator_is_list_of_dicts (generator ):
72+ list_of_dicts = [{"a" : 1 }, {"b" : 2 }]
73+ not_list_of_dicts = {"a" : 1 }
74+
75+ assert generator ._is_list_of_dicts (list_of_dicts ) is True
76+ assert generator ._is_list_of_dicts (not_list_of_dicts ) is False
77+
78+
79+ def test_generator_allocate_widget (generator ):
80+ scrn_mapping = {
81+ "file" : "ADAravis/ADAravis_summary.bob" ,
82+ "prefix" : "$(P)$(R)" ,
83+ "type" : "embedded" ,
84+ }
85+ component = Entity (
86+ type = "ADAravis.aravisCamera" , P = "BL23B-DI-MOD-02" , desc = None , M = None , R = "CAM:"
87+ )
88+
89+ widget = generator ._allocate_widget (scrn_mapping , component )
90+
91+ control_widget = Path ("tests/test_files/widget.xml" )
92+
93+ with open (control_widget ) as f :
94+ xml_content = f .read ()
95+
96+ assert str (widget ) == xml_content
97+
98+
99+ def test_generator_create_widget (generator ):
100+ component = Entity (
101+ type = "ADAravis.aravisCamera" , P = "BL23B-DI-MOD-02" , desc = None , M = None , R = "CAM:"
102+ )
103+
104+ widget = generator ._create_widget (
105+ component = component ,
106+ )
107+
108+ control_widget = Path ("tests/test_files/widget.xml" )
109+
110+ with open (control_widget ) as f :
111+ xml_content = f .read ()
112+
113+ assert str (widget ) == xml_content
114+
115+
116+ @pytest .mark .parametrize (
117+ "index, x, y" ,
118+ [
119+ (0 , 0 , 0 ),
120+ (1 , 0 , 150 ),
121+ (2 , 0 , 300 ),
122+ (3 , 0 , 450 ),
123+ (4 , 120 , 450 ),
124+ (5 , 0 , 520 ),
125+ ],
126+ )
127+ def test_generator_layout_widgets (generator , index , x , y ):
128+ widgets_list = [
129+ Widget .EmbeddedDisplay (name = "A" , file = "" , x = 0 , y = 0 , width = 205 , height = 120 ),
130+ Widget .EmbeddedDisplay (name = "X" , file = "" , x = 0 , y = 0 , width = 205 , height = 120 ),
131+ Widget .EmbeddedDisplay (
132+ name = "pmac.autohome" , file = "" , x = 0 , y = 0 , width = 205 , height = 120
133+ ),
134+ Widget .EmbeddedDisplay (
135+ name = "pmac.GeoBrick" , file = "" , x = 0 , y = 0 , width = 100 , height = 40
136+ ),
137+ Widget .ActionButton (
138+ name = "pmac.Action1" ,
139+ text = "test1" ,
140+ pv_name = "abc" ,
141+ x = 0 ,
142+ y = 0 ,
143+ width = 100 ,
144+ height = 40 ,
145+ ),
146+ Widget .ActionButton (
147+ name = "pmac.Action2" ,
148+ text = "test2" ,
149+ pv_name = "xyz" ,
150+ x = 0 ,
151+ y = 0 ,
152+ width = 100 ,
153+ height = 40 ,
154+ ),
155+ ]
156+ arranged_widgets = generator .layout_widgets (widgets_list )
157+ assert objectify .fromstring (str (arranged_widgets [index ])).x == x
158+ assert objectify .fromstring (str (arranged_widgets [index ])).y == y
159+
160+
161+ def test_generator_build_groups (generator ):
162+ entity = Entity (
163+ type = "ADAravis.aravisCamera" , P = "BL23B-DI-MOD-02" , desc = None , M = None , R = "CAM:"
164+ )
165+ generator .load_screen ("test" , [entity ])
166+ generator .build_groups ()
167+ print (generator .screen_ )
168+ assert objectify .fromstring (str (generator .screen_ )).xpath ("//widget[@type='group']" )
169+
170+
171+ def test_generator_write_screen (generator ):
172+ entity = Entity (
173+ type = "ADAravis.aravisCamera" , P = "BL23B-DI-MOD-02" , desc = None , M = None , R = "CAM:"
174+ )
175+ generator .load_screen ("test" , [entity ])
176+ generator .build_groups ()
177+ generator .write_screen (Path ("tests/test_files/" ))
178+ assert Path ("tests/test_files/test.bob" ).exists ()
179+ Path ("tests/test_files/test.bob" ).unlink ()
0 commit comments