Python numpy.testing 模块,assert_() 实例源码

我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用numpy.testing.assert_()

项目:radar    作者:amoose136    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:kubeface    作者:hammerlab    | 项目源码 | 文件源码
def test_put_and_get_to_bucket(bucket):
    data = "ABCDe" * 1000
    data_handle = BytesIO(data.encode("UTF-8"))
    file_name = "kubeface-test-%s.txt" % (
        str(time.time()).replace(".", ""))
    name = "%s/%s" % (bucket, file_name)
    storage.put(name, data_handle)
    testing.assert_equal(storage.list_contents(name), [file_name])
    testing.assert_(
        file_name in storage.list_contents("%s/kubeface-test-" % bucket))

    result_handle = storage.get(name)
    testing.assert_equal(result_handle.read().decode("UTF-8"), data)
    storage.delete(name)
    testing.assert_(
        file_name not in storage.list_contents("%s/" % bucket))
项目:kubeface    作者:hammerlab    | 项目源码 | 文件源码
def test_move(bucket):
    data = "ABCDe" * 1000
    data_handle = BytesIO(data.encode("UTF-8"))
    file_name = "kubeface-test-%s.txt" % (
        str(time.time()).replace(".", ""))
    name = "%s/%s" % (bucket, file_name)
    name2 = "%s/moved-%s" % (bucket, file_name)
    storage.put(name, data_handle)
    testing.assert_equal(storage.list_contents(name), [file_name])
    storage.move(name, name2)
    testing.assert_equal(storage.list_contents(name), [])
    testing.assert_equal(
        storage.list_contents(name2),
        ["moved-%s" % file_name])
    result_handle = storage.get(name2)
    testing.assert_equal(result_handle.read().decode("UTF-8"), data)
    storage.delete(name2)
    testing.assert_(
        ("moved-%s" % file_name) not in storage.list_contents("%s/" % bucket))
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:pyAFQ    作者:yeatmanlab    | 项目源码 | 文件源码
def test_fit_csd():
    fdata, fbval, fbvec = dpd.get_data('small_64D')
    with nbtmp.InTemporaryDirectory() as tmpdir:
        # Convert from npy to txt:
        bvals = np.load(fbval)
        bvecs = np.load(fbvec)
        np.savetxt(op.join(tmpdir, 'bvals.txt'), bvals)
        np.savetxt(op.join(tmpdir, 'bvecs.txt'), bvecs)
        for sh_order in [4, 6]:
            fname = csd.fit_csd(fdata, op.join(tmpdir, 'bvals.txt'),
                                op.join(tmpdir, 'bvecs.txt'),
                                out_dir=tmpdir, sh_order=sh_order)
            npt.assert_(op.exists(fname))
            sh_coeffs_img = nib.load(fname)
            npt.assert_equal(sh_order,
                             calculate_max_order(sh_coeffs_img.shape[-1]))
项目:pyAFQ    作者:yeatmanlab    | 项目源码 | 文件源码
def test_register_dwi():
    fdata, fbval, fbvec = dpd.get_data('small_64D')
    with nbtmp.InTemporaryDirectory() as tmpdir:
        # Use an abbreviated data-set:
        img = nib.load(fdata)
        data = img.get_data()[..., :10]
        nib.save(nib.Nifti1Image(data, img.affine),
                 op.join(tmpdir, 'data.nii.gz'))
        # Convert from npy to txt:
        bvals = np.load(fbval)
        bvecs = np.load(fbvec)
        np.savetxt(op.join(tmpdir, 'bvals.txt'), bvals[:10])
        np.savetxt(op.join(tmpdir, 'bvecs.txt'), bvecs[:10])
        reg_file = register_dwi(op.join(tmpdir, 'data.nii.gz'),
                                op.join(tmpdir, 'bvals.txt'),
                                op.join(tmpdir, 'bvecs.txt'))
        npt.assert_(op.exists(reg_file))
项目:pyAFQ    作者:yeatmanlab    | 项目源码 | 文件源码
def test_csd_tracking():
    for sh_order in [4, 8, 10]:
        fname = fit_csd(fdata, fbval, fbvec,
                        response=((0.0015, 0.0003, 0.0003), 100),
                        sh_order=8, lambda_=1, tau=0.1, mask=None,
                        out_dir=tmpdir.name)
        for directions in ["det", "prob"]:
            sl = track(fname, directions,
                       max_angle=30.,
                       sphere=None,
                       seed_mask=None,
                       seeds=seeds,
                       stop_mask=None,
                       step_size=0.5)

            npt.assert_(len(sl[0]) > 10)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't1', 's0', 's1']:
            assert_(t(23) == asbytes('2'))
            r = t('ab')
            assert_(r == asbytes('a'), repr(r))
            r = t(array('ab'))
            assert_(r == asbytes('a'), repr(r))
            r = t(array(77, 'u1'))
            assert_(r == asbytes('M'), repr(r))
            #assert_(_raises(ValueError, t, array([77,87])))
            #assert_(_raises(ValueError, t, array(77)))
        elif tname in ['ts', 'ss']:
            assert_(t(23) == asbytes('23        '), repr(t(23)))
            assert_(t('123456789abcdef') == asbytes('123456789a'))
        elif tname in ['t5', 's5']:
            assert_(t(23) == asbytes('23   '), repr(t(23)))
            assert_(t('ab') == asbytes('ab   '), repr(t('ab')))
            assert_(t('123456789abcdef') == asbytes('12345'))
        else:
            raise NotImplementedError
