Skip to content

Commit

Permalink
Add DateRangePicker test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoMathurin committed Dec 11, 2023
1 parent 2a303c4 commit 90f15cb
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions panel/tests/widgets/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 90f15cb

Please sign in to comment.