4
4
import pytest
5
5
6
6
from dash .development .base_component import Component
7
+ import dash_html_components as html
7
8
8
9
Component ._prop_names = ("id" , "a" , "children" , "style" )
9
10
Component ._type = "TestComponent"
@@ -36,23 +37,23 @@ def nested_tree():
36
37
return c , c1 , c2 , c3 , c4 , c5
37
38
38
39
39
- def test_init ():
40
+ def test_debc001_init ():
40
41
Component (a = 3 )
41
42
42
43
43
- def test_get_item_with_children ():
44
+ def test_debc002_get_item_with_children ():
44
45
c1 = Component (id = "1" )
45
46
c2 = Component (children = [c1 ])
46
47
assert c2 ["1" ] == c1
47
48
48
49
49
- def test_get_item_with_children_as_component_instead_of_list ():
50
+ def test_debc003_get_item_with_children_as_component_instead_of_list ():
50
51
c1 = Component (id = "1" )
51
52
c2 = Component (id = "2" , children = c1 )
52
53
assert c2 ["1" ] == c1
53
54
54
55
55
- def test_get_item_with_nested_children_one_branch ():
56
+ def test_debc004_get_item_with_nested_children_one_branch ():
56
57
c1 = Component (id = "1" )
57
58
c2 = Component (id = "2" , children = [c1 ])
58
59
c3 = Component (children = [c2 ])
@@ -61,7 +62,7 @@ def test_get_item_with_nested_children_one_branch():
61
62
assert c3 ["1" ] == c1
62
63
63
64
64
- def test_get_item_with_nested_children_two_branches ():
65
+ def test_debc005_get_item_with_nested_children_two_branches ():
65
66
c1 = Component (id = "1" )
66
67
c2 = Component (id = "2" , children = [c1 ])
67
68
c3 = Component (id = "3" )
@@ -75,7 +76,7 @@ def test_get_item_with_nested_children_two_branches():
75
76
assert c5 ["3" ] == c3
76
77
77
78
78
- def test_get_item_with_nested_children_with_mixed_strings_and_without_lists ():
79
+ def test_debc006_get_item_with_full_tree ():
79
80
c , c1 , c2 , c3 , c4 , c5 = nested_tree ()
80
81
keys = [k for k in c ]
81
82
@@ -90,15 +91,15 @@ def test_get_item_with_nested_children_with_mixed_strings_and_without_lists():
90
91
c ["x" ]
91
92
92
93
93
- def test_len_with_nested_children_with_mixed_strings_and_without_lists ():
94
+ def test_debc007_len_with_full_tree ():
94
95
c = nested_tree ()[0 ]
95
96
assert (
96
97
len (c ) == 5 + 5 + 1
97
98
), "the length of the nested children should match the total of 5 \
98
99
components, 2 strings + 2 numbers + none in c2, and 1 string in c1"
99
100
100
101
101
- def test_set_item_with_nested_children_with_mixed_strings_and_without_lists ():
102
+ def test_debc008_set_item_anywhere_in_tree ():
102
103
keys = ["0.0" , "0.1" , "0.1.x" , "0.1.x.x" , "0.1.x.x.0" ]
103
104
c = nested_tree ()[0 ]
104
105
@@ -110,7 +111,7 @@ def test_set_item_with_nested_children_with_mixed_strings_and_without_lists():
110
111
assert c [new_id ] == new_component
111
112
112
113
113
- def test_del_item_with_nested_children_with_mixed_strings_and_without_lists ():
114
+ def test_debc009_del_item_full_tree ():
114
115
c = nested_tree ()[0 ]
115
116
keys = reversed ([k for k in c ])
116
117
for key in keys :
@@ -120,21 +121,21 @@ def test_del_item_with_nested_children_with_mixed_strings_and_without_lists():
120
121
c [key ]
121
122
122
123
123
- def test_traverse_with_nested_children_with_mixed_strings_and_without_lists ():
124
+ def test_debc010_traverse_full_tree ():
124
125
c , c1 , c2 , c3 , c4 , c5 = nested_tree ()
125
126
elements = [i for i in c ._traverse ()]
126
127
assert elements == c .children + [c3 ] + [c2 ] + c2 .children
127
128
128
129
129
- def test_traverse_with_tuples ():
130
+ def test_debc011_traverse_with_tuples ():
130
131
c , c1 , c2 , c3 , c4 , c5 = nested_tree ()
131
132
c2 .children = tuple (c2 .children )
132
133
c .children = tuple (c .children )
133
134
elements = [i for i in c ._traverse ()]
134
135
assert elements == list (c .children ) + [c3 ] + [c2 ] + list (c2 .children )
135
136
136
137
137
- def test_to_plotly_json_with_nested_children_with_mixed_strings_and_without_lists ():
138
+ def test_debc012_to_plotly_json_full_tree ():
138
139
c = nested_tree ()[0 ]
139
140
Component ._namespace
140
141
Component ._type
@@ -194,7 +195,7 @@ def test_to_plotly_json_with_nested_children_with_mixed_strings_and_without_list
194
195
assert res == expected
195
196
196
197
197
- def test_get_item_raises_key_if_id_doesnt_exist ():
198
+ def test_debc013_get_item_raises_key_if_id_doesnt_exist ():
198
199
c = Component ()
199
200
with pytest .raises (KeyError ):
200
201
c ["1" ]
@@ -212,7 +213,7 @@ def test_get_item_raises_key_if_id_doesnt_exist():
212
213
c3 ["0" ]
213
214
214
215
215
- def test_set_item ():
216
+ def test_debc014_set_item ():
216
217
c1a = Component (id = "1" , children = "Hello world" )
217
218
c2 = Component (id = "2" , children = c1a )
218
219
assert c2 ["1" ] == c1a
@@ -222,7 +223,7 @@ def test_set_item():
222
223
assert c2 ["1" ] == c1b
223
224
224
225
225
- def test_set_item_with_children_as_list ():
226
+ def test_debc015_set_item_with_children_as_list ():
226
227
c1 = Component (id = "1" )
227
228
c2 = Component (id = "2" , children = [c1 ])
228
229
assert c2 ["1" ] == c1
@@ -231,7 +232,7 @@ def test_set_item_with_children_as_list():
231
232
assert c2 ["3" ] == c3
232
233
233
234
234
- def test_set_item_with_nested_children ():
235
+ def test_debc016_set_item_with_nested_children ():
235
236
c1 = Component (id = "1" )
236
237
c2 = Component (id = "2" , children = [c1 ])
237
238
c3 = Component (id = "3" )
@@ -256,14 +257,14 @@ def test_set_item_with_nested_children():
256
257
c5 ["1" ]
257
258
258
259
259
- def test_set_item_raises_key_error ():
260
+ def test_debc017_set_item_raises_key_error ():
260
261
c1 = Component (id = "1" )
261
262
c2 = Component (id = "2" , children = [c1 ])
262
263
with pytest .raises (KeyError ):
263
264
c2 ["3" ] = Component (id = "3" )
264
265
265
266
266
- def test_del_item_from_list ():
267
+ def test_debc018_del_item_from_list ():
267
268
c1 = Component (id = "1" )
268
269
c2 = Component (id = "2" )
269
270
c3 = Component (id = "3" , children = [c1 , c2 ])
@@ -280,7 +281,7 @@ def test_del_item_from_list():
280
281
assert c3 .children == []
281
282
282
283
283
- def test_del_item_from_class ():
284
+ def test_debc019_del_item_from_class ():
284
285
c1 = Component (id = "1" )
285
286
c2 = Component (id = "2" , children = c1 )
286
287
assert c2 ["1" ] == c1
@@ -291,7 +292,7 @@ def test_del_item_from_class():
291
292
assert c2 .children is None
292
293
293
294
294
- def test_to_plotly_json_without_children ():
295
+ def test_debc020_to_plotly_json_without_children ():
295
296
c = Component (id = "a" )
296
297
c ._prop_names = ("id" ,)
297
298
c ._type = "MyComponent"
@@ -303,7 +304,7 @@ def test_to_plotly_json_without_children():
303
304
}
304
305
305
306
306
- def test_to_plotly_json_with_null_arguments ():
307
+ def test_debc021_to_plotly_json_with_null_arguments ():
307
308
c = Component (id = "a" )
308
309
c ._prop_names = ("id" , "style" )
309
310
c ._type = "MyComponent"
@@ -325,7 +326,7 @@ def test_to_plotly_json_with_null_arguments():
325
326
}
326
327
327
328
328
- def test_to_plotly_json_with_children ():
329
+ def test_debc022_to_plotly_json_with_children ():
329
330
c = Component (id = "a" , children = "Hello World" )
330
331
c ._prop_names = ("id" , "children" )
331
332
c ._type = "MyComponent"
@@ -341,7 +342,7 @@ def test_to_plotly_json_with_children():
341
342
}
342
343
343
344
344
- def test_to_plotly_json_with_wildcards ():
345
+ def test_debc023_to_plotly_json_with_wildcards ():
345
346
c = Component (
346
347
id = "a" , ** {"aria-expanded" : "true" , "data-toggle" : "toggled" , "data-none" : None }
347
348
)
@@ -360,15 +361,15 @@ def test_to_plotly_json_with_wildcards():
360
361
}
361
362
362
363
363
- def test_len ():
364
+ def test_debc024_len ():
364
365
assert len (Component ()) == 0
365
366
assert len (Component (children = "Hello World" )) == 1
366
367
assert len (Component (children = Component ())) == 1
367
368
assert len (Component (children = [Component (), Component ()])) == 2
368
369
assert len (Component (children = [Component (children = Component ()), Component ()])) == 3
369
370
370
371
371
- def test_iter ():
372
+ def test_debc025_iter ():
372
373
# The mixin methods from MutableMapping were cute but probably never
373
374
# used - at least not by us. Test that they're gone
374
375
@@ -418,3 +419,19 @@ def test_iter():
418
419
assert k in keys , "iteration produces key " + k
419
420
420
421
assert len (keys ) == len (keys2 ), "iteration produces no extra keys"
422
+
423
+
424
+ def test_debc026_component_not_children ():
425
+ children = [Component (id = 'a' ), html .Div (id = 'b' ), 'c' , 1 ]
426
+ for i in range (len (children )):
427
+ # cycle through each component in each position
428
+ children = children [1 :] + [children [0 ]]
429
+
430
+ # use html.Div because only real components accept positional args
431
+ html .Div (children )
432
+ # the first arg is children, and a single component works there
433
+ html .Div (children [0 ], id = 'x' )
434
+
435
+ with pytest .raises (TypeError ):
436
+ # If you forget the `[]` around children you get this:
437
+ html .Div (children [0 ], children [1 ], children [2 ], children [3 ])
0 commit comments