Skip to content

Commit

Permalink
TST: fix doctests to actually run
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Jevnik committed Jun 21, 2016
1 parent c0d08f9 commit 5925107
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ before_script:
- pip freeze | sort
script:
- flake8 zipline tests
- nosetests --with-coverage tests/
- nosetests --with-coverage
# deactive env to get access to anaconda command
- source deactivate
- if [[ "$TRAVIS_SECURE_ENV_VARS" = "true" && "$TRAVIS_BRANCH" = "master" && "$TRAVIS_PULL_REQUEST" = "false" ]]; then DO_UPLOAD="true"; else DO_UPLOAD="false"; fi
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ install:
- pip freeze | sort

test_script:
- nosetests tests/
- nosetests
- flake8 zipline tests

branches:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ with-ignore-docstrings=1
with-timer=1
timer-top-n=15
cover-package=zipline
with-doctest=1
testmatch=(?:^|[\\b_\\.-])[Tt]est(?!ing)

[metadata]
description-file = README.rst
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def to_dict(l):
Example
-------
>>> to_dict([2, 3, 4])
>>> to_dict([2, 3, 4]) # doctest: +SKIP
{'0': 2, '1': 3, '2': 4}
"""
return dict(zip(map(str, range(len(l))), l))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
#
# Copyright 2013 Quantopian, Inc.
#
Expand Down
91 changes: 0 additions & 91 deletions tests/test_doctests.py

This file was deleted.

2 changes: 1 addition & 1 deletion zipline/examples/olmar.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def simplex_projection(v, b=1):
:Example:
>>> proj = simplex_projection([.4 ,.3, -.4, .5])
>>> print(proj)
>>> proj # doctest: +NORMALIZE_WHITESPACE
array([ 0.33333333, 0.23333333, 0. , 0.43333333])
>>> print(proj.sum())
1.0
Expand Down
2 changes: 1 addition & 1 deletion zipline/lib/labelarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __array_finalize__(self, obj):
1. Someone tries to directly construct a new array by doing::
>>> ndarray.__new__(LabelArray, ...)
>>> ndarray.__new__(LabelArray, ...) # doctest: +SKIP
In this case, obj will be None. We treat this as an error case and
fail.
Expand Down
18 changes: 11 additions & 7 deletions zipline/pipeline/factors/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ class Factor(RestrictedDTypeMixin, ComputableTerm):
Factors. For example, constructing a Factor that computes the average of
two other Factors is simply::
>>> f1 = SomeFactor(...)
>>> f2 = SomeOtherFactor(...)
>>> average = (f1 + f2) / 2.0
>>> f1 = SomeFactor(...) # doctest: +SKIP
>>> f2 = SomeOtherFactor(...) # doctest: +SKIP
>>> average = (f1 + f2) / 2.0 # doctest: +SKIP
Factors can also be converted into :class:`zipline.pipeline.Filter` objects
via comparison operators: (``<``, ``<=``, ``!=``, ``eq``, ``>``, ``>=``).
Expand Down Expand Up @@ -492,8 +492,10 @@ def demean(self, mask=NotSpecified, groupby=NotSpecified):
to use the ``mask`` parameter to discard values at the extremes of the
distribution::
>>> base = MyFactor(...)
>>> normalized = base.demean(mask=base.percentile_between(1, 99))
>>> base = MyFactor(...) # doctest: +SKIP
>>> normalized = base.demean(
... mask=base.percentile_between(1, 99),
... ) # doctest: +SKIP
``demean()`` is only supported on Factors of dtype float64.
Expand Down Expand Up @@ -553,8 +555,10 @@ def zscore(self, mask=NotSpecified, groupby=NotSpecified):
outliers, it is often useful to use the ``mask`` parameter to discard
values at the extremes of the distribution::
>>> base = MyFactor(...)
>>> normalized = base.zscore(mask=base.percentile_between(1, 99))
>>> base = MyFactor(...) # doctest: +SKIP
>>> normalized = base.zscore(
... mask=base.percentile_between(1, 99),
... ) # doctest: +SKIP
``zscore()`` is only supported on Factors of dtype float64.
Expand Down
6 changes: 3 additions & 3 deletions zipline/pipeline/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def delimit(delimiters, content):
Surround `content` with the first and last characters of `delimiters`.
>>> delimit('[]', "foo")
[foo]
u'[foo]'
>>> delimit('""', "foo")
'"foo"'
u'"foo"'
"""
if len(delimiters) != 2:
raise ValueError(
Expand Down Expand Up @@ -220,7 +220,7 @@ def format_attrs(attrs):
Example
-------
>>> format_attrs({'key1': 'value1', 'key2': 'value2'})
>>> format_attrs({'key1': 'value1', 'key2': 'value2'}) # doctest: +SKIP
'[key1=value1, key2=value2]'
"""
if not attrs:
Expand Down
2 changes: 1 addition & 1 deletion zipline/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def alias(attr_name):
>>> class C(object):
... attr = 1
...
>>> class D(object):
>>> class D(C):
... attr_alias = alias('attr')
...
>>> D.attr
Expand Down
2 changes: 1 addition & 1 deletion zipline/utils/context_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CallbackManager(object):
>>> with manager('example'):
... print('inside example block')
entering example block
inside example
inside example block
exiting example block
These are reusable with different args:
Expand Down
2 changes: 1 addition & 1 deletion zipline/utils/control_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def invert(d):
"""
Invert a dictionary into a dictionary of sets.
>>> invert({'a': 1, 'b': 2, 'c': 1})
>>> invert({'a': 1, 'b': 2, 'c': 1}) # doctest: +SKIP
{1: {'a', 'c'}, 2: {'b'}}
"""
out = {}
Expand Down
6 changes: 4 additions & 2 deletions zipline/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ class AfterOpen(StatelessRule):
A rule that triggers for some offset after the market opens.
Example that triggers after 30 minutes of the market opening:
>>> AfterOpen(minutes=30)
>>> AfterOpen(minutes=30) # doctest: +ELLIPSIS
<zipline.utils.events.AfterOpen object at ...>
"""
def __init__(self, offset=None, **kwargs):
self.offset = _build_offset(
Expand Down Expand Up @@ -346,7 +347,8 @@ class BeforeClose(StatelessRule):
A rule that triggers for some offset time before the market closes.
Example that triggers for the last 30 minutes every day:
>>> BeforeClose(minutes=30)
>>> BeforeClose(minutes=30) # doctest: +ELLIPSIS
<zipline.utils.events.BeforeClose object at ...>
"""
def __init__(self, offset=None, **kwargs):
self.offset = _build_offset(
Expand Down
2 changes: 1 addition & 1 deletion zipline/utils/final.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class final(with_metaclass(ABCMeta)):
Example usage:
>>> from six import with_metaclass
>>> class C(with_metaclass(FinalMeta)):
>>> class C(with_metaclass(FinalMeta, object)):
... @final
... def f(self):
... return 'value'
Expand Down
4 changes: 3 additions & 1 deletion zipline/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,16 @@ def unzip(seq, elem_len=None):
>>> seq = [('a', 1), ('b', 2), ('c', 3, 'extra')]
>>> cs, ns = unzip(seq)
Traceback (most recent call last):
...
...
ValueError: element at index 2 was length 3, expected 2
# allows an explicit element length instead of infering
>>> seq = [('a', 1, 'extra'), ('b', 2), ('c', 3)]
>>> cs, ns = unzip(seq, 2)
Traceback (most recent call last):
...
ValueError: element at index 0 was length 3, expected 2
# handles empty sequences when a length is given
>>> cs, ns = unzip([], elem_len=2)
>>> cs == ns == ()
Expand Down
27 changes: 16 additions & 11 deletions zipline/utils/input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ def expect_dtypes(**named):
...
>>> foo(arange(3), 'foo')
(array([0, 1, 2]), 'foo')
>>> foo(arange(3, dtype=float), 'foo')
>>> foo(arange(3, dtype=float), 'foo') # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
TypeError: foo() expected an argument with dtype 'int64' for argument 'x', but got dtype 'float64' instead. # noqa
TypeError: zipline.utils.input_validation.foo() expected a value with
dtype 'int64' for argument 'x', but got 'float64' instead.
"""
for name, type_ in iteritems(named):
if not isinstance(type_, (dtype, tuple)):
Expand Down Expand Up @@ -278,10 +279,11 @@ def expect_kinds(**named):
2
>>> foo(int32(2))
2
>>> foo(float32(2))
>>> foo(float32(2)) # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...n
TypeError: foo() expected a numpy object of kind 'i' for argument 'x', but got 'f' instead. # noqa
...
TypeError: zipline.utils.input_validation.foo() expected a numpy object of
kind 'i' for argument 'x', but got 'f' instead.
"""
for name, kind in iteritems(named):
if not isinstance(kind, (str, tuple)):
Expand Down Expand Up @@ -337,10 +339,11 @@ def expect_types(*_pos, **named):
...
>>> foo(2, '3')
(2, '3')
>>> foo(2.0, '3')
>>> foo(2.0, '3') # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
TypeError: foo() expected an argument of type 'int' for argument 'x', but got float instead. # noqa
TypeError: zipline.utils.input_validation.foo() expected a value of type
int for argument 'x', but got float instead.
"""
if _pos:
raise TypeError("expect_types() only takes keyword arguments.")
Expand Down Expand Up @@ -463,10 +466,11 @@ def expect_element(*_pos, **named):
'A'
>>> foo('b')
'B'
>>> foo('c')
>>> foo('c') # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ValueError: foo() expected a value in ('a', 'b') for argument 'x', but got 'c' instead. # noqa
ValueError: zipline.utils.input_validation.foo() expected a value in
('a', 'b') for argument 'x', but got 'c' instead.
Notes
-----
Expand Down Expand Up @@ -505,10 +509,11 @@ def expect_dimensions(**dimensions):
...
>>> foo(array([1, 1]), array([[1, 1], [2, 2]]))
2
>>> foo(array([1, 1], array([1, 1])))
>>> foo(array([1, 1]), array([1, 1])) # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
TypeError: foo() expected a 2-D array for argument 'y', but got a 1-D array instead. # noqa
ValueError: zipline.utils.input_validation.foo() expected a 2-D array for
argument 'y', but got a 1-D array instead.
"""
def _expect_dimension(expected_ndim):
def _check(func, argname, argvalue):
Expand Down
Loading

0 comments on commit 5925107

Please sign in to comment.