Skip to content

Commit

Permalink
Fix a bug in the clone method of the layouts (#1349)
Browse files Browse the repository at this point in the history
* Fix clone method of layout

* Add tests to clone method of layour
  • Loading branch information
maximlt authored May 16, 2020
1 parent 489cc0c commit c4e9d40
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion panel/layout/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def clone(self, *objects, **params):
% type(self).__name__)
p = dict(self.param.get_param_values(), **params)
del p['objects']
return type(self)(*objects, **params)
return type(self)(*objects, **p)

def append(self, obj):
"""
Expand Down
40 changes: 40 additions & 0 deletions panel/tests/layout/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,46 @@ def test_layout_clone_kwargs(panel):
assert clone.sizing_mode == 'stretch_height'


@pytest.mark.parametrize('panel', [Column, Row])
def test_layout_clone_no_args_no_kwargs(panel):
div1 = Div()
div2 = Div()
layout = panel(div1, div2, width=400, sizing_mode='stretch_height')
clone = layout.clone()

assert layout.objects[0].object is clone.objects[0].object
assert layout.objects[1].object is clone.objects[1].object

assert clone.width == 400
assert clone.sizing_mode == 'stretch_height'


@pytest.mark.parametrize('panel', [Column, Row])
def test_layout_clone_objects_in_kwargs(panel):
div1 = Div()
div2 = Div()
layout = panel(div1, div2)
clone = layout.clone(
objects=(div2, div1),
width=400, sizing_mode='stretch_height'
)

assert layout.objects[0].object is clone.objects[1].object
assert layout.objects[1].object is clone.objects[0].object

assert clone.width == 400
assert clone.sizing_mode == 'stretch_height'


@pytest.mark.parametrize('panel', [Column, Row])
def test_layout_clone_objects_in_args_and_kwargs(panel):
div1 = Div()
div2 = Div()
layout = panel(div1, div2)
with pytest.raises(ValueError):
layout.clone(div1, objects=div1)


def test_widgetbox(document, comm):
widget_box = WidgetBox("WidgetBox")

Expand Down

0 comments on commit c4e9d40

Please sign in to comment.