From 109c2ac89fbecfb6ee7ea9793975743425d95c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Mathurin?= Date: Mon, 11 Dec 2023 11:34:54 +0100 Subject: [PATCH] Add DateRangePicker test --- panel/tests/widgets/test_input.py | 44 +++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/panel/tests/widgets/test_input.py b/panel/tests/widgets/test_input.py index a3e5140697d..c235a18d3eb 100644 --- a/panel/tests/widgets/test_input.py +++ b/panel/tests/widgets/test_input.py @@ -8,9 +8,9 @@ from panel import config from panel.widgets import ( - ArrayInput, Checkbox, DatePicker, DatetimeInput, DatetimePicker, - DatetimeRangeInput, DatetimeRangePicker, FileInput, FloatInput, IntInput, - LiteralInput, StaticText, TextInput, + ArrayInput, Checkbox, DatePicker, DateRangePicker, DatetimeInput, + DatetimePicker, DatetimeRangeInput, DatetimeRangePicker, FileInput, + FloatInput, IntInput, LiteralInput, StaticText, TextInput, ) @@ -58,6 +58,42 @@ def test_date_picker(document, comm): assert widget.value == '2018-09-04' +def test_daterange_picker(document, comm): + date_range_picker = DateRangePicker(name='DateRangePicker', + value=(date(2018, 9, 2), date(2018, 9, 3)), + start=date(2018, 9, 1), + end=date(2018, 9, 10)) + + widget = date_range_picker.get_root(document, comm=comm) + + assert isinstance(widget, date_range_picker._widget_type) + assert widget.title == 'DateRangePicker' + assert widget.value == ('2018-09-02', '2018-09-03') + assert widget.min_date == '2018-09-01' + assert widget.max_date == '2018-09-10' + + date_range_picker._process_events({'value': ('2018-09-03', '2018-09-04')}) + assert date_range_picker.value == (date(2018, 9, 3), date(2018, 9, 4)) + + date_range_picker._process_events({'value': ('2018-09-05', '2018-09-08')}) + assert date_range_picker.value == (date(2018, 9, 5), date(2018, 9, 8)) + + value = date_range_picker._process_param_change({'value': (date(2018, 9, 4), date(2018, 9, 5))}) + assert value['value'] == ('2018-09-04', '2018-09-05') + + value = date(2018, 9, 4) + assert date_range_picker._convert_date_to_string(value) == '2018-09-04' + assert date_range_picker._convert_string_to_date(date_range_picker._convert_date_to_string(value)) == value + + # Check start value + with pytest.raises(ValueError): + date_range_picker._process_events({'value': ('2018-08-31', '2018-09-01')}) + + # Check end value + with pytest.raises(ValueError): + date_range_picker._process_events({'value': ('2018-09-10', '2018-09-11')}) + + def test_datetime_picker(document, comm): datetime_picker = DatetimePicker( name='DatetimePicker', value=datetime(2018, 9, 2, 1, 5), @@ -94,7 +130,6 @@ def test_datetime_picker(document, comm): datetime_picker._process_events({'value': '2018-09-10 00:00:01'}) - def test_datetime_range_picker(document, comm): datetime_range_picker = DatetimeRangePicker( name='DatetimeRangePicker', value=(datetime(2018, 9, 2, 1, 5), datetime(2018, 9, 2, 1, 6)), @@ -130,7 +165,6 @@ def test_datetime_range_picker(document, comm): datetime_range_picker._process_events({'value': '2018-09-10 00:00:01'}) - def test_file_input(document, comm): file_input = FileInput(accept='.txt')