1 7
import pytest
2

3 7
from bokeh.models import (
4
    Div, Tabs as BkTabs, Panel as BkPanel, Spacer as BkSpacer
5
)
6

7 7
from panel.layout import Tabs
8 7
from panel.pane import Pane
9

10

11 7
@pytest.fixture
12 2
def tabs(document, comm):
13
    """Set up a tabs instance"""
14 7
    div1, div2 = Div(), Div()
15

16 7
    return Tabs(('Tab1', div1), ('Tab2', div2))
17

18

19 7
def assert_tab_is_similar(tab1, tab2):
20
    """Helper function to check tab match"""
21 7
    assert tab1.child is tab2.child
22 7
    assert tab1.name == tab2.name
23 7
    assert tab1.title == tab2.title
24

25

26

27 7
def test_tabs_basic_constructor(document, comm):
28 7
    tabs = Tabs('plain', 'text')
29

30 7
    model = tabs.get_root(document, comm=comm)
31

32 7
    assert isinstance(model, BkTabs)
33 7
    assert len(model.tabs) == 2
34 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
35 7
    tab1, tab2 = model.tabs
36

37 7
    assert 'plain' in tab1.child.text
38 7
    assert 'text' in tab2.child.text
39

40

41 7
def test_tabs_constructor(document, comm):
42 7
    div1 = Div()
43 7
    div2 = Div()
44 7
    tabs = Tabs(('Div1', div1), ('Div2', div2))
45

46 7
    model = tabs.get_root(document, comm=comm)
47

48 7
    assert isinstance(model, BkTabs)
49 7
    assert len(model.tabs) == 2
50 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
51 7
    tab1, tab2 = model.tabs
52

53 7
    assert tab1.title == 'Div1'
54 7
    assert tab1.child is div1
55 7
    assert tab2.title == 'Div2'
56 7
    assert tab2.child is div2
57

58

59 7
def test_tabs_implicit_constructor(document, comm):
60 7
    div1, div2 = Div(), Div()
61 7
    p1 = Pane(div1, name='Div1')
62 7
    p2 = Pane(div2, name='Div2')
63 7
    tabs = Tabs(p1, p2)
64

65 7
    model = tabs.get_root(document, comm=comm)
66

67 7
    assert isinstance(model, BkTabs)
68 7
    assert len(model.tabs) == 2
69 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
70 7
    tab1, tab2 = model.tabs
71

72 7
    assert tab1.title == tab1.name == p1.name == 'Div1'
73 7
    assert tab1.child is div1
74 7
    assert tab2.title == tab2.name == p2.name == 'Div2'
75 7
    assert tab2.child is div2
76

77

78 7
def test_tabs_constructor_with_named_objects(document, comm):
79 7
    div1, div2 = Div(), Div()
80 7
    p1 = Pane(div1, name='Div1')
81 7
    p2 = Pane(div2, name='Div2')
82 7
    tabs = Tabs(('Tab1', p1), ('Tab2', p2))
83

84 7
    model = tabs.get_root(document, comm=comm)
85

86 7
    assert isinstance(model, BkTabs)
87 7
    assert len(model.tabs) == 2
88 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
89 7
    tab1, tab2 = model.tabs
90

91 7
    assert tab1.title == 'Tab1'
92 7
    assert tab1.name == p1.name == 'Div1'
93 7
    assert tab1.child is div1
94 7
    assert tab2.title == 'Tab2'
95 7
    assert tab2.name == p2.name =='Div2'
96 7
    assert tab2.child is div2
97

98

99 7
def test_tabs_cleanup_panels(document, comm, tabs):
100 7
    model = tabs.get_root(document, comm=comm)
101

102 7
    assert model.ref['id'] in tabs._panels
103 7
    tabs._cleanup(model)
104 7
    assert model.ref['id'] not in tabs._panels
105

106

107 7
def test_tabs_add(document, comm):
108 7
    div1 = Div()
109 7
    div2 = Div()
110 7
    tabs1 = Tabs(('Div1', div1), ('Div2', div2))
111 7
    div3 = Div()
112 7
    div4 = Div()
113 7
    tabs2 = Tabs(('Div3', div3), ('Div4', div4))
114

115 7
    combined = tabs1 + tabs2
116

117 7
    model = combined.get_root(document, comm=comm)
118

119 7
    assert isinstance(model, BkTabs)
120 7
    assert len(model.tabs) == 4
121 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
122 7
    tab1, tab2, tab3, tab4 = model.tabs
