Skip to content

Commit

Permalink
TST: Adds wildcard object for assert_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Jevnik committed Jun 20, 2016
1 parent 46d8a02 commit c0d08f9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
28 changes: 27 additions & 1 deletion zipline/testing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
from os.path import abspath, dirname, join, realpath
import shutil
from sys import _getframe
import tempfile

from logbook import TestHandler
Expand All @@ -23,7 +24,7 @@
from six.moves import filter, map
from sqlalchemy import create_engine
from testfixtures import TempDirectory
from toolz import concat
from toolz import concat, curry

from zipline.assets import AssetFinder, AssetDBWriter
from zipline.assets.synthetic import make_simple_equity_info
Expand Down Expand Up @@ -860,6 +861,7 @@ def __str__(self):
)


@nottest
def subtest(iterator, *_names):
"""
Construct a subtest in a unittest.
Expand Down Expand Up @@ -1374,3 +1376,27 @@ def patched_read_csv(filepath_or_buffer, *args, **kwargs):

with patch.object(module, 'read_csv', patched_read_csv):
yield


@curry
def ensure_doctest(f, name=None):
"""Ensure that an object gets doctested. This is useful for instances
of objects like curry or partial which are not discovered by default.
Parameters
----------
f : any
The thing to doctest.
name : str, optional
The name to use in the doctest function mapping. If this is None,
Then ``f.__name__`` will be used.
Returns
-------
f : any
``f`` unchanged.
"""
_getframe(2).f_globals.setdefault('__test__', {})[
f.__name__ if name is None else name
] = f
return f
37 changes: 36 additions & 1 deletion zipline/testing/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,47 @@
from toolz import dissoc, keyfilter
import toolz.curried.operator as op

from zipline.testing.core import ensure_doctest
from zipline.dispatch import dispatch
from zipline.lib.adjustment import Adjustment
from zipline.utils.functional import dzip_exact
from zipline.utils.functional import dzip_exact, instance
from zipline.utils.math_utils import tolerant_equals


@instance
@ensure_doctest
class wildcard(object):
"""An object that compares equal to any other object.
This is useful when using :func:`~zipline.testing.predicates.assert_equal`
with a large recursive structure and some fields to be ignored.
Examples
--------
>>> wildcard == 5
True
>>> wildcard == 'ayy'
True
# reflected
>>> 5 == wildcard
True
>>> 'ayy' == wildcard
True
"""
@staticmethod
def __eq__(other):
return True

@staticmethod
def __ne__(other):
return False

def __repr__(self):
return '<%s>' % type(self).__name__
__str__ = __repr__


def keywords(func):
"""Get the argument names of a function
Expand Down

0 comments on commit c0d08f9

Please sign in to comment.