sdui-python 1.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Unit tests for the SDUI Python package common properties functionality
4
+ """
5
+
6
+ import unittest
7
+ from sdui_python import (
8
+ get_all_common_properties
9
+ )
10
+
11
+ class TestCommonProperties(unittest.TestCase):
12
+ """Test common properties functionality"""
13
+
14
+ def test_get_all_common_properties(self):
15
+ """Test that get_all_common_properties returns a dictionary of common properties"""
16
+ common_properties = get_all_common_properties()
17
+ self.assertIsInstance(common_properties, dict)
18
+ self.assertGreater(len(common_properties), 0)
19
+
20
+ # Check for some expected common properties
21
+ self.assertIn("padding", common_properties)
22
+ self.assertIn("frame", common_properties)
23
+ self.assertIn("background", common_properties)
24
+ self.assertIn("foregroundColor", common_properties)
25
+ self.assertIn("font", common_properties)
26
+ self.assertIn("fontWeight", common_properties)
27
+
28
+ # Check that each property has the required structure
29
+ for prop_name, prop_info in common_properties.items():
30
+ self.assertIsInstance(prop_info, dict)
31
+ self.assertIn("type", prop_info)
32
+ self.assertIn("description", prop_info)
33
+ # Optional fields
34
+ if "optional" in prop_info:
35
+ self.assertIsInstance(prop_info["optional"], bool)
36
+ if "defaultValue" in prop_info:
37
+ # defaultValue can be any type
38
+ pass
39
+ if "enumValues" in prop_info:
40
+ self.assertIsInstance(prop_info["enumValues"], list)
41
+
42
+ if __name__ == "__main__":
43
+ unittest.main()
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Unit tests for the SDUI Python package component registry functionality
4
+ """
5
+
6
+ import unittest
7
+ import json
8
+ from sdui_python import (
9
+ get_available_components,
10
+ validate_from_source,
11
+ serialize_from_source,
12
+ validate_and_serialize
13
+ )
14
+
15
+ class TestComponentRegistry(unittest.TestCase):
16
+
17
+ def test_get_available_components(self):
18
+ """Test that get_available_components returns a list of components with their properties"""
19
+ components = get_available_components()
20
+ self.assertIsInstance(components, list)
21
+ self.assertGreater(len(components), 0)
22
+
23
+ # Check that each component has the required structure
24
+ for component in components:
25
+ self.assertIn("name", component)
26
+ self.assertIn("props", component)
27
+
28
+ # Check that props is a dictionary of property info objects
29
+ self.assertIsInstance(component["props"], dict)
30
+
31
+ # Check for specific components
32
+ if component["name"] == "SduiButton":
33
+ self.assertIn("text", component["props"])
34
+ # Check that each property has type info
35
+ self.assertIn("type", component["props"]["text"])
36
+ # Check for disabled property (it's optional, so just check if it exists)
37
+ # Note: disabled property is in the extends array, not in props directly
38
+ elif component["name"] == "SduiText":
39
+ self.assertIn("text", component["props"])
40
+ # Check that each property has type info
41
+ self.assertIn("type", component["props"]["text"])
42
+ # Check for font property (it's in the extends array, not in props directly)
43
+
44
+ def test_validate_from_source(self):
45
+ """Test component structure validation"""
46
+ # Valid component
47
+ valid_component = """
48
+ function MyComponent() {
49
+ return <SduiText text="Hello World" />;
50
+ }
51
+ """
52
+ result = validate_from_source(valid_component)
53
+ self.assertTrue(result["isValid"])
54
+ self.assertEqual(len(result["errors"]), 0)
55
+
56
+ # Invalid component (unknown Sdui component)
57
+ invalid_component = """
58
+ function MyComponent() {
59
+ return <SduiUnknownComponent />;
60
+ }
61
+ """
62
+ result = validate_from_source(invalid_component)
63
+ self.assertFalse(result["isValid"])
64
+ self.assertGreater(len(result["errors"]), 0)
65
+
66
+ class TestSerialization(unittest.TestCase):
67
+ """Test serialization functionality"""
68
+
69
+ def test_serialize_from_source_simple(self):
70
+ """Test serialize_from_source with a simple component"""
71
+ source_code = """
72
+ function MyComponent() {
73
+ return <SduiText text="Hello World" font="headline" />;
74
+ }
75
+ """
76
+ result = serialize_from_source(source_code)
77
+ self.assertIsInstance(result, dict)
78
+ self.assertIn("type", result)
79
+ self.assertEqual(result["type"], "SduiText")
80
+ self.assertIn("props", result)
81
+ self.assertIn("text", result["props"])
82
+ self.assertEqual(result["props"]["text"], "Hello World")
83
+ # Note: font is a common property that is applied via modifiers, not directly in props
84
+
85
+ def test_serialize_from_source_complex(self):
86
+ """Test serialize_from_source with a complex component"""
87
+ source_code = """
88
+ function ComplexComponent() {
89
+ return (
90
+ <SduiVStack spacing={16}>
91
+ <SduiText text="Welcome" font="headline" />
92
+ <SduiHStack spacing={8}>
93
+ <SduiButton text="Save" />
94
+ <SduiButton text="Cancel" />
95
+ </SduiHStack>
96
+ </SduiVStack>
97
+ );
98
+ }
99
+ """
100
+ result = serialize_from_source(source_code)
101
+ self.assertIsInstance(result, dict)
102
+ self.assertIn("type", result)
103
+ self.assertEqual(result["type"], "SduiVStack")
104
+ self.assertIn("props", result)
105
+ self.assertIn("spacing", result["props"])
106
+ self.assertEqual(result["props"]["spacing"], 16)
107
+ self.assertIn("children", result)
108
+ self.assertIsInstance(result["children"], list)
109
+ self.assertEqual(len(result["children"]), 2)
110
+
111
+ # Check first child (SduiText)
112
+ text_child = result["children"][0]
113
+ self.assertEqual(text_child["type"], "SduiText")
114
+ self.assertEqual(text_child["props"]["text"], "Welcome")
115
+
116
+ # Check second child (SduiHStack)
117
+ hstack_child = result["children"][1]
118
+ self.assertEqual(hstack_child["type"], "SduiHStack")
119
+ self.assertEqual(hstack_child["props"]["spacing"], 8)
120
+ self.assertIn("children", hstack_child)
121
+ self.assertEqual(len(hstack_child["children"]), 2)
122
+
123
+ # Check buttons in HStack
124
+ button1 = hstack_child["children"][0]
125
+ button2 = hstack_child["children"][1]
126
+ self.assertEqual(button1["type"], "SduiButton")
127
+ self.assertEqual(button1["props"]["text"], "Save")
128
+ self.assertEqual(button2["type"], "SduiButton")
129
+ self.assertEqual(button2["props"]["text"], "Cancel")
130
+
131
+ class TestValidateAndSerialize(unittest.TestCase):
132
+ """Test validate and serialize functionality"""
133
+
134
+ def test_validate_and_serialize_valid(self):
135
+ """Test validate_and_serialize with a valid component"""
136
+ component = """
137
+ function MyComponent() {
138
+ return <SduiText text="Hello World" />;
139
+ }
140
+ """
141
+ result = validate_and_serialize(component)
142
+ self.assertIsInstance(result, dict)
143
+ self.assertIn("isValid", result)
144
+ self.assertTrue(result["isValid"])
145
+ self.assertIn("errors", result)
146
+ self.assertEqual(len(result["errors"]), 0)
147
+ self.assertIn("serialized", result)
148
+ self.assertIsInstance(result["serialized"], dict)
149
+ self.assertEqual(result["serialized"]["type"], "SduiText")
150
+ self.assertEqual(result["serialized"]["props"]["text"], "Hello World")
151
+
152
+ def test_validate_and_serialize_invalid(self):
153
+ """Test validate_and_serialize with an invalid component"""
154
+ component = {
155
+ "props": {"text": "Missing type"}
156
+ }
157
+ result = validate_and_serialize(json.dumps(component))
158
+ self.assertIsInstance(result, dict)
159
+ self.assertIn("isValid", result)
160
+ self.assertFalse(result["isValid"])
161
+ self.assertIn("errors", result)
162
+ self.assertGreater(len(result["errors"]), 0)
163
+ self.assertIn("serialized", result)
164
+ self.assertIsNone(result["serialized"])
165
+
166
+ if __name__ == "__main__":
167
+ unittest.main()
@@ -0,0 +1,359 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Component types comprehensive tests for the SDUI Python package
4
+ """
5
+
6
+ import unittest
7
+ import json
8
+ from sdui_python import (
9
+ get_available_components,
10
+ serialize_from_source,
11
+ validate_and_serialize
12
+ )
13
+
14
+ class TestComponentTypes(unittest.TestCase):
15
+ """Test different component types functionality"""
16
+
17
+ def test_layout_components(self):
18
+ """Test layout components (VStack, HStack, ZStack)"""
19
+ # Test VStack
20
+ vstack_code = """
21
+ function TestVStack() {
22
+ return (
23
+ <SduiVStack spacing={10} alignment="center">
24
+ <SduiText text="Item 1" />
25
+ <SduiText text="Item 2" />
26
+ </SduiVStack>
27
+ );
28
+ }
29
+ """
30
+ result = serialize_from_source(vstack_code)
31
+ self.assertIsNotNone(result)
32
+ self.assertEqual(result["type"], "SduiVStack")
33
+ self.assertEqual(result["props"]["spacing"], 10)
34
+ self.assertEqual(result["props"]["alignment"], "center")
35
+ self.assertEqual(len(result["children"]), 2)
36
+
37
+ # Test HStack
38
+ hstack_code = """
39
+ function TestHStack() {
40
+ return (
41
+ <SduiHStack spacing={5} fillWidth={true}>
42
+ <SduiButton text="Left" />
43
+ <SduiButton text="Right" />
44
+ </SduiHStack>
45
+ );
46
+ }
47
+ """
48
+ result = serialize_from_source(hstack_code)
49
+ self.assertIsNotNone(result)
50
+ self.assertEqual(result["type"], "SduiHStack")
51
+ self.assertEqual(result["props"]["spacing"], 5)
52
+ self.assertTrue(result["props"]["fillWidth"])
53
+ self.assertEqual(len(result["children"]), 2)
54
+
55
+ def test_input_components(self):
56
+ """Test input components (TextField, SecureField, TextEditor)"""
57
+ # Test TextField
58
+ textfield_code = """
59
+ function TestTextField() {
60
+ return (
61
+ <SduiTextField
62
+ text="Hello World"
63
+ placeholder="Enter text..."
64
+ keyboardType="default"
65
+ />
66
+ );
67
+ }
68
+ """
69
+ result = serialize_from_source(textfield_code)
70
+ self.assertIsNotNone(result)
71
+ self.assertEqual(result["type"], "SduiTextField")
72
+ self.assertEqual(result["props"]["text"], "Hello World")
73
+ self.assertEqual(result["props"]["placeholder"], "Enter text...")
74
+
75
+ # Test SecureField
76
+ securefield_code = """
77
+ function TestSecureField() {
78
+ return (
79
+ <SduiSecureField
80
+ text="secret123"
81
+ placeholder="Enter password..."
82
+ />
83
+ );
84
+ }
85
+ """
86
+ result = serialize_from_source(securefield_code)
87
+ self.assertIsNotNone(result)
88
+ self.assertEqual(result["type"], "SduiSecureField")
89
+ self.assertEqual(result["props"]["text"], "secret123")
90
+
91
+ # Test TextEditor
92
+ texteditor_code = """
93
+ function TestTextEditor() {
94
+ return (
95
+ <SduiTextEditor
96
+ text="Long text content..."
97
+ placeholder="Enter description..."
98
+ />
99
+ );
100
+ }
101
+ """
102
+ result = serialize_from_source(texteditor_code)
103
+ self.assertIsNotNone(result)
104
+ self.assertEqual(result["type"], "SduiTextEditor")
105
+ self.assertEqual(result["props"]["text"], "Long text content...")
106
+
107
+ def test_picker_components(self):
108
+ """Test picker components (Picker, DatePicker)"""
109
+ # Test Picker
110
+ picker_code = """
111
+ function TestPicker() {
112
+ return (
113
+ <SduiPicker
114
+ selection="option1"
115
+ options={["option1", "option2", "option3"]}
116
+ />
117
+ );
118
+ }
119
+ """
120
+ result = serialize_from_source(picker_code)
121
+ self.assertIsNotNone(result)
122
+ self.assertEqual(result["type"], "SduiPicker")
123
+ self.assertEqual(result["props"]["selection"], "option1")
124
+
125
+ # Test DatePicker
126
+ datepicker_code = """
127
+ function TestDatePicker() {
128
+ return (
129
+ <SduiDatePicker
130
+ date="2023-12-25"
131
+ mode="date"
132
+ />
133
+ );
134
+ }
135
+ """
136
+ result = serialize_from_source(datepicker_code)
137
+ self.assertIsNotNone(result)
138
+ self.assertEqual(result["type"], "SduiDatePicker")
139
+ self.assertEqual(result["props"]["date"], "2023-12-25")
140
+
141
+ def test_media_components(self):
142
+ """Test media components (Image, Camera)"""
143
+ # Test Image
144
+ image_code = """
145
+ function TestImage() {
146
+ return (
147
+ <SduiImage
148
+ source="https://example.com/image.jpg"
149
+ contentMode="aspectFill"
150
+ frame={{ width: 200, height: 200 }}
151
+ />
152
+ );
153
+ }
154
+ """
155
+ result = serialize_from_source(image_code)
156
+ self.assertIsNotNone(result)
157
+ self.assertEqual(result["type"], "SduiImage")
158
+ self.assertEqual(result["props"]["source"], "https://example.com/image.jpg")
159
+
160
+ # Test Camera
161
+ camera_code = """
162
+ function TestCamera() {
163
+ return (
164
+ <SduiCamera
165
+ mode="photo"
166
+ quality="high"
167
+ />
168
+ );
169
+ }
170
+ """
171
+ result = serialize_from_source(camera_code)
172
+ self.assertIsNotNone(result)
173
+ self.assertEqual(result["type"], "SduiCamera")
174
+ self.assertEqual(result["props"]["mode"], "photo")
175
+
176
+ def test_list_components(self):
177
+ """Test list components (List, ForEach)"""
178
+ # Test List
179
+ list_code = """
180
+ function TestList() {
181
+ return (
182
+ <SduiList>
183
+ <SduiText text="Item 1" />
184
+ <SduiText text="Item 2" />
185
+ <SduiText text="Item 3" />
186
+ </SduiList>
187
+ );
188
+ }
189
+ """
190
+ result = serialize_from_source(list_code)
191
+ self.assertIsNotNone(result)
192
+ self.assertEqual(result["type"], "SduiList")
193
+ self.assertEqual(len(result["children"]), 3)
194
+
195
+ # Test ForEach
196
+ foreach_code = """
197
+ function TestForEach() {
198
+ return (
199
+ <SduiForEach
200
+ dataSource="[1, 2, 3]"
201
+ itemKey="index"
202
+ template={{
203
+ type: "SduiText",
204
+ props: { text: "Item {{index}}" }
205
+ }}
206
+ />
207
+ );
208
+ }
209
+ """
210
+ result = serialize_from_source(foreach_code)
211
+ self.assertIsNotNone(result)
212
+ self.assertEqual(result["type"], "SduiForEach")
213
+ self.assertEqual(result["props"]["dataSource"], "[1, 2, 3]")
214
+
215
+ def test_form_components(self):
216
+ """Test form components (Form, Alert)"""
217
+ # Test Form
218
+ form_code = """
219
+ function TestForm() {
220
+ return (
221
+ <SduiForm>
222
+ <SduiTextField text="Username" />
223
+ <SduiSecureField text="Password" />
224
+ <SduiButton text="Submit" />
225
+ </SduiForm>
226
+ );
227
+ }
228
+ """
229
+ result = serialize_from_source(form_code)
230
+ self.assertIsNotNone(result)
231
+ self.assertEqual(result["type"], "SduiForm")
232
+ self.assertEqual(len(result["children"]), 3)
233
+
234
+ # Test Alert
235
+ alert_code = """
236
+ function TestAlert() {
237
+ return (
238
+ <SduiAlert
239
+ title="Information"
240
+ message="This is an alert message"
241
+ buttons={["OK", "Cancel"]}
242
+ />
243
+ );
244
+ }
245
+ """
246
+ result = serialize_from_source(alert_code)
247
+ self.assertIsNotNone(result)
248
+ self.assertEqual(result["type"], "SduiAlert")
249
+ self.assertEqual(result["props"]["title"], "Information")
250
+
251
+ def test_control_components(self):
252
+ """Test control components (Slider, Stepper, Toggle, ProgressView)"""
253
+ # Test Slider
254
+ slider_code = """
255
+ function TestSlider() {
256
+ return (
257
+ <SduiSlider
258
+ value={0.5}
259
+ range={[0, 1]}
260
+ step={0.1}
261
+ />
262
+ );
263
+ }
264
+ """
265
+ result = serialize_from_source(slider_code)
266
+ self.assertIsNotNone(result)
267
+ self.assertEqual(result["type"], "SduiSlider")
268
+ self.assertEqual(result["props"]["value"], 0.5)
269
+
270
+ # Test Stepper
271
+ stepper_code = """
272
+ function TestStepper() {
273
+ return (
274
+ <SduiStepper
275
+ value={5}
276
+ range={[0, 100]}
277
+ step={1}
278
+ />
279
+ );
280
+ }
281
+ """
282
+ result = serialize_from_source(stepper_code)
283
+ self.assertIsNotNone(result)
284
+ self.assertEqual(result["type"], "SduiStepper")
285
+ self.assertEqual(result["props"]["value"], 5)
286
+
287
+ # Test ProgressView
288
+ progress_code = """
289
+ function TestProgressView() {
290
+ return (
291
+ <SduiProgressView
292
+ progress={0.75}
293
+ style="bar"
294
+ />
295
+ );
296
+ }
297
+ """
298
+ result = serialize_from_source(progress_code)
299
+ self.assertIsNotNone(result)
300
+ self.assertEqual(result["type"], "SduiProgressView")
301
+ self.assertEqual(result["props"]["progress"], 0.75)
302
+
303
+ def test_decorative_components(self):
304
+ """Test decorative components (Divider, Icon)"""
305
+ # Test Divider
306
+ divider_code = """
307
+ function TestDivider() {
308
+ return (
309
+ <SduiDivider
310
+ color="#E0E0E0"
311
+ thickness={1}
312
+ />
313
+ );
314
+ }
315
+ """
316
+ result = serialize_from_source(divider_code)
317
+ self.assertIsNotNone(result)
318
+ self.assertEqual(result["type"], "SduiDivider")
319
+ self.assertEqual(result["props"]["color"], "#E0E0E0")
320
+
321
+ # Test Icon
322
+ icon_code = """
323
+ function TestIcon() {
324
+ return (
325
+ <SduiIcon
326
+ name="heart.fill"
327
+ size="large"
328
+ foregroundColor="#FF0000"
329
+ />
330
+ );
331
+ }
332
+ """
333
+ result = serialize_from_source(icon_code)
334
+ self.assertIsNotNone(result)
335
+ self.assertEqual(result["type"], "SduiIcon")
336
+ self.assertEqual(result["props"]["name"], "heart.fill")
337
+
338
+ def test_scroll_components(self):
339
+ """Test scroll components (ScrollView)"""
340
+ scrollview_code = """
341
+ function TestScrollView() {
342
+ return (
343
+ <SduiScrollView
344
+ axis="vertical"
345
+ showsIndicators={true}
346
+ >
347
+ <SduiText text="Scrollable content" />
348
+ </SduiScrollView>
349
+ );
350
+ }
351
+ """
352
+ result = serialize_from_source(scrollview_code)
353
+ self.assertIsNotNone(result)
354
+ self.assertEqual(result["type"], "SduiScrollView")
355
+ self.assertEqual(result["props"]["axis"], "vertical")
356
+ self.assertTrue(result["props"]["showsIndicators"])
357
+
358
+ if __name__ == "__main__":
359
+ unittest.main()