123

124 7
    assert tab1.title == 'Div1'
125 7
    assert tab1.child is div1
126 7
    assert tab2.title == 'Div2'
127 7
    assert tab2.child is div2
128 7
    assert tab3.title == 'Div3'
129 7
    assert tab3.child is div3
130 7
    assert tab4.title == 'Div4'
131 7
    assert tab4.child is div4
132

133

134 7
def test_tabs_add_list(document, comm):
135 7
    div1 = Div()
136 7
    div2 = Div()
137 7
    tabs1 = Tabs(('Div1', div1), ('Div2', div2))
138 7
    div3 = Div()
139 7
    div4 = Div()
140

141 7
    combined = tabs1 + [('Div3', div3), ('Div4', div4)]
142

143 7
    model = combined.get_root(document, comm=comm)
144

145 7
    assert isinstance(model, BkTabs)
146 7
    assert len(model.tabs) == 4
147 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
148 7
    tab1, tab2, tab3, tab4 = model.tabs
149

150 7
    assert tab1.title == 'Div1'
151 7
    assert tab1.child is div1
152 7
    assert tab2.title == 'Div2'
153 7
    assert tab2.child is div2
154 7
    assert tab3.title == 'Div3'
155 7
    assert tab3.child is div3
156 7
    assert tab4.title == 'Div4'
157 7
    assert tab4.child is div4
158

159

160 7
def test_tabs_radd_list(document, comm):
161 7
    div1 = Div()
162 7
    div2 = Div()
163 7
    tabs1 = Tabs(('Div1', div1), ('Div2', div2))
164 7
    div3 = Div()
165 7
    div4 = Div()
166

167 7
    combined = [('Div3', div3), ('Div4', div4)] + tabs1
168

169 7
    model = combined.get_root(document, comm=comm)
170

171 7
    assert isinstance(model, BkTabs)
172 7
    assert len(model.tabs) == 4
173 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
174 7
    tab3, tab4, tab1, tab2 = model.tabs
175

176 7
    assert tab1.title == 'Div1'
177 7
    assert tab1.child is div1
178 7
    assert tab2.title == 'Div2'
179 7
    assert tab2.child is div2
180 7
    assert tab3.title == 'Div3'
181 7
    assert tab3.child is div3
182 7
    assert tab4.title == 'Div4'
183 7
    assert tab4.child is div4
184

185

186 7
def test_tabs_set_panes(document, comm):
187 7
    div1, div2 = Div(), Div()
188 7
    p1 = Pane(div1, name='Div1')
189 7
    p2 = Pane(div2, name='Div2')
190 7
    tabs = Tabs(p1, p2)
191

192 7
    model = tabs.get_root(document, comm=comm)
193

194 7
    div3 = Div()
195 7
    p3 = Pane(div3, name='Div3')
196 7
    tabs.objects = [p1, p2, p3]
197

198 7
    assert isinstance(model, BkTabs)
199 7
    assert len(model.tabs) == 3
200 7
    assert all(isinstance(c, BkPanel) for c in model.tabs)
201 7
    tab1, tab2, tab3 = model.tabs
202

203 7
    assert tab1.title == tab1.name == p1.name =='Div1'
204 7
    assert tab1.child is div1
205 7
    assert tab2.title == tab2.name == p2.name =='Div2'
206 7
    assert tab2.child is div2
207 7
    assert tab3.title == tab3.name == p3.name =='Div3'
208 7
    assert tab3.child is div3
209

210

211 7
def test_tabs_reverse(document, comm):
212 7
    div1, div2 = Div(), Div()
213 7
    p1 = Pane(div1, name='Div1')
214 7
    p2 = Pane(div2, name='Div2')
215 7
    tabs = Tabs(p1, p2)
216

217 7
    model = tabs.get_root(document, comm=comm)
218

219 7
    tabs.reverse()
220 7
    tab1, tab2 = model.tabs
221 7
    assert tab1.child is div2
222 7
    assert tab1.title == tab1.name == p2.name == 'Div2'
223 7
    assert tab2.child is div1
224 7
    assert tab2.title == tab2.name == p1.name == 'Div1'
225

226

227 7
def test_tabs_append(document, comm, tabs):
228 7
    model = tabs.get_root(document, comm=comm)
229 7
    tab1_before, tab2_before = model.tabs
230

231 7
    div3 = Div()
232 7
    tabs.append(div3)
233

234 7
    tab1, tab2, tab3 = model.tabs
