-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Calendar and CalendarDateRange for real date types (#348)
Date and DateRange as kepts for hybrid date/datetime for compatibility.
- Loading branch information
1 parent
4d6d346
commit 44a95ca
Showing
6 changed files
with
324 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Unit test for CalendarDate parameters. | ||
""" | ||
|
||
import unittest | ||
import datetime as dt | ||
import param | ||
|
||
|
||
class TestDateTimeParameters(unittest.TestCase): | ||
|
||
def test_initialization_out_of_bounds(self): | ||
try: | ||
class Q(param.Parameterized): | ||
q = param.Date(dt.date(2017,2,27), | ||
bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26))) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_set_out_of_bounds(self): | ||
class Q(param.Parameterized): | ||
q = param.Date(bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26))) | ||
try: | ||
Q.q = dt.date(2017,2,27) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_set_exclusive_out_of_bounds(self): | ||
class Q(param.Parameterized): | ||
q = param.Date(bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26)), | ||
inclusive_bounds=(True, False)) | ||
try: | ||
Q.q = dt.date(2017,2,26) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_get_soft_bounds(self): | ||
q = param.Date(dt.date(2017,2,25), | ||
bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26)), | ||
softbounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,25))) | ||
self.assertEqual(q.get_soft_bounds(), (dt.date(2017,2,1), | ||
dt.date(2017,2,25))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Unit tests for CalendarDateRange parameter. | ||
""" | ||
|
||
import unittest | ||
import datetime as dt | ||
import param | ||
|
||
|
||
# Assuming tests of range parameter cover most of what's needed to | ||
# test date range. | ||
|
||
class TestDateTimeRange(unittest.TestCase): | ||
|
||
bad_range = (dt.date(2017,2,27),dt.date(2017,2,26)) | ||
|
||
def test_wrong_type_default(self): | ||
try: | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange(default=(1.0,2.0)) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_wrong_type_init(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
try: | ||
Q(a=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_wrong_type_set(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
q = Q() | ||
|
||
try: | ||
q.a = self.bad_range | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_start_before_end_default(self): | ||
try: | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange(default=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") | ||
|
||
def test_start_before_end_init(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
try: | ||
Q(a=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") | ||
|
||
def test_start_before_end_set(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
q = Q() | ||
try: | ||
q.a = self.bad_range | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Unit test for CalendarDate parameters. | ||
""" | ||
|
||
|
||
import datetime as dt | ||
import param | ||
from . import API1TestCase | ||
|
||
|
||
class TestDateTimeParameters(API1TestCase): | ||
|
||
def test_initialization_out_of_bounds(self): | ||
try: | ||
class Q(param.Parameterized): | ||
q = param.CalendarDate(dt.date(2017,2,27), | ||
bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26))) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_set_out_of_bounds(self): | ||
class Q(param.Parameterized): | ||
q = param.CalendarDate(bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26))) | ||
try: | ||
Q.q = dt.date(2017,2,27) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_set_exclusive_out_of_bounds(self): | ||
class Q(param.Parameterized): | ||
q = param.CalendarDate(bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26)), | ||
inclusive_bounds=(True, False)) | ||
try: | ||
Q.q = dt.date(2017,2,26) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("No exception raised on out-of-bounds date") | ||
|
||
def test_get_soft_bounds(self): | ||
q = param.CalendarDate(dt.date(2017,2,25), | ||
bounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,26)), | ||
softbounds=(dt.date(2017,2,1), | ||
dt.date(2017,2,25))) | ||
self.assertEqual(q.get_soft_bounds(), (dt.date(2017,2,1), | ||
dt.date(2017,2,25))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
Unit tests for CalendarDateRange parameter. | ||
""" | ||
|
||
import datetime as dt | ||
import param | ||
from . import API1TestCase | ||
|
||
# Assuming tests of range parameter cover most of what's needed to | ||
# test date range. | ||
|
||
class TestDateTimeRange(API1TestCase): | ||
|
||
bad_range = (dt.date(2017,2,27),dt.date(2017,2,26)) | ||
|
||
def test_wrong_type_default(self): | ||
try: | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange(default=(1.0,2.0)) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_wrong_type_init(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
try: | ||
Q(a=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_wrong_type_set(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
q = Q() | ||
|
||
try: | ||
q.a = self.bad_range | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date type was accepted.") | ||
|
||
def test_start_before_end_default(self): | ||
try: | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange(default=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") | ||
|
||
def test_start_before_end_init(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
try: | ||
Q(a=self.bad_range) | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") | ||
|
||
def test_start_before_end_set(self): | ||
class Q(param.Parameterized): | ||
a = param.CalendarDateRange() | ||
|
||
q = Q() | ||
try: | ||
q.a = self.bad_range | ||
except ValueError: | ||
pass | ||
else: | ||
raise AssertionError("Bad date range was accepted.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters