mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-18 12:20:12 +08:00
TST: Adds wildcard object for assert_equal
This commit is contained in:
+27
-1
@@ -12,6 +12,7 @@ import operator
|
||||
import os
|
||||
from os.path import abspath, dirname, join, realpath
|
||||
import shutil
|
||||
from sys import _getframe
|
||||
import tempfile
|
||||
|
||||
from logbook import TestHandler
|
||||
@@ -23,7 +24,7 @@ from six import itervalues, iteritems, with_metaclass
|
||||
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
|
||||
@@ -860,6 +861,7 @@ class SubTestFailures(AssertionError):
|
||||
)
|
||||
|
||||
|
||||
@nottest
|
||||
def subtest(iterator, *_names):
|
||||
"""
|
||||
Construct a subtest in a unittest.
|
||||
@@ -1374,3 +1376,27 @@ def patch_read_csv(url_map, module=pd, strict=False):
|
||||
|
||||
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
|
||||
|
||||
@@ -39,12 +39,47 @@ from six import iteritems, viewkeys, PY2
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user