235 7
    assert_tab_is_similar(tab1_before, tab1)
236 7
    assert_tab_is_similar(tab2_before, tab2)
237

238 7
    assert tab3.child is div3
239

240

241 7
def test_empty_tabs_append(document, comm):
242 7
    tabs = Tabs()
243

244 7
    model = tabs.get_root(document, comm=comm)
245

246 7
    div1 = Div()
247 7
    tabs.append(('test title', div1))
248 7
    assert len(model.tabs) == 1
249 7
    assert model.tabs[0].title == 'test title'
250

251

252 7
def test_tabs_close_tab_in_notebook(document, comm, tabs):
253 7
    model = tabs.get_root(document, comm=comm)
254 7
    old_tabs = list(model.tabs)
255 7
    _, div2 = tabs
256

257 7
    tabs._comm_change(document, model.ref['id'], comm, 'tabs', old_tabs, [model.tabs[1]])
258

259 7
    assert len(tabs.objects) == 1
260 7
    assert tabs.objects[0] is div2
261

262

263 7
def test_tabs_close_tab_on_server(document, comm, tabs):
264 7
    model = tabs.get_root(document, comm=comm)
265 7
    _, div2 = tabs
266

267 7
    tabs._server_change(document, model.ref['id'], 'tabs', model.tabs, model.tabs[1:])
268

269 7
    assert len(tabs.objects) == 1
270 7
    assert tabs.objects[0] is div2
271

272

273 7
def test_dynamic_tabs(document, comm, tabs):
274 7
    tabs.dynamic = True
275 7
    model = tabs.get_root(document, comm=comm)
276 7
    div1, div2 = tabs
277

278 7
    tab1, tab2 = model.tabs
279 7
    assert tab1.child is div1.object
280 7
    assert isinstance(tab2.child, BkSpacer)
281

282 7
    tabs.active = 1
283

284 7
    tab1, tab2 = model.tabs
285 7
    assert isinstance(tab1.child, BkSpacer)
286 7
    assert tab2.child is div2.object
287

288 7
    tabs.dynamic = False
289

290 7
    tab1, tab2 = model.tabs
291 7
    assert tab1.child is div1.object
292 7
    assert tab2.child is div2.object
293

294 7
    tabs.param.set_param(dynamic=True, active=0)
295

296 7
    tab1, tab2 = model.tabs
297 7
    assert tab1.child is div1.object
298 7
    assert isinstance(tab2.child, BkSpacer)
299

300

301 7
def test_tabs_append_uses_object_name(document, comm, tabs):
302 7
    model = tabs.get_root(document, comm=comm)
303 7
    tab1_before, tab2_before = model.tabs
304

305 7
    div3 = Div()
306 7
    p3 = Pane(div3, name='Div3')
307 7
    tabs.append(p3)
308

309 7
    tab1, tab2, tab3 = model.tabs
310 7
    assert_tab_is_similar(tab1_before, tab1)
311 7
    assert_tab_is_similar(tab2_before, tab2)
312

313 7
    assert tab3.child is div3
314 7
    assert tab3.title == tab3.name == p3.name == 'Div3'
315

316

317 7
def test_tabs_append_with_tuple_and_unnamed_contents(document, comm, tabs):
318 7
    model = tabs.get_root(document, comm=comm)
319 7
    tab1_before, tab2_before = model.tabs
320

321 7
    div3 = Div()
322 7
    tabs.append(('Div3', div3))
323

324 7
    tab1, tab2, tab3 = model.tabs
325 7
    assert_tab_is_similar(tab1_before, tab1)
326 7
    assert_tab_is_similar(tab2_before, tab2)
327

328 7
    assert tab3.child is div3
329 7
    assert tab3.title == 'Div3'
330

331

332 7
def test_tabs_append_with_tuple_and_named_contents(document, comm, tabs):
333 7
    model = tabs.get_root(document, comm=comm)
334 7
    tab1_before, tab2_before = model.tabs
335

336 7
    div3 = Div()
337 7
    p3 = Pane(div3, name='Div3')
338 7
    tabs.append(('Tab3', p3))
339

340 7
    tab1, tab2, tab3 = model.tabs
341 7
    assert_tab_is_similar(tab1_before, tab1)
342 7
    assert_tab_is_similar(tab2_before, tab2)
343

344 7
    assert tab3.child is div3
345 7
    assert tab3.title == 'Tab3'
346 7
    assert tab3.name == p3.name == 'Div3'
347

