Python nose.tools 模块,assert_is_instance() 实例源码

我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用nose.tools.assert_is_instance()

项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def assert_dict_equal(d1, d2):
    # check keys
    nt.assert_is_instance(d1, dict)
    nt.assert_is_instance(d2, dict)
    nt.assert_set_equal(set(d1.keys()), set(d2.keys()))
    for k in d1:
        v1 = d1[k]
        v2 = d2[k]

        asserter = nt.assert_equal
        if isinstance(v1, pd.DataFrame):
            asserter = tm.assert_frame_equal
        if isinstance(v1, pd.Series):
            asserter = tm.assert_series_equal

        try:
            asserter(v1, v2)
        except AssertionError:
            raise AssertionError('{k} is not equal'.format(k=k))
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_class_inheritance():
    @interactive
    class C(object):
        a=5

    @interactive
    class D(C):
        b=10

    bufs = serialize_object(dict(D=D))
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned['D'], CannedClass)
    d, r = deserialize_object(bufs)
    D2 = d['D']
    nt.assert_equal(D2.a, D.a)
    nt.assert_equal(D2.b, D.b)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def test_display_handle():
    ip = get_ipython()
    handle = display.DisplayHandle()
    nt.assert_is_instance(handle.display_id, str)
    handle = display.DisplayHandle('my-id')
    nt.assert_equal(handle.display_id, 'my-id')
    with mock.patch.object(ip.display_pub, 'publish') as pub:
        handle.display('x')
        handle.update('y')

    args, kwargs = pub.call_args_list[0]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('x')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        }
    })
    args, kwargs = pub.call_args_list[1]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('y')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        },
        'update': True,
    })
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def test_bad_module_all():
    """Test module with invalid __all__

    https://github.com/ipython/ipython/issues/9678
    """
    testsdir = os.path.dirname(__file__)
    sys.path.insert(0, testsdir)
    try:
        results = module_completion('from bad_all import ')
        nt.assert_in('puppies', results)
        for r in results:
            nt.assert_is_instance(r, str)
    finally:
        sys.path.remove(testsdir)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def test_clipboard_get():
    # Smoketest for clipboard access - we can't easily guarantee that the
    # clipboard is accessible and has something on it, but this tries to
    # exercise the relevant code anyway.
    try:
        a = get_ipython().hooks.clipboard_get()
    except ClipboardEmpty:
        # Nothing in clipboard to get
        pass
    except TryNext:
        # No clipboard access API available
        pass
    else:
        nt.assert_is_instance(a, str)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def test_LSString():
    lss = text.LSString("abc\ndef")
    nt.assert_equal(lss.l, ['abc', 'def'])
    nt.assert_equal(lss.s, 'abc def')
    lss = text.LSString(os.getcwd())
    nt.assert_is_instance(lss.p[0], Path)
项目:deep-action-proposals    作者:escorciav    | 项目源码 | 文件源码
def test_Dataset():
    for i in ['thumos14', 'activitynet']:
        ds = Dataset(i)
        nt.assert_is_instance(ds.wrapped_dataset, DatasetBase)
        # Assert main methods
        nt.assert_true(hasattr(ds.wrapped_dataset, 'segments_info'))
        nt.assert_true(hasattr(ds.wrapped_dataset, 'video_info'))
项目:tidml    作者:tidchile    | 项目源码 | 文件源码
def test_default_pickle_model_persistor():
    ds = TestAlgorithm({'model.pickle': ''})
    nt.assert_is_instance(ds.persistor, PickleModelPersistor)
