本文整理汇总了Python中nose.tools.assert_true方法的典型用法代码示例。如果您正苦于以下问题:Python tools.assert_true方法的具体用法?Python tools.assert_true怎么用?Python tools.assert_true使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nose.tools
的用法示例。
在下文中一共展示了tools.assert_true方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_euler_instability
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_euler_instability():
# Test for numerical errors in mat2euler
# problems arise for cos(y) near 0
po2 = pi / 2
zyx = po2, po2, po2
M = nea.euler2mat(*zyx)
# Round trip
M_back = nea.euler2mat(*nea.mat2euler(M))
yield assert_true, np.allclose(M, M_back)
# disturb matrix slightly
M_e = M - FLOAT_EPS
# round trip to test - OK
M_e_back = nea.euler2mat(*nea.mat2euler(M_e))
yield assert_true, np.allclose(M_e, M_e_back)
# not so with crude routine
M_e_back = nea.euler2mat(*crude_mat2euler(M_e))
yield assert_false, np.allclose(M_e, M_e_back)
示例2: test_sugar
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_sugar():
# Syntactic sugar for recoder class
codes = ((1,'one','1','first'), (2,'two'))
rc = Recoder(codes)
# Field1 is synonym for first named dict
yield assert_equal, rc.code, rc.field1
rc = Recoder(codes, fields=('code1', 'label'))
yield assert_equal, rc.code1, rc.field1
# Direct key access identical to key access for first named
yield assert_equal, rc[1], rc.field1[1]
yield assert_equal, rc['two'], rc.field1['two']
# keys gets all keys
yield assert_equal, set(rc.keys()), set((1,'one','1','first',2,'two'))
# value_set gets set of values from first column
yield assert_equal, rc.value_set(), set((1, 2))
# or named column if given
yield assert_equal, rc.value_set('label'), set(('one', 'two'))
# "in" works for values in and outside the set
yield assert_true, 'one' in rc
yield assert_false, 'three' in rc
示例3: test_upgrade_from_sha_with_unicode_password
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_upgrade_from_sha_with_unicode_password(self):
user = factories.User()
password = u'testpassword\xc2\xa0'
user_obj = model.User.by_name(user['name'])
# setup our user with an old password hash
old_hash = self._set_password(password)
user_obj._password = old_hash
user_obj.save()
nt.assert_true(user_obj.validate_password(password))
nt.assert_not_equals(old_hash, user_obj.password)
nt.assert_true(pbkdf2_sha512.identify(user_obj.password))
nt.assert_true(pbkdf2_sha512.verify(password, user_obj.password))
# check that we now allow unicode characters
nt.assert_false(pbkdf2_sha512.verify('testpassword',
user_obj.password))
示例4: test_subprocess_error
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_subprocess_error():
"""error in mp.Process doesn't crash"""
with new_kernel() as km:
iopub = km.iopub_channel
code = '\n'.join([
"import multiprocessing as mp",
"p = mp.Process(target=int, args=('hi',))",
"p.start()",
"p.join()",
])
msg_id, content = execute(km=km, code=code)
stdout, stderr = assemble_output(iopub)
nt.assert_equal(stdout, '')
nt.assert_true("ValueError" in stderr, stderr)
_check_mp_mode(km, expected=False)
_check_mp_mode(km, expected=False, stream="stderr")
示例5: test_extract_dates
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_extract_dates():
timestamps = [
'2013-07-03T16:34:52.249482',
'2013-07-03T16:34:52.249482Z',
'2013-07-03T16:34:52.249482Z-0800',
'2013-07-03T16:34:52.249482Z+0800',
'2013-07-03T16:34:52.249482Z+08:00',
'2013-07-03T16:34:52.249482Z-08:00',
'2013-07-03T16:34:52.249482-0800',
'2013-07-03T16:34:52.249482+0800',
'2013-07-03T16:34:52.249482+08:00',
'2013-07-03T16:34:52.249482-08:00',
]
extracted = jsonutil.extract_dates(timestamps)
ref = extracted[0]
for dt in extracted:
nt.assert_true(isinstance(dt, datetime.datetime))
nt.assert_equal(dt, ref)
示例6: test_get_ipython_cache_dir
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_get_ipython_cache_dir():
os.environ["HOME"] = HOME_TEST_DIR
if os.name == 'posix' and sys.platform != 'darwin':
# test default
os.makedirs(os.path.join(HOME_TEST_DIR, ".cache"))
os.environ.pop("XDG_CACHE_HOME", None)
ipdir = path.get_ipython_cache_dir()
nt.assert_equal(os.path.join(HOME_TEST_DIR, ".cache", "ipython"),
ipdir)
nt.assert_true(os.path.isdir(ipdir))
# test env override
os.environ["XDG_CACHE_HOME"] = XDG_CACHE_DIR
ipdir = path.get_ipython_cache_dir()
nt.assert_true(os.path.isdir(ipdir))
nt.assert_equal(ipdir, os.path.join(XDG_CACHE_DIR, "ipython"))
else:
nt.assert_equal(path.get_ipython_cache_dir(),
path.get_ipython_dir())
示例7: test_numpy_in_seq
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_numpy_in_seq():
import numpy
from numpy.testing.utils import assert_array_equal
for shape in SHAPES:
for dtype in DTYPES:
A = numpy.empty(shape, dtype=dtype)
_scrub_nan(A)
bufs = serialize_object((A,1,2,b'hello'))
canned = pickle.loads(bufs[0])
yield nt.assert_true(canned[0], CannedArray)
tup, r = unserialize_object(bufs)
B = tup[0]
yield nt.assert_equals(r, [])
yield nt.assert_equals(A.shape, B.shape)
yield nt.assert_equals(A.dtype, B.dtype)
yield assert_array_equal(A,B)
示例8: test_numpy_in_dict
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_numpy_in_dict():
import numpy
from numpy.testing.utils import assert_array_equal
for shape in SHAPES:
for dtype in DTYPES:
A = numpy.empty(shape, dtype=dtype)
_scrub_nan(A)
bufs = serialize_object(dict(a=A,b=1,c=range(20)))
canned = pickle.loads(bufs[0])
yield nt.assert_true(canned['a'], CannedArray)
d, r = unserialize_object(bufs)
B = d['a']
yield nt.assert_equals(r, [])
yield nt.assert_equals(A.shape, B.shape)
yield nt.assert_equals(A.dtype, B.dtype)
yield assert_array_equal(A,B)
示例9: test_class_inheritance
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
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])
yield nt.assert_true(canned['D'], CannedClass)
d, r = unserialize_object(bufs)
D2 = d['D']
yield nt.assert_equal(D2.a, D.a)
yield nt.assert_equal(D2.b, D.b)
示例10: test_get_connection_file
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_get_connection_file():
cfg = Config()
with TemporaryWorkingDirectory() as d:
cfg.ProfileDir.location = d
cf = 'kernel.json'
app = DummyConsoleApp(config=cfg, connection_file=cf)
app.initialize(argv=[])
profile_cf = os.path.join(app.profile_dir.location, 'security', cf)
nt.assert_equal(profile_cf, app.connection_file)
with open(profile_cf, 'w') as f:
f.write("{}")
nt.assert_true(os.path.exists(profile_cf))
nt.assert_equal(connect.get_connection_file(app), profile_cf)
app.connection_file = cf
nt.assert_equal(connect.get_connection_file(app), profile_cf)
示例11: test_subprocess_error
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_subprocess_error():
"""error in mp.Process doesn't crash"""
with new_kernel() as kc:
iopub = kc.iopub_channel
code = '\n'.join([
"import multiprocessing as mp",
"p = mp.Process(target=int, args=('hi',))",
"p.start()",
"p.join()",
])
msg_id, content = execute(kc=kc, code=code)
stdout, stderr = assemble_output(iopub)
nt.assert_equal(stdout, '')
nt.assert_true("ValueError" in stderr, stderr)
_check_mp_mode(kc, expected=False)
_check_mp_mode(kc, expected=False, stream="stderr")
# raw_input tests
示例12: test_deepreload
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_deepreload():
"Test that dreload does deep reloads and skips excluded modules."
with TemporaryDirectory() as tmpdir:
with prepended_to_syspath(tmpdir):
with open(os.path.join(tmpdir, 'A.py'), 'w') as f:
f.write("class Object(object):\n pass\n")
with open(os.path.join(tmpdir, 'B.py'), 'w') as f:
f.write("import A\n")
import A
import B
# Test that A is not reloaded.
obj = A.Object()
dreload(B, exclude=['A'])
nt.assert_true(isinstance(obj, A.Object))
# Test that A is reloaded.
obj = A.Object()
dreload(B)
nt.assert_false(isinstance(obj, A.Object))
示例13: test_last_two_blanks
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_last_two_blanks():
nt.assert_false(isp.last_two_blanks(''))
nt.assert_false(isp.last_two_blanks('abc'))
nt.assert_false(isp.last_two_blanks('abc\n'))
nt.assert_false(isp.last_two_blanks('abc\n\na'))
nt.assert_false(isp.last_two_blanks('abc\n \n'))
nt.assert_false(isp.last_two_blanks('abc\n\n'))
nt.assert_true(isp.last_two_blanks('\n\n'))
nt.assert_true(isp.last_two_blanks('\n\n '))
nt.assert_true(isp.last_two_blanks('\n \n'))
nt.assert_true(isp.last_two_blanks('abc\n\n '))
nt.assert_true(isp.last_two_blanks('abc\n\n\n'))
nt.assert_true(isp.last_two_blanks('abc\n\n \n'))
nt.assert_true(isp.last_two_blanks('abc\n\n \n '))
nt.assert_true(isp.last_two_blanks('abc\n\n \n \n'))
nt.assert_true(isp.last_two_blanks('abc\nd\n\n\n'))
nt.assert_true(isp.last_two_blanks('abc\nd\ne\nf\n\n\n'))
示例14: test_command_chain_dispatcher_ff
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_command_chain_dispatcher_ff():
"""Test two failing hooks"""
fail1 = Fail(u'fail1')
fail2 = Fail(u'fail2')
dp = CommandChainDispatcher([(0, fail1),
(10, fail2)])
try:
dp()
except TryNext as e:
nt.assert_equal(str(e), u'fail2')
else:
assert False, "Expected exception was not raised."
nt.assert_true(fail1.called)
nt.assert_true(fail2.called)
示例15: test_omit__names
# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_true [as 别名]
def test_omit__names():
# also happens to test IPCompleter as a configurable
ip = get_ipython()
ip._hidden_attr = 1
c = ip.Completer
ip.ex('ip=get_ipython()')
cfg = Config()
cfg.IPCompleter.omit__names = 0
c.update_config(cfg)
s,matches = c.complete('ip.')
nt.assert_true('ip.__str__' in matches)
nt.assert_true('ip._hidden_attr' in matches)
cfg.IPCompleter.omit__names = 1
c.update_config(cfg)
s,matches = c.complete('ip.')
nt.assert_false('ip.__str__' in matches)
nt.assert_true('ip._hidden_attr' in matches)
cfg.IPCompleter.omit__names = 2
c.update_config(cfg)
s,matches = c.complete('ip.')
nt.assert_false('ip.__str__' in matches)
nt.assert_false('ip._hidden_attr' in matches)
del ip._hidden_attr