From 4e84b2c5ca442527e889a805f7dad5a9cad85402 Mon Sep 17 00:00:00 2001 From: Richard Frank Date: Thu, 4 Feb 2016 17:36:40 -0500 Subject: [PATCH] TST: Added doctest --- tests/test_doctests.py | 4 ++++ zipline/utils/data.py | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/test_doctests.py b/tests/test_doctests.py index 7ff2d5a2..c08659af 100644 --- a/tests/test_doctests.py +++ b/tests/test_doctests.py @@ -10,6 +10,7 @@ from zipline.pipeline import ( ) from zipline.utils import ( cache, + data, input_validation, memoize, numpy_utils, @@ -78,3 +79,6 @@ class DoctestTestCase(TestCase): def test_numpy_utils_docs(self): self._check_docs(numpy_utils) + + def test_data_docs(self): + self._check_docs(data) diff --git a/zipline/utils/data.py b/zipline/utils/data.py index 1f4788b5..9c10b8d7 100644 --- a/zipline/utils/data.py +++ b/zipline/utils/data.py @@ -419,16 +419,25 @@ class SortedDict(MutableMapping): >>> d[-1] = 'negative one' >>> d[0] = 'zero' >>> d[2] = 'two' - >>> d - SortedDict[]([(0, 'zero'), (-1, 'negative one'), (1, 'one')]) # noqa + >>> d # doctest: +NORMALIZE_WHITESPACE + SortedDict(, + [(0, 'zero'), (-1, 'negative one'), (2, 'two')]) >>> d[1] = 'one' # Mutating the mapping maintains the sort order. + >>> d # doctest: +NORMALIZE_WHITESPACE + SortedDict(, + [(0, 'zero'), (-1, 'negative one'), (1, 'one'), (2, 'two')]) + >>> del d[0] + >>> d # doctest: +NORMALIZE_WHITESPACE + SortedDict(, + [(-1, 'negative one'), (1, 'one'), (2, 'two')]) + >>> del d[2] >>> d - SortedDict[]([(0, 'zero'), (-1, 'negative one'), (1, 'one')]) # noqa + SortedDict(, [(-1, 'negative one'), (1, 'one')]) """ - def __init__(self, sort_key, mapping=None, **kwargs): + def __init__(self, key, mapping=None, **kwargs): self._map = {} self._sorted_key_names = [] - self._sort_key = sort_key + self._sort_key = key self.update(merge(mapping or {}, kwargs)) @@ -464,8 +473,8 @@ class SortedDict(MutableMapping): _repr_running[call_key] = 1 try: if not self: - return '%s[%r]()' % (self.__class__.__name__, self._sort_key) - return '%s[%r](%r)' % (self.__class__.__name__, self._sort_key, - self.items()) + return '%s(%r)' % (self.__class__.__name__, self._sort_key) + return '%s(%r, %r)' % (self.__class__.__name__, self._sort_key, + list(self.items())) finally: del _repr_running[call_key]