项目:tidml    作者:tidchile    | 项目源码 | 文件源码
def test_with_custom_model_persistor():
    ds = TestAlgorithmWithCustomPersistor()
    nt.assert_is_instance(ds.persistor, ModelPersistor)
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_numpy_in_seq():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = new_array(shape, dtype=dtype)
            bufs = serialize_object((A,1,2,b'hello'))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned[0], CannedArray)
            tup, r = deserialize_object(bufs)
            B = tup[0]
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_numpy_in_dict():
    import numpy
    from numpy.testing.utils import assert_array_equal
    for shape in SHAPES:
        for dtype in DTYPES:
            A = new_array(shape, dtype=dtype)
            bufs = serialize_object(dict(a=A,b=1,c=range(20)))
            canned = pickle.loads(bufs[0])
            nt.assert_is_instance(canned['a'], CannedArray)
            d, r = deserialize_object(bufs)
            B = d['a']
            nt.assert_equal(r, [])
            nt.assert_equal(A.shape, B.shape)
            nt.assert_equal(A.dtype, B.dtype)
            assert_array_equal(A,B)
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_class():
    @interactive
    class C(object):
        a=5
    bufs = serialize_object(dict(C=C))
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned['C'], CannedClass)
    d, r = deserialize_object(bufs)
    C2 = d['C']
    nt.assert_equal(C2.a, C.a)
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_class_oldstyle():
    @interactive
    class C:
        a=5

    bufs = serialize_object(dict(C=C))
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned['C'], CannedClass)
    d, r = deserialize_object(bufs)
    C2 = d['C']
    nt.assert_equal(C2.a, C.a)
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_tuple():
    tup = (lambda x:x, 1)
    bufs = serialize_object(tup)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, tuple)
    t2, r = deserialize_object(bufs)
    nt.assert_equal(t2[0](t2[1]), tup[0](tup[1]))
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def test_list():
    lis = [lambda x:x, 1]
    bufs = serialize_object(lis)
    canned = pickle.loads(bufs[0])
    nt.assert_is_instance(canned, list)
    l2, r = deserialize_object(bufs)
    nt.assert_equal(l2[0](l2[1]), lis[0](lis[1]))
项目:dfkernel    作者:dataflownb    | 项目源码 | 文件源码
def _data_changed(self, name, old, new):
        for k,v in iteritems(new):
            assert mime_pat.match(k)
            nt.assert_is_instance(v, string_types)


# shell replies
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def test_bad_module_all():
    """Test module with invalid __all__

    https://github.com/ipython/ipython/issues/9678
    """
    testsdir = os.path.dirname(__file__)
    sys.path.insert(0, testsdir)
    try:
        results = module_completion('from bad_all import ')
        nt.assert_in('puppies', results)
        for r in results:
            nt.assert_is_instance(r, py3compat.string_types)
    finally:
        sys.path.remove(testsdir)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def test_clipboard_get():
    # Smoketest for clipboard access - we can't easily guarantee that the
    # clipboard is accessible and has something on it, but this tries to
    # exercise the relevant code anyway.
    try:
        a = get_ipython().hooks.clipboard_get()
    except ClipboardEmpty:
        # Nothing in clipboard to get
        pass
    except TryNext:
        # No clipboard access API available
        pass
    else:
        nt.assert_is_instance(a, unicode_type)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def test_LSString():
    lss = text.LSString("abc\ndef")
    nt.assert_equal(lss.l, ['abc', 'def'])
    nt.assert_equal(lss.s, 'abc def')
    lss = text.LSString(os.getcwd())
    nt.assert_is_instance(lss.p[0], Path)
项目:automata    作者:caleb531    | 项目源码 | 文件源码
def test_validate_input_step(self):
        """Should return validation generator if step flag is supplied."""
        validation_generator = self.dtm1.validate_input('00001111', step=True)
        nose.assert_is_instance(validation_generator, types.GeneratorType)
        configs = []
        for current_state, tape in validation_generator:
            configs.append((current_state, tape.copy()))
        nose.assert_equal(configs[0][0], 'q0')
        nose.assert_equal(str(configs[0][1]), 'TMTape(\'00001111\')')
        nose.assert_equal(configs[-1][0], 'q4')
        nose.assert_equal(str(configs[-1][1]), 'TMTape(\'xxxxyyyy.\')')
项目:automata    作者:caleb531    | 项目源码 | 文件源码
def test_validate_input_step(self):
        """Should return validation generator if step flag is supplied."""
        validation_generator = self.nfa.validate_input('aba', step=True)
        nose.assert_is_instance(validation_generator, types.GeneratorType)
        nose.assert_equal(list(validation_generator), [
            {'q0'}, {'q1', 'q2'}, {'q0'}, {'q1', 'q2'}
        ])