348

349 7
def test_tabs_extend(document, comm, tabs):
350 7
    model = tabs.get_root(document, comm=comm)
351 7
    tab1_before, tab2_before = model.tabs
352

353 7
    div3, div4 = Div(), Div()
354 7
    tabs.extend([div4, div3])
355

356 7
    tab1, tab2, tab3, tab4 = model.tabs
357 7
    assert_tab_is_similar(tab1_before, tab1)
358 7
    assert_tab_is_similar(tab2_before, tab2)
359

360 7
    assert tab3.child is div4
361 7
    assert tab4.child is div3
362

363

364 7
def test_tabs_iadd(document, comm, tabs):
365 7
    model = tabs.get_root(document, comm=comm)
366 7
    tab1_before, tab2_before = model.tabs
367

368 7
    div3, div4 = Div(), Div()
369 7
    tabs += [div4, div3]
370

371 7
    tab1, tab2, tab3, tab4 = model.tabs
372 7
    assert_tab_is_similar(tab1_before, tab1)
373 7
    assert_tab_is_similar(tab2_before, tab2)
374

375 7
    assert tab3.child is div4
376 7
    assert tab4.child is div3
377

378
    
379 7
def test_tabs_extend_uses_object_name(document, comm, tabs):
380 7
    model = tabs.get_root(document, comm=comm)
381 7
    tab1_before, tab2_before = model.tabs
382

383 7
    div3, div4 = Div(), Div()
384 7
    p3, p4 = Pane(div3, name='Div3'), Pane(div4, name='Div4')
385 7
    tabs.extend([p4, p3])
386

387 7
    tab1, tab2, tab3, tab4 = model.tabs
388 7
    assert_tab_is_similar(tab1_before, tab1)
389 7
    assert_tab_is_similar(tab2_before, tab2)
390

391 7
    assert tab3.child is div4
392 7
    assert tab3.title == p4.name == 'Div4'
393 7
    assert tab4.child is div3
394 7
    assert tab4.title  == p3.name == 'Div3'
395

396

397 7
def test_tabs_extend_with_tuple_and_unnamed_contents(document, comm, tabs):
398 7
    model = tabs.get_root(document, comm=comm)
399 7
    tab1_before, tab2_before = model.tabs
400

401 7
    div3, div4 = Div(), Div()
402 7
    tabs.extend([('Div4', div4), ('Div3', div3)])
403

404 7
    tab1, tab2, tab3, tab4 = model.tabs
405 7
    assert_tab_is_similar(tab1_before, tab1)
406 7
    assert_tab_is_similar(tab2_before, tab2)
407

408 7
    assert tab3.child is div4
409 7
    assert tab3.title == 'Div4'
410 7
    assert tab4.child is div3
411 7
    assert tab4.title == 'Div3'
412

413

414 7
def test_tabs_extend_with_tuple_and_named_contents(document, comm, tabs):
415 7
    model = tabs.get_root(document, comm=comm)
416 7
    tab1_before, tab2_before = model.tabs
417

418 7
    div3, div4 = Div(), Div()
419 7
    p3, p4 = Pane(div3, name='Div3'), Pane(div4, name='Div4')
420 7
    tabs.extend([('Tab4', p4), ('Tab3', p3)])
421

422 7
    tab1, tab2, tab3, tab4 = model.tabs
423 7
    assert_tab_is_similar(tab1_before, tab1)
424 7
    assert_tab_is_similar(tab2_before, tab2)
425

426 7
    assert tab3.child is div4
427 7
    assert tab3.title == 'Tab4'
428 7
    assert tab3.name == p4.name == 'Div4'
429 7
    assert tab4.child is div3
430 7
    assert tab4.title == 'Tab3'
431 7
    assert tab4.name == p3.name == 'Div3'
432

433

434 7
def test_tabs_insert(document, comm, tabs):
435 7
    model = tabs.get_root(document, comm=comm)
436 7
    tab1_before, tab2_before = model.tabs
437

438 7
    div3 = Div()
439 7
    tabs.insert(1, div3)
440

441 7
    tab1, tab2, tab3 = model.tabs
442

443 7
    assert_tab_is_similar(tab1_before, tab1)
444 7
    assert tab2.child is div3
445 7
    assert_tab_is_similar(tab2_before, tab3)
446

447

448 7
def test_tabs_insert_uses_object_name(document, comm, tabs):
449 7
    model = tabs.get_root(document, comm=comm)
450 7
    tab1_before, tab2_before = model.tabs
