def test_paste_py_multi_r(self):
"Now, test that self.paste -r works"
self.test_paste_py_multi()
nt.assert_equal(ip.user_ns.pop('x'), [1,2,3])
nt.assert_equal(ip.user_ns.pop('y'), [1,4,9])
nt.assert_false('x' in ip.user_ns)
ip.magic('paste -r')
nt.assert_equal(ip.user_ns['x'], [1,2,3])
nt.assert_equal(ip.user_ns['y'], [1,4,9])
python类assert_false()的实例源码
def test_reset_in():
"Test '%reset in' magic"
# test '%reset -f in'
_ip.run_cell("parrot", store_history=True)
nt.assert_true('parrot' in [_ip.user_ns[x] for x in ('_i','_ii','_iii')])
_ip.magic('%reset -f in')
nt.assert_false('parrot' in [_ip.user_ns[x] for x in ('_i','_ii','_iii')])
nt.assert_equal(len(set(_ip.user_ns['In'])), 1)
def test_last_blank():
nt.assert_false(isp.last_blank(''))
nt.assert_false(isp.last_blank('abc'))
nt.assert_false(isp.last_blank('abc\n'))
nt.assert_false(isp.last_blank('abc\na'))
nt.assert_true(isp.last_blank('\n'))
nt.assert_true(isp.last_blank('\n '))
nt.assert_true(isp.last_blank('abc\n '))
nt.assert_true(isp.last_blank('abc\n\n'))
nt.assert_true(isp.last_blank('abc\nd\n\n'))
nt.assert_true(isp.last_blank('abc\nd\ne\n\n'))
nt.assert_true(isp.last_blank('abc \n \n \n\n'))
def test_cellmagic_help(self):
self.sp.push('%%cellm?')
nt.assert_false(self.sp.push_accepts_more())
def test_linux():
nt.assert_false(sys.platform.startswith('linux'),"This test can't run under linux")
def test_shutdown():
"""Kernel exits after polite shutdown_request"""
with new_kernel() as kc:
km = kc.parent
execute(u'a = 1', kc=kc)
wait_for_idle(kc)
kc.shutdown()
for i in range(100): # 10s timeout
if km.is_alive():
time.sleep(.1)
else:
break
nt.assert_false(km.is_alive())
def test_embed_kernel_namespace():
"""IPython.embed_kernel() inherits calling namespace"""
cmd = '\n'.join([
'from IPython import embed_kernel',
'def go():',
' a=5',
' b="hi there"',
' embed_kernel()',
'go()',
'',
])
with setup_kernel(cmd) as client:
# oinfo a (int)
msg_id = client.inspect('a')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_true(content['found'])
text = content['data']['text/plain']
nt.assert_in(u'5', text)
# oinfo b (str)
msg_id = client.inspect('b')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_true(content['found'])
text = content['data']['text/plain']
nt.assert_in(u'hi there', text)
# oinfo c (undefined)
msg_id = client.inspect('c')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_false(content['found'])
def test_oinfo_not_found():
flush_channels()
msg_id = KC.inspect('dne')
reply = KC.get_shell_msg(timeout=TIMEOUT)
validate_message(reply, 'inspect_reply', msg_id)
content = reply['content']
nt.assert_false(content['found'])
def test_has_open_quotes3():
for s in ["''", "''' '''", "'hi' 'ipython'"]:
nt.assert_false(completer.has_open_quotes(s))
def test_has_open_quotes4():
for s in ['""', '""" """', '"hi" "ipython"']:
nt.assert_false(completer.has_open_quotes(s))
def test_paste_py_multi_r(self):
"Now, test that self.paste -r works"
self.test_paste_py_multi()
nt.assert_equal(ip.user_ns.pop('x'), [1,2,3])
nt.assert_equal(ip.user_ns.pop('y'), [1,4,9])
nt.assert_false('x' in ip.user_ns)
ip.magic('paste -r')
nt.assert_equal(ip.user_ns['x'], [1,2,3])
nt.assert_equal(ip.user_ns['y'], [1,4,9])
def test_reset_in():
"Test '%reset in' magic"
# test '%reset -f in'
_ip.run_cell("parrot", store_history=True)
nt.assert_true('parrot' in [_ip.user_ns[x] for x in ('_i','_ii','_iii')])
_ip.magic('%reset -f in')
nt.assert_false('parrot' in [_ip.user_ns[x] for x in ('_i','_ii','_iii')])
nt.assert_equal(len(set(_ip.user_ns['In'])), 1)
def test_last_blank():
nt.assert_false(isp.last_blank(''))
nt.assert_false(isp.last_blank('abc'))
nt.assert_false(isp.last_blank('abc\n'))
nt.assert_false(isp.last_blank('abc\na'))
nt.assert_true(isp.last_blank('\n'))
nt.assert_true(isp.last_blank('\n '))
nt.assert_true(isp.last_blank('abc\n '))
nt.assert_true(isp.last_blank('abc\n\n'))
nt.assert_true(isp.last_blank('abc\nd\n\n'))
nt.assert_true(isp.last_blank('abc\nd\ne\n\n'))
nt.assert_true(isp.last_blank('abc \n \n \n\n'))
def test_cellmagic_help(self):
self.sp.push('%%cellm?')
nt.assert_false(self.sp.push_accepts_more())
def test_linux():
nt.assert_false(sys.platform.startswith('linux'),"This test can't run under linux")
def test_add_parameter():
pName = 'nTopics'
yield assert_false, hasattr(config, pName)
add_parameter(pName, nTopics, jsonFile)
config2 = load_config(jsonFile)
yield assert_equal, config2[pName], nTopics
def detach_vm_network_from_host_0(api):
engine = api.system_service()
host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
host_service = engine.hosts_service().host_service(id=host.id)
network_utils_v4.set_network_required_in_cluster(
engine, VM_NETWORK, CLUSTER_NAME, False)
network_utils_v4.detach_network_from_host(engine, host_service, VM_NETWORK)
nt.assert_false(_host_is_attached_to_network(engine, host_service,
VM_NETWORK))
def _validate_db_empty(token_id, engine_ip):
networks = _get_networks(token_id, engine_ip)['networks']
nt.assert_false(networks)
ports = _get_ports(token_id, engine_ip)['ports']
nt.assert_false(ports)
subnets = _get_subnets(token_id, engine_ip)['subnets']
nt.assert_false(subnets)
def detach_vm_network_from_host(api):
host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0]
network_utils_v3.set_network_required_in_cluster(
api, VM_NETWORK, CLUSTER_NAME, False)
network_utils_v3.detach_network_from_host(api, host, VM_NETWORK)
nt.assert_false(_host_is_attached_to_network(api, host, VM_NETWORK))
def remove_bonding(api):
def _remove_bonding(host):
network_utils_v3.detach_network_from_host(api, host, MIGRATION_NETWORK,
BOND_NAME)
network_utils_v3.set_network_required_in_cluster(api, MIGRATION_NETWORK,
CLUSTER_NAME, False)
utils.invoke_in_parallel(_remove_bonding,
test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME))
for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME):
nt.assert_false(_host_is_attached_to_network(api, host,
MIGRATION_NETWORK))