Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
428 additions
and
13 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,86 @@ | ||
from pandas import Timestamp | ||
from nose_parameterized import parameterized | ||
|
||
from zipline.testing import ZiplineTestCase | ||
from zipline.utils.calendars import get_calendar | ||
from zipline.utils.date_utils import compute_date_range_chunks | ||
|
||
|
||
def T(s): | ||
""" | ||
Helpful function to improve readibility. | ||
""" | ||
return Timestamp(s, tz='UTC') | ||
|
||
|
||
class TestDateUtils(ZiplineTestCase): | ||
|
||
@classmethod | ||
def init_class_fixtures(cls): | ||
super(TestDateUtils, cls).init_class_fixtures() | ||
cls.calendar = get_calendar('NYSE') | ||
|
||
@parameterized.expand([ | ||
(None, [(T('2017-01-03'), T('2017-01-31'))]), | ||
(10, [ | ||
(T('2017-01-03'), T('2017-01-17')), | ||
(T('2017-01-18'), T('2017-01-31')) | ||
]), | ||
(15, [ | ||
(T('2017-01-03'), T('2017-01-24')), | ||
(T('2017-01-25'), T('2017-01-31')) | ||
]), | ||
]) | ||
def test_compute_date_range_chunks(self, chunksize, expected): | ||
# This date range results in 20 business days | ||
start_date = T('2017-01-03') | ||
end_date = T('2017-01-31') | ||
|
||
date_ranges = compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
start_date, | ||
end_date, | ||
chunksize | ||
) | ||
|
||
self.assertListEqual(list(date_ranges), expected) | ||
|
||
def test_compute_date_range_chunks_invalid_input(self): | ||
# Start date not found in calendar | ||
with self.assertRaises(KeyError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-05-07'), # Sunday | ||
T('2017-06-01'), | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"'Start date 2017-05-07 is not found in calendar.'" | ||
) | ||
|
||
# End date not found in calendar | ||
with self.assertRaises(KeyError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-05-01'), | ||
T('2017-05-27'), # Saturday | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"'End date 2017-05-27 is not found in calendar.'" | ||
) | ||
|
||
# End date before start date | ||
with self.assertRaises(ValueError) as cm: | ||
compute_date_range_chunks( | ||
self.calendar.all_sessions, | ||
T('2017-06-01'), | ||
T('2017-05-01'), | ||
None | ||
) | ||
self.assertEqual( | ||
str(cm.exception), | ||
"End date 2017-05-01 cannot precede start date 2017-06-01." | ||
) |
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,21 @@ | ||
from zipline.testing import ZiplineTestCase | ||
from zipline.utils.sharedoc import copydoc | ||
|
||
|
||
class TestSharedoc(ZiplineTestCase): | ||
|
||
def test_copydoc(self): | ||
def original_docstring_function(): | ||
""" | ||
My docstring brings the boys to the yard. | ||
""" | ||
pass | ||
|
||
@copydoc(original_docstring_function) | ||
def copied_docstring_function(): | ||
pass | ||
|
||
self.assertEqual( | ||
original_docstring_function.__doc__, | ||
copied_docstring_function.__doc__ | ||
) |
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
Oops, something went wrong.