451

452 7
    div3 = Div()
453 7
    p3 = Pane(div3, name='Div3')
454 7
    tabs.insert(1, p3)
455

456 7
    tab1, tab2, tab3 = model.tabs
457

458 7
    assert_tab_is_similar(tab1_before, tab1)
459 7
    assert tab2.child is div3
460 7
    assert tab2.title == tab2.name == p3.name == 'Div3'
461 7
    assert_tab_is_similar(tab2_before, tab3)
462

463

464 7
def test_tabs_insert_with_tuple_and_unnamed_contents(document, comm, tabs):
465 7
    model = tabs.get_root(document, comm=comm)
466 7
    tab1_before, tab2_before = model.tabs
467

468 7
    div3 = Div()
469 7
    tabs.insert(1, ('Div3', div3))
470 7
    tab1, tab2, tab3 = model.tabs
471

472 7
    assert_tab_is_similar(tab1_before, tab1)
473 7
    assert tab2.child is div3
474 7
    assert tab2.title == 'Div3'
475 7
    assert_tab_is_similar(tab2_before, tab3)
476

477

478 7
def test_tabs_insert_with_tuple_and_named_contents(document, comm, tabs):
479 7
    model = tabs.get_root(document, comm=comm)
480 7
    tab1_before, tab2_before = model.tabs
481

482 7
    div3 = Div()
483 7
    p3 = Pane(div3, name='Div3')
484 7
    tabs.insert(1, ('Tab3', p3))
485 7
    tab1, tab2, tab3 = model.tabs
486

487 7
    assert_tab_is_similar(tab1_before, tab1)
488 7
    assert tab2.child is div3
489 7
    assert tab2.title == 'Tab3'
490 7
    assert tab2.name  == p3.name == 'Div3'
491 7
    assert_tab_is_similar(tab2_before, tab3)
492

493

494 7
def test_tabs_setitem(document, comm):
495 7
    div1 = Div()
496 7
    div2 = Div()
497 7
    tabs = Tabs(div1, div2)
498 7
    p1, p2 = tabs.objects
499

500 7
    model = tabs.get_root(document, comm=comm)
501

502 7
    tab1, tab2 = model.tabs
503 7
    assert p1._models[model.ref['id']][0] is tab1.child
504 7
    div3 = Div()
505 7
    tabs[0] = ('C', div3)
506 7
    tab1, tab2 = model.tabs
507 7
    assert tab1.child is div3
508 7
    assert tab1.title == 'C'
509 7
    assert tab2.child is div2
510 7
    assert p1._models == {}
511

512

513 7
def test_tabs_clone():
514 7
    div1 = Div()
515 7
    div2 = Div()
516 7
    tabs = Tabs(Pane(div1), Pane(div2))
517 7
    clone = tabs.clone()
518

519 7
    assert ([(k, v) for k, v in tabs.param.get_param_values() if k != 'name'] ==
520
            [(k, v) for k, v in clone.param.get_param_values() if k != 'name'])
521

522

523 7
def test_tabs_clone_args():
524 7
    div1 = Div()
525 7
    div2 = Div()
526 7
    tabs = Tabs(div1, div2)
527 7
    clone = tabs.clone(div2, div1)
528

529 7
    assert tabs.objects[0].object is clone.objects[1].object
530 7
    assert tabs.objects[1].object is clone.objects[0].object
531

532

533 7
def test_tabs_clone_kwargs():
534 7
    div1 = Div()
535 7
    div2 = Div()
536 7
    tabs = Tabs(div1, div2)
537 7
    clone = tabs.clone(width=400, sizing_mode='stretch_height')
538

539 7
    assert clone.width == 400
540 7
    assert clone.sizing_mode == 'stretch_height'
541

542

543 7
def test_tabs_setitem_out_of_bounds(document, comm):
544 7
    div1 = Div()
545 7
    div2 = Div()
546 7
    layout = Tabs(div1, div2)
547

548 7
    layout.get_root(document, comm=comm)
549 7
    div3 = Div()
550 7
    with pytest.raises(IndexError):
551 7
        layout[2] = div3
552

553

554 7
def test_tabs_setitem_replace_all(document, comm):
555 7
    div1 = Div()
556 7
    div2 = Div()
557 7
    layout = Tabs(div1, div2)
558 7
    p1, p2 = layout.objects
559

560 7
    model = layout.get_root(document, comm=comm)
561

562 7
    assert p1._models[model.ref['id']][0] is model.tabs[0].child
563 7
    div3 = Div()
564 7
    div4 = Div()
565 7
    layout[:] = [('B', div3), ('C', div4)]
566 7
    tab1, tab2 = model.tabs
567 7
    assert tab1.child is div3
568 7
    assert tab1.title == 'B'
569 7
    assert tab2.child is div4
570 7
    assert tab2.title == 'C'
571 7
    assert p1._models == {}
572 7
    assert p2._models == {}
573

574

575 7
def test_tabs_setitem_replace_all_error(document, comm):
576 7
    div1 = Div()
577 7
    div2 = Div()
578 7
    layout = Tabs(div1, div2)
579 7
    layout.get_root(document, comm=comm)
580

581 7
    div3 = Div()
582 7
    with pytest.raises(IndexError):
583 7
        layout[:] = div3
584

585

586 7
def test_tabs_setitem_replace_slice(document, comm):
587 7
    div1 = Div()
588 7
    div2 = Div()
589 7
    div3 = Div()
590 7
    layout = Tabs(('A', div1), ('B', div2), ('C', div3))
591 7
    p1, p2, p3 = layout.objects
592

593 7
    model = layout.get_root(document, comm=comm)
594

595 7
    assert p1._models[model.ref['id']][0] is model.tabs[0].child
596 7
    div3 = Div()
597 7
    div4 = Div()
598 7
    layout[1:] = [('D', div3), ('E', div4)]
599 7
    tab1, tab2, tab3 = model.tabs
600 7
    assert tab1.child is div1
601 7
    assert tab1.title == 'A'
602 7
    assert tab2.child is div3
603 7
    assert tab2.title == 'D'
604 7
    assert tab3.child is div4
605 7
    assert tab3.title == 'E'
606 7
    assert p2._models == {}
607 7
    assert p3._models == {}
608

609

610 7
def test_tabs_setitem_replace_slice_error(document, comm):
611 7
    div1 = Div()
612 7
    div2 = Div()
613 7
    div3 = Div()
614 7
    layout = Tabs(div1, div2, div3)
615 7
    layout.get_root(document, comm=comm)
616

617 7
    div3 = Div()
618 7
    with pytest.raises(IndexError):
619 7
        layout[1:] = [div3]
620

621

622 7
def test_tabs_setitem_replace_slice_out_of_bounds(document, comm):
623 7
    div1 = Div()
624 7
    div2 = Div()
625 7
    div3 = Div()
626 7
    layout = Tabs(div1, div2, div3)
627 7
    layout.get_root(document, comm=comm)
628

629 7
    div3 = Div()
630 7
    with pytest.raises(IndexError):
631 7
        layout[3:4] = [div3]
632

633

634 7
def test_tabs_pop(document, comm):
635 7
    div1 = Div()
636 7
    div2 = Div()
637 7
    tabs = Tabs(div1, div2)
638 7
    p1, p2 = tabs.objects
639

640 7
    model = tabs.get_root(document, comm=comm)
641

642 7
    tab1 = model.tabs[0]
643 7
    assert p1._models[model.ref['id']][0] is tab1.child
644 7
    tabs.pop(0)
645 7
    assert len(model.tabs) == 1
646 7
    tab1 = model.tabs[0]
647 7
    assert tab1.child is div2
648 7
    assert p1._models == {}
649

650

651 7
def test_tabs_remove(document, comm):
652 7
    div1 = Div()
653 7
    div2 = Div()
654 7
    tabs = Tabs(div1, div2)
655 7
    p1, p2 = tabs.objects
656

657 7
    model = tabs.get_root(document, comm=comm)
658

659 7
    tab1 = model.tabs[0]
660 7
    assert p1._models[model.ref['id']][0] is tab1.child
661 7
    tabs.remove(p1)
662 7
    assert len(model.tabs) == 1
663 7
    tab1 = model.tabs[0]
664 7
    assert tab1.child is div2
665 7
    assert p1._models == {}
666

667

668 7
def test_tabs_clear(document, comm):
669 7
    div1 = Div()
670 7
    div2 = Div()
671 7
    tabs = Tabs(div1, div2)
672 7
    p1, p2 = tabs.objects
673

674 7
    model = tabs.get_root(document, comm=comm)
675

676 7
    tabs.clear()
677 7
    assert tabs._names == []
678 7
    assert len(model.tabs) == 0
679 7
    assert p1._models == p2._models == {}

Read our documentation on viewing source code .

Loading