当前位置: 首页>>代码示例>>Python>>正文


Python nose.tools方法代码示例

本文整理汇总了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) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:test_nose.py

示例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>()*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:24,代码来源:test_nose.py

示例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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:decorators.py

示例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 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:34,代码来源:decorators.py

示例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)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:14,代码来源:decorators.py

示例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') 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:14,代码来源:test_bsc.py

示例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') 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:34,代码来源:test_dtype.py

示例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]') 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:14,代码来源:test_dtype.py

示例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)) 
开发者ID:JonJala,项目名称:mtag,代码行数:14,代码来源:test_jackknife.py

示例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) 
开发者ID:JonJala,项目名称:mtag,代码行数:12,代码来源:test_jackknife.py

示例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') 
开发者ID:JonJala,项目名称:mtag,代码行数:5,代码来源:test_regressions.py

示例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)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:30,代码来源:test_axes.py

示例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) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:32,代码来源:test_ticker.py

示例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()) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:7,代码来源:test_ticker.py

示例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)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:10,代码来源:test_ticker.py


注:本文中的nose.tools方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。