项目:pulse2percept    作者:uwescience    | 项目源码 | 文件源码
def test_Movie2Pulsetrain():
    fps = 30.0
    amplitude_transform = 'linear'
    amp_max = 90
    freq = 20
    pulse_dur = .075 / 1000.
    interphase_dur = .075 / 1000.
    tsample = .005 / 1000.
    pulsetype = 'cathodicfirst'
    stimtype = 'pulsetrain'
    rflum = np.zeros(100)
    rflum[50] = 1
    m2pt = stimuli.Movie2Pulsetrain(rflum,
                                    fps=fps,
                                    amp_transform=amplitude_transform,
                                    amp_max=amp_max,
                                    freq=freq,
                                    pulse_dur=pulse_dur,
                                    interphase_dur=interphase_dur,
                                    tsample=tsample,
                                    pulsetype=pulsetype,
                                    stimtype=stimtype)
    npt.assert_equal(m2pt.shape[0], round((rflum.shape[-1] / fps) / tsample))
    npt.assert_(m2pt.data.max() < amp_max)

    with pytest.raises(ValueError):
        stimuli.Movie2Pulsetrain(np.zeros(10), -0.1)
项目:pyAFQ    作者:yeatmanlab    | 项目源码 | 文件源码
def test_fit_dti():
    # Let's see whether we can pass a list of files for each one:
    fdata1, fbval1, fbvec1 = dpd.get_data('small_101D')
    fdata2, fbval2, fbvec2 = dpd.get_data('small_101D')

    with nbtmp.InTemporaryDirectory() as tmpdir:
        file_dict = dti.fit_dti([fdata1, fdata2],
                                [fbval1, fbval2],
                                [fbvec1, fbvec2],
                                out_dir=tmpdir)
        for f in file_dict.values():
            npt.assert_(op.exists(f))
项目:pyAFQ    作者:yeatmanlab    | 项目源码 | 文件源码
def test_dti_tracking():
    fdict = fit_dti(fdata, fbval, fbvec)
    for directions in ["det", "prob"]:
        sl = track(fdict['params'],
                   directions,
                   max_angle=30.,
                   sphere=None,
                   seed_mask=None,
                   seeds=1,
                   step_size=0.5)
        npt.assert_(len(sl[0]) > 10)
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def check_function(self, t):
        tname = t.__doc__.split()[0]
        if tname in ['t0', 't8', 's0', 's8']:
            err = 1e-5
        else:
            err = 0.0
        assert_(abs(t(234j) - 234.0j) <= err)
        assert_(abs(t(234.6) - 234.6) <= err)
        assert_(abs(t(long(234)) - 234.0) <= err)
        assert_(abs(t(234.6 + 3j) - (234.6 + 3j)) <= err)
        #assert_( abs(t('234')-234.)<=err)
        #assert_( abs(t('234.6')-234.6)<=err)
        assert_(abs(t(-234) + 234.) <= err)
        assert_(abs(t([234]) - 234.) <= err)
        assert_(abs(t((234,)) - 234.) <= err)
        assert_(abs(t(array(234)) - 234.) <= err)
        assert_(abs(t(array(23 + 4j, 'F')) - (23 + 4j)) <= err)
        assert_(abs(t(array([234])) - 234.) <= err)
        assert_(abs(t(array([[234]])) - 234.) <= err)
        assert_(abs(t(array([234], 'b')) + 22.) <= err)
        assert_(abs(t(array([234], 'h')) - 234.) <= err)
        assert_(abs(t(array([234], 'i')) - 234.) <= err)
        assert_(abs(t(array([234], 'l')) - 234.) <= err)
        assert_(abs(t(array([234], 'q')) - 234.) <= err)
        assert_(abs(t(array([234], 'f')) - 234.) <= err)
        assert_(abs(t(array([234], 'd')) - 234.) <= err)
        assert_(abs(t(array([234 + 3j], 'F')) - (234 + 3j)) <= err)
        assert_(abs(t(array([234], 'D')) - 234.) <= err)

        #assert_raises(TypeError, t, array([234], 'a1'))
        assert_raises(TypeError, t, 'abc')

        assert_raises(IndexError, t, [])
        assert_raises(IndexError, t, ())

        assert_raises(TypeError, t, t)
        assert_raises(TypeError, t, {})

        try:
            r = t(10 ** 400)
            assert_(repr(r) in ['(inf+0j)', '(Infinity+0j)'], repr(r))
        except OverflowError:
            pass