我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用nose.tools.assert_not_equal()。
def test_prefilter_shadowed(): def dummy_magic(line): pass prev_automagic_state = ip.automagic ip.automagic = True ip.autocall = 0 try: # These should not be transformed - they are shadowed by other names for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global ip.register_magic_function(dummy_magic, magic_name=name) res = ip.prefilter(name+' foo') nt.assert_equal(res, name+' foo') del ip.magics_manager.magics['line'][name] # These should be transformed for name in ['fi', 'piz', 'nohtypi_teg']: ip.register_magic_function(dummy_magic, magic_name=name) res = ip.prefilter(name+' foo') nt.assert_not_equal(res, name+' foo') del ip.magics_manager.magics['line'][name] finally: ip.automagic = prev_automagic_state
def assert_not_equal(self, *args, **kwds): assert_not_equal(*args, **kwds)
def test_find_file_magic(): run = ip.find_line_magic('run') nt.assert_not_equal(oinspect.find_file(run), None) # A few generic objects we can then inspect in the tests below
def test_info(): "Check that Inspector.info fills out various fields as expected." i = inspector.info(Call, oname='Call') nt.assert_equal(i['type_name'], 'type') expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> nt.assert_equal(i['base_class'], expted_class) nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>") fname = __file__ if fname.endswith(".pyc"): fname = fname[:-1] # case-insensitive comparison needed on some filesystems # e.g. Windows: nt.assert_equal(i['file'].lower(), compress_user(fname).lower()) nt.assert_equal(i['definition'], None) nt.assert_equal(i['docstring'], Call.__doc__) nt.assert_equal(i['source'], None) nt.assert_true(i['isclass']) nt.assert_equal(i['init_definition'], "Call(x, y=1)") nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) i = inspector.info(Call, detail_level=1) nt.assert_not_equal(i['source'], None) nt.assert_equal(i['docstring'], None) c = Call(1) c.__doc__ = "Modified instance docstring" i = inspector.info(c) nt.assert_equal(i['type_name'], 'Call') nt.assert_equal(i['docstring'], "Modified instance docstring") nt.assert_equal(i['class_docstring'], Call.__doc__) nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) nt.assert_equal(i['call_docstring'], Call.__call__.__doc__)
def assert_inode_not_equal(self, a, b): nt.assert_not_equal(os.stat(a).st_ino, os.stat(b).st_ino, "%r and %r do reference the same indoes" %(a, b))
def test_osx(): nt.assert_not_equal(sys.platform,'darwin',"This test can't run under osx")
def test_win32(): nt.assert_not_equal(sys.platform,'win32',"This test can't run under windows")
def add_directlun(prefix): # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh(['cat', '/root/multipath.txt']) nt.assert_equals(ret.code, 0) all_guids = ret.out.splitlines() lun_guid = all_guids[SD_ISCSI_NR_LUNS] #Take the first unused LUN. 0-(SD_ISCSI_NR_LUNS) are used by iSCSI SD dlun_params = params.Disk( name=DLUN_DISK_NAME, interface='virtio_scsi', format='raw', lun_storage=params.Storage( type_='iscsi', logical_unit=[ params.LogicalUnit( id=lun_guid, address=prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ip(), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='username', password='password', ) ] ), sgio='unfiltered', ) api = prefix.virt_env.engine_vm().get_api() api.vms.get(VM0_NAME).disks.add(dlun_params) nt.assert_not_equal( api.vms.get(VM0_NAME).disks.get(DLUN_DISK_NAME), None, 'Direct LUN disk not attached' )
def add_directlun(prefix): # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh( ['multipath', '-ll', '-v1', '|sort'] ) nt.assert_equals(ret.code, 0) all_guids = ret.out.splitlines() # Take the first unused LUN. 0-(SD_ISCSI_NR_LUNS) are used by iSCSI SD lun_guid = all_guids[SD_ISCSI_NR_LUNS] dlun_params = params.Disk( name=DLUN_DISK_NAME, interface='virtio_scsi', format='raw', lun_storage=params.Storage( type_='iscsi', logical_unit=[ params.LogicalUnit( id=lun_guid, address=prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ip(), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, ) ] ), ) api = prefix.virt_env.engine_vm().get_api() api.vms.get(VM0_NAME).disks.add(dlun_params) nt.assert_not_equal( api.vms.get(VM0_NAME).disks.get(DLUN_DISK_NAME), None, 'Direct LUN disk not attached' )
def add_directlun(prefix): # Find LUN GUIDs ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh(['cat', '/root/multipath.txt']) nt.assert_equals(ret.code, 0) all_guids = ret.out.splitlines() # Take the first unused LUN. 0-(SD_ISCSI_NR_LUNS) are used by iSCSI SD lun_guid = all_guids[SD_ISCSI_NR_LUNS] dlun_params = params.Disk( name=DLUN_DISK_NAME, interface='virtio_scsi', format='raw', lun_storage=params.Storage( type_='iscsi', logical_unit=[ params.LogicalUnit( id=lun_guid, address=prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ip(), port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='username', password='password', ) ] ), ) api = prefix.virt_env.engine_vm().get_api() api.vms.get(VM0_NAME).disks.add(dlun_params) nt.assert_not_equal( api.vms.get(VM0_NAME).disks.get(DLUN_DISK_NAME), None, 'Direct LUN disk not attached' )
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, }, })
def test_info(): "Check that Inspector.info fills out various fields as expected." i = inspector.info(Call, oname='Call') nt.assert_equal(i['type_name'], 'type') expted_class = str(type(type)) # <class 'type'> (Python 3) or <type 'type'> nt.assert_equal(i['base_class'], expted_class) if sys.version_info > (3,): nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>") fname = __file__ if fname.endswith(".pyc"): fname = fname[:-1] # case-insensitive comparison needed on some filesystems # e.g. Windows: nt.assert_equal(i['file'].lower(), compress_user(fname).lower()) nt.assert_equal(i['definition'], None) nt.assert_equal(i['docstring'], Call.__doc__) nt.assert_equal(i['source'], None) nt.assert_true(i['isclass']) _self_py2 = '' if py3compat.PY3 else 'self, ' nt.assert_equal(i['init_definition'], "Call(%sx, y=1)" % _self_py2) nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) i = inspector.info(Call, detail_level=1) nt.assert_not_equal(i['source'], None) nt.assert_equal(i['docstring'], None) c = Call(1) c.__doc__ = "Modified instance docstring" i = inspector.info(c) nt.assert_equal(i['type_name'], 'Call') nt.assert_equal(i['docstring'], "Modified instance docstring") nt.assert_equal(i['class_docstring'], Call.__doc__) nt.assert_equal(i['init_docstring'], Call.__init__.__doc__) nt.assert_equal(i['call_docstring'], Call.__call__.__doc__) # Test old-style classes, which for example may not have an __init__ method. if not py3compat.PY3: i = inspector.info(OldStyle) nt.assert_equal(i['type_name'], 'classobj') i = inspector.info(OldStyle()) nt.assert_equal(i['type_name'], 'instance') nt.assert_equal(i['docstring'], OldStyle.__doc__)
def add_directlun(prefix): # Find LUN GUIDs iscsi_host = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME) ret = iscsi_host.ssh(['cat', '/root/multipath.txt']) nt.assert_equals(ret.code, 0) all_guids = ret.out.splitlines() lun_guid = all_guids[SD_ISCSI_NR_LUNS] # Take the first unused LUN. 0-(SD_ISCSI_NR_LUNS) are used by iSCSI SD ips = iscsi_host.all_ips() luns = [] for ip in ips: lun=types.LogicalUnit( id=lun_guid, address=ip, port=SD_ISCSI_PORT, target=SD_ISCSI_TARGET, username='username', password='password', ) luns.append(lun) dlun_params = types.Disk( name=DLUN_DISK_NAME, format=types.DiskFormat.RAW, lun_storage=types.HostStorage( type=types.StorageType.ISCSI, logical_units=luns, ), sgio=types.ScsiGenericIO.UNFILTERED, ) api = prefix.virt_env.engine_vm().get_api_v4() engine = api.system_service() disk_attachments_service = test_utils.get_disk_attachments_service(engine, VM0_NAME) disk_attachments_service.add(types.DiskAttachment( disk=dlun_params, interface=types.DiskInterface.VIRTIO_SCSI)) disk_service = test_utils.get_disk_service(engine, DLUN_DISK_NAME) attachment_service = disk_attachments_service.attachment_service(disk_service.get().id) nt.assert_not_equal( attachment_service.get(), None, 'Direct LUN disk not attached' )