本文整理匯總了Python中nose.tools方法的典型用法代碼示例。如果您正苦於以下問題:Python nose.tools方法的具體用法?Python nose.tools怎麽用?Python nose.tools使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nose
的用法示例。
在下文中一共展示了nose.tools方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_nose_setup
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_nose_setup(testdir):
p = testdir.makepyfile(
"""
values = []
from nose.tools import with_setup
@with_setup(lambda: values.append(1), lambda: values.append(2))
def test_hello():
assert values == [1]
def test_world():
assert values == [1,2]
test_hello.setup = lambda: values.append(1)
test_hello.teardown = lambda: values.append(2)
"""
)
result = testdir.runpytest(p, "-p", "nose")
result.assert_outcomes(passed=2)
示例2: test_nose_setup_func_failure
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_nose_setup_func_failure(testdir):
p = testdir.makepyfile(
"""
from nose.tools import with_setup
values = []
my_setup = lambda x: 1
my_teardown = lambda x: 2
@with_setup(my_setup, my_teardown)
def test_hello():
print(values)
assert values == [1]
def test_world():
print(values)
assert values == [1,2]
"""
)
result = testdir.runpytest(p, "-p", "nose")
result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"])
示例3: setastest
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def setastest(tf=True):
"""
Signals to nose that this function is or is not a test.
Parameters
----------
tf : bool
If True, specifies that the decorated callable is a test.
If False, specifies that the decorated callable is not a test.
Default is True.
Notes
-----
This decorator can't use the nose namespace, because it can be
called from a non-test module. See also ``istest`` and ``nottest`` in
``nose.tools``.
Examples
--------
`setastest` can be used in the following way::
from numpy.testing import dec
@dec.setastest(False)
def func_with_test_in_name(arg1, arg2):
pass
"""
def set_test(t):
t.__test__ = tf
return t
return set_test
示例4: setastest
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def setastest(tf=True):
"""
Signals to nose that this function is or is not a test.
Parameters
----------
tf : bool
If True, specifies that the decorated callable is a test.
If False, specifies that the decorated callable is not a test.
Default is True.
Notes
-----
This decorator can't use the nose namespace, because it can be
called from a non-test module. See also ``istest`` and ``nottest`` in
``nose.tools``.
Examples
--------
`setastest` can be used in the following way::
from numpy.testing.decorators import setastest
@setastest(False)
def func_with_test_in_name(arg1, arg2):
pass
"""
def set_test(t):
t.__test__ = tf
return t
return set_test
示例5: apply_wrapper
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def apply_wrapper(wrapper,func):
"""Apply a wrapper to a function for decoration.
This mixes Michele Simionato's decorator tool with nose's make_decorator,
to apply a wrapper in a decorator so that all nose attributes, as well as
function signature and other properties, survive the decoration cleanly.
This will ensure that wrapped functions can still be well introspected via
IPython, for example.
"""
import nose.tools
return decorator(wrapper,nose.tools.make_decorator(func)(wrapper))
示例6: test_time_rotation_index_decoding
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_time_rotation_index_decoding(self, socket_mock):
handler = {'name':'name', 'log_dir':'/tmp', 'rotate_log':True}
sl = bsc.SocketStreamCapturer(handler, ['', 9000], 'udp')
# We expect an error when we input a bad time index value
nose.tools.assert_raises(
ValueError,
sl._decode_time_rotation_index,
'this is not a valid value'
)
assert 2 == sl._decode_time_rotation_index('tm_mday')
示例7: testArrayType
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def testArrayType():
array = dtype.ArrayType('MSB_U16', 3)
bin123 = b'\x00\x01\x00\x02\x00\x03'
bin456 = b'\x00\x04\x00\x05\x00\x06'
assert array.name == 'MSB_U16[3]'
assert array.nbits == 3 * 16
assert array.nbytes == 3 * 2
assert array.nelems == 3
assert array.type == dtype.PrimitiveType('MSB_U16')
assert array.encode(1, 2, 3) == bin123
assert array.decode(bin456) == [4, 5, 6]
assert array.decode(bin456, 0) == 4
assert array.decode(bin456, 1) == 5
assert array.decode(bin456, 2) == 6
assert array.decode(bin456, slice(1, 3)) == [5, 6]
with nose.tools.assert_raises(ValueError):
array.encode(1, 2)
with nose.tools.assert_raises(IndexError):
array.decode(bin456[1:5])
with nose.tools.assert_raises(IndexError):
array.decode(bin456, 3)
with nose.tools.assert_raises(TypeError):
array.decode(bin456, 'foo')
with nose.tools.assert_raises(TypeError):
dtype.ArrayType('U8', '4')
示例8: testget
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def testget():
assert isinstance( dtype.get("U8") , dtype.PrimitiveType )
assert isinstance( dtype.get("S40") , dtype.PrimitiveType )
assert isinstance( dtype.get("TIME32"), dtype.Time32Type )
assert dtype.get('LSB_U32[10]') == dtype.ArrayType('LSB_U32', 10)
with nose.tools.assert_raises(ValueError):
dtype.get('U8["foo"]')
with nose.tools.assert_raises(ValueError):
dtype.get('U8[-42]')
示例9: test_jknife_1d
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_jknife_1d(self):
pseudovalues = np.atleast_2d(np.arange(10)).T
(est, var, se, cov) = jk.Jackknife.jknife(pseudovalues)
nose.tools.assert_almost_equal(var, 0.91666667)
nose.tools.assert_almost_equal(est, 4.5)
nose.tools.assert_almost_equal(cov, var)
nose.tools.assert_almost_equal(se ** 2, var)
self.assertTrue(not np.any(np.isnan(cov)))
assert_array_equal(cov.shape, (1, 1))
assert_array_equal(var.shape, (1, 1))
assert_array_equal(est.shape, (1, 1))
assert_array_equal(se.shape, (1, 1))
示例10: test_delete_to_pseudo
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_delete_to_pseudo(self):
for dim in [1, 2]:
est = np.ones((1, dim))
delete_values = np.ones((20, dim))
x = jk.Jackknife.delete_values_to_pseudovalues(delete_values, est)
assert_array_equal(x, np.ones_like(delete_values))
est = est.T
nose.tools.assert_raises(
ValueError, jk.Jackknife.delete_values_to_pseudovalues, delete_values, est)
示例11: test_remove_brackets
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_remove_brackets():
x = ' [] [] asdf [] '
nose.tools.assert_equal(reg.remove_brackets(x), 'asdf')
示例12: test_polar_units
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_polar_units():
import matplotlib.testing.jpl_units as units
from nose.tools import assert_true
units.register()
pi = np.pi
deg = units.UnitDbl(1.0, "deg")
km = units.UnitDbl(1.0, "km")
x1 = [pi/6.0, pi/4.0, pi/3.0, pi/2.0]
x2 = [30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg]
y1 = [1.0, 2.0, 3.0, 4.0]
y2 = [4.0, 3.0, 2.0, 1.0]
fig = plt.figure()
plt.polar(x2, y1, color="blue")
# polar(x2, y1, color = "red", xunits="rad")
# polar(x2, y2, color = "green")
fig = plt.figure()
# make sure runits and theta units work
y1 = [y*km for y in y1]
plt.polar(x2, y1, color="blue", thetaunits="rad", runits="km")
assert_true(isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter))
示例13: test_LogFormatterExponent
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_LogFormatterExponent():
class FakeAxis(object):
"""Allow Formatter to be called without having a "full" plot set up."""
def get_view_interval(self):
return 1, 10
i = np.arange(-3, 4, dtype=float)
expected_result = ['-3', '-2', '-1', '0', '1', '2', '3']
for base in [2, 5, 10, np.pi, np.e]:
formatter = mticker.LogFormatterExponent(base=base)
formatter.axis = FakeAxis()
vals = base**i
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
nose.tools.assert_equal(labels, expected_result)
# Should be a blank string for non-integer powers if labelOnlyBase=True
formatter = mticker.LogFormatterExponent(base=10, labelOnlyBase=True)
formatter.axis = FakeAxis()
nose.tools.assert_equal(formatter(10**0.1), '')
# Otherwise, non-integer powers should be nicely formatted
locs = np.array([0.1, 0.00001, np.pi, 0.2, -0.2, -0.00001])
i = range(len(locs))
expected_result = ['0.1', '1e-05', '3.14', '0.2', '-0.2', '-1e-05']
for base in [2, 5, 10, np.pi, np.e]:
formatter = mticker.LogFormatterExponent(base, labelOnlyBase=False)
formatter.axis = FakeAxis()
vals = base**locs
labels = [formatter(x, pos) for (x, pos) in zip(vals, i)]
nose.tools.assert_equal(labels, expected_result)
示例14: test_use_offset
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_use_offset():
for use_offset in [True, False]:
with matplotlib.rc_context({'axes.formatter.useoffset': use_offset}):
tmp_form = mticker.ScalarFormatter()
nose.tools.assert_equal(use_offset, tmp_form.get_useOffset())
示例15: test_formatstrformatter
# 需要導入模塊: import nose [as 別名]
# 或者: from nose import tools [as 別名]
def test_formatstrformatter():
# test % style formatter
tmp_form = mticker.FormatStrFormatter('%05d')
nose.tools.assert_equal('00002', tmp_form(2))
# test str.format() style formatter
tmp_form = mticker.StrMethodFormatter('{x:05d}')
nose.tools.assert_equal('00002', tmp_form(2))