项目:automata    作者:caleb531    | 项目源码 | 文件源码
def test_validate_input_step(self):
        """Should return validation generator if step flag is supplied."""
        validation_generator = self.dfa.validate_input('0111', step=True)
        nose.assert_is_instance(validation_generator, types.GeneratorType)
        nose.assert_equal(list(validation_generator), [
            'q0', 'q0', 'q1', 'q2', 'q1'
        ])
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def test_bad_module_all():
    """Test module with invalid __all__

    https://github.com/ipython/ipython/issues/9678
    """
    testsdir = os.path.dirname(__file__)
    sys.path.insert(0, testsdir)
    try:
        results = module_completion('from bad_all import ')
        nt.assert_in('puppies', results)
        for r in results:
            nt.assert_is_instance(r, py3compat.string_types)
    finally:
        sys.path.remove(testsdir)
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def test_clipboard_get():
    # Smoketest for clipboard access - we can't easily guarantee that the
    # clipboard is accessible and has something on it, but this tries to
    # exercise the relevant code anyway.
    try:
        a = get_ipython().hooks.clipboard_get()
    except ClipboardEmpty:
        # Nothing in clipboard to get
        pass
    except TryNext:
        # No clipboard access API available
        pass
    else:
        nt.assert_is_instance(a, unicode_type)
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def test_LSString():
    lss = text.LSString("abc\ndef")
    nt.assert_equal(lss.l, ['abc', 'def'])
    nt.assert_equal(lss.s, 'abc def')
    lss = text.LSString(os.getcwd())
    nt.assert_is_instance(lss.p[0], Path)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def test_display_handle():
    ip = get_ipython()
    handle = display.DisplayHandle()
    nt.assert_is_instance(handle.display_id, str)
    handle = display.DisplayHandle('my-id')
    nt.assert_equal(handle.display_id, 'my-id')
    with mock.patch.object(ip.display_pub, 'publish') as pub:
        handle.display('x')
        handle.update('y')

    args, kwargs = pub.call_args_list[0]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('x')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        }
    })
    args, kwargs = pub.call_args_list[1]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('y')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        },
        'update': True,
    })
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def test_bad_module_all():
    """Test module with invalid __all__

    https://github.com/ipython/ipython/issues/9678
    """
    testsdir = os.path.dirname(__file__)
    sys.path.insert(0, testsdir)
    try:
        results = module_completion('from bad_all import ')
        nt.assert_in('puppies', results)
        for r in results:
            nt.assert_is_instance(r, str)
    finally:
        sys.path.remove(testsdir)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def test_clipboard_get():
    # Smoketest for clipboard access - we can't easily guarantee that the
    # clipboard is accessible and has something on it, but this tries to
    # exercise the relevant code anyway.
    try:
        a = get_ipython().hooks.clipboard_get()
    except ClipboardEmpty:
        # Nothing in clipboard to get
        pass
    except TryNext:
        # No clipboard access API available
        pass
    else:
        nt.assert_is_instance(a, str)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def test_LSString():
    lss = text.LSString("abc\ndef")
    nt.assert_equal(lss.l, ['abc', 'def'])
    nt.assert_equal(lss.s, 'abc def')
    lss = text.LSString(os.getcwd())
    nt.assert_is_instance(lss.p[0], Path)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def test_display_id():
    ip = get_ipython()
    with mock.patch.object(ip.display_pub, 'publish') as pub:
        handle = display.display('x')
        nt.assert_is(handle, None)
        handle = display.display('y', display_id='secret')
        nt.assert_is_instance(handle, display.DisplayHandle)
        handle2 = display.display('z', display_id=True)
        nt.assert_is_instance(handle2, display.DisplayHandle)
    nt.assert_not_equal(handle.display_id, handle2.display_id)

    nt.assert_equal(pub.call_count, 3)
    args, kwargs = pub.call_args_list[0]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('x')
        },
        'metadata': {},
    })
    args, kwargs = pub.call_args_list[1]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('y')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        },
    })
    args, kwargs = pub.call_args_list[2]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('z')
        },
        'metadata': {},
        'transient': {
            'display_id': handle2.display_id,
        },
    })
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def test_dictproxy():
    # This is the dictproxy constructor itself from the Python API,
    DP = ctypes.pythonapi.PyDictProxy_New
    DP.argtypes, DP.restype = (ctypes.py_object,), ctypes.py_object

    underlying_dict = {}
    mp_recursive = DP(underlying_dict)
    underlying_dict[0] = mp_recursive
    underlying_dict[-3] = underlying_dict

    cases = [
        (DP({}), "dict_proxy({})"),
        (DP({None: DP({})}), "dict_proxy({None: dict_proxy({})})"),
        (DP({k: k.lower() for k in string.ascii_uppercase}),
         "dict_proxy({'A': 'a',\n"
         "            'B': 'b',\n"
         "            'C': 'c',\n"
         "            'D': 'd',\n"
         "            'E': 'e',\n"
         "            'F': 'f',\n"
         "            'G': 'g',\n"
         "            'H': 'h',\n"
         "            'I': 'i',\n"
         "            'J': 'j',\n"
         "            'K': 'k',\n"
         "            'L': 'l',\n"
         "            'M': 'm',\n"
         "            'N': 'n',\n"
         "            'O': 'o',\n"
         "            'P': 'p',\n"
         "            'Q': 'q',\n"
         "            'R': 'r',\n"
         "            'S': 's',\n"
         "            'T': 't',\n"
         "            'U': 'u',\n"
         "            'V': 'v',\n"
         "            'W': 'w',\n"
         "            'X': 'x',\n"
         "            'Y': 'y',\n"
         "            'Z': 'z'})"),
        (mp_recursive, "dict_proxy({-3: {-3: {...}, 0: {...}}, 0: {...}})"),
    ]
    for obj, expected in cases:
        nt.assert_is_instance(obj, types.DictProxyType) # Meta-test
        nt.assert_equal(pretty.pretty(obj), expected)
    nt.assert_equal(pretty.pretty(underlying_dict),
                    "{-3: {...}, 0: dict_proxy({-3: {...}, 0: {...}})}")
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
def test_dictproxy():
    # This is the dictproxy constructor itself from the Python API,
    DP = ctypes.pythonapi.PyDictProxy_New
    DP.argtypes, DP.restype = (ctypes.py_object,), ctypes.py_object

    underlying_dict = {}
    mp_recursive = DP(underlying_dict)
    underlying_dict[0] = mp_recursive
    underlying_dict[-3] = underlying_dict

    cases = [
        (DP({}), "dict_proxy({})"),
        (DP({None: DP({})}), "dict_proxy({None: dict_proxy({})})"),
        (DP({k: k.lower() for k in string.ascii_uppercase}),
         "dict_proxy({'A': 'a',\n"
         "            'B': 'b',\n"
         "            'C': 'c',\n"
         "            'D': 'd',\n"
         "            'E': 'e',\n"
         "            'F': 'f',\n"
         "            'G': 'g',\n"
         "            'H': 'h',\n"
         "            'I': 'i',\n"
         "            'J': 'j',\n"
         "            'K': 'k',\n"
         "            'L': 'l',\n"
         "            'M': 'm',\n"
         "            'N': 'n',\n"
         "            'O': 'o',\n"
         "            'P': 'p',\n"
         "            'Q': 'q',\n"
         "            'R': 'r',\n"
         "            'S': 's',\n"
         "            'T': 't',\n"
         "            'U': 'u',\n"
         "            'V': 'v',\n"
         "            'W': 'w',\n"
         "            'X': 'x',\n"
         "            'Y': 'y',\n"
         "            'Z': 'z'})"),
        (mp_recursive, "dict_proxy({-3: {-3: {...}, 0: {...}}, 0: {...}})"),
    ]
    for obj, expected in cases:
        nt.assert_is_instance(obj, types.DictProxyType) # Meta-test
        nt.assert_equal(pretty.pretty(obj), expected)
    nt.assert_equal(pretty.pretty(underlying_dict),
                    "{-3: {...}, 0: dict_proxy({-3: {...}, 0: {...}})}")
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def test_display_id():
    ip = get_ipython()
    with mock.patch.object(ip.display_pub, 'publish') as pub:
        handle = display.display('x')
        nt.assert_is(handle, None)
        handle = display.display('y', display_id='secret')
        nt.assert_is_instance(handle, display.DisplayHandle)
        handle2 = display.display('z', display_id=True)
        nt.assert_is_instance(handle2, display.DisplayHandle)
    nt.assert_not_equal(handle.display_id, handle2.display_id)

    nt.assert_equal(pub.call_count, 3)
    args, kwargs = pub.call_args_list[0]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('x')
        },
        'metadata': {},
    })
    args, kwargs = pub.call_args_list[1]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('y')
        },
        'metadata': {},
        'transient': {
            'display_id': handle.display_id,
        },
    })
    args, kwargs = pub.call_args_list[2]
    nt.assert_equal(args, ())
    nt.assert_equal(kwargs, {
        'data': {
            'text/plain': repr('z')
        },
        'metadata': {},
        'transient': {
            'display_id': handle2.display_id,
        },
    })