test_widget_box.py 995 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. from unittest import TestCase
  4. from traitlets import TraitError
  5. import ipywidgets as widgets
  6. class TestBox(TestCase):
  7. def test_construction(self):
  8. box = widgets.Box()
  9. assert box.get_state()['children'] == []
  10. def test_construction_with_children(self):
  11. html = widgets.HTML('some html')
  12. slider = widgets.IntSlider()
  13. box = widgets.Box([html, slider])
  14. children_state = box.get_state()['children']
  15. assert children_state == [
  16. widgets.widget._widget_to_json(html, None),
  17. widgets.widget._widget_to_json(slider, None),
  18. ]
  19. def test_construction_style(self):
  20. box = widgets.Box(box_style='warning')
  21. assert box.get_state()['box_style'] == 'warning'
  22. def test_construction_invalid_style(self):
  23. with self.assertRaises(TraitError):
  24. widgets.Box(box_style='invalid')