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

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

项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def test_strip_column_names():
    d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
         'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
         'PD L1 (val)': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),
         'PD L1 (>1)': pd.Series([0., 1., 1., 1.], index=['a', 'b', 'c', 'd']),
         }
    df = pd.DataFrame(d)

    # should not error & should rename columns
    df2 = df.rename(columns=strip_column_names(df.columns))
    ok_((df2.columns != df.columns).any())
    # should not rename columns -- should raise a warning
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        df3 = df.rename(columns=strip_column_names(
                        df.columns, keep_paren_contents=False))
        ok_(len(w) > 0, 'warning not raised when keep_paren_contents results in dups')
    ok_((df3.columns == df.columns).all())
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_pvs_effective_permittivity_real():
    testpack = setup_func_pc(0.3e-3)
    em = setup_func_mm(testpack)
    # Allow 5% error
    ok_(abs(em._effective_permittivity.real - 1.52441173e+00) < tolerance_pc * em._effective_permittivity.real)
    # eq_(em._effective_permittivity.real, 1.52441173e+00)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p3_mm():
    testpack = setup_func_pc(0.3e-3)
    em = setup_func_em(testpack)
    # Allow 5% error
    memls_ks = 4.13718676e+00
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p25_mm():
    testpack = setup_func_pc(0.25e-3)
    em = setup_func_em(testpack)
    # Allow 5% error
    memls_ks = 2.58158887e+00
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p2_mm():
    testpack = setup_func_pc(0.2e-3)
    em = setup_func_em(testpack)
    # Allow 5% error
    memls_ks = 1.41304849e+00
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p15_mm():
    testpack = setup_func_pc(0.15e-3)
    em = setup_func_em(testpack)
    # Allow 5% error
    memls_ks = 6.30218291e-01
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p2_mm():
    testpack = setup_func_pc(0.05e-3)
    em = setup_func_em(testpack)
    # Allow 5% error
    memls_ks = 2.49851702e-02
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_ks_pc_is_0p1_mm():
    testpack = setup_func_pc(0.1e-3)
    em = setup_func_mm(testpack)
    # Allow 5% error
    memls_ks = 1.94727497e-01
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) < tolerance_pc * em.ks)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_memlsks_pc_is_0p05_mm():
    testpack = setup_func_pc(0.05e-3)
    em = setup_func_mm(testpack)
    # Allow 5% error
    memls_ks = 2.49851702e-02
    # eq_(em.ks, memls_ks)
    ok_(abs(em.ks - memls_ks) / em.ks < tolerance_pc)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_memls_ka():
    testpack = setup_func_pc(0.05e-3)  # Corr fn is irrelevant
    em = setup_func_mm(testpack)
    # Allow 5% error
    memls_ka = 3.00937657e-01
    # eq_(em.ka, memls_ka)
    ok_(abs(em.ka - memls_ka) / em.ka < tolerance_pc)
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_iba_vs_rayleigh_passive_m0():
    em_iba, em_ray = setup_func_rayleigh()
    mu = setup_mu(1. / 64)
    ok_((abs(em_iba.ft_even_phase(0, mu, npol=2) / em_iba.ks - em_ray.ft_even_phase(0, mu, npol=2) / em_ray.ks) < tolerance_pc).all())
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_iba_vs_rayleigh_active_m1():
    em_iba, em_ray = setup_func_rayleigh()
    mu = setup_mu(1. / 64, bypass_exception=True)
    # Clear cache
    em_iba.cached_mu = None
    ok_((abs(em_iba.ft_even_phase(1, mu, npol=3) / em_iba.ks - em_ray.ft_even_phase(1, mu, npol=3) / em_ray.ks) < tolerance_pc).all())
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_iba_vs_rayleigh_active_m2():
    em_iba, em_ray = setup_func_rayleigh()
    mu = setup_mu(1. / 64, bypass_exception=True)
    ok_((abs(em_iba.ft_even_phase(2, mu, npol=3) / em_iba.ks - em_ray.ft_even_phase(2, mu, npol=3) / em_ray.ks) < tolerance_pc).all())
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_iba_raise_exception_mu_is_1():
    shs_pack = setup_func_shs()
    em = setup_func_active(testpack=shs_pack)
    bad_mu = np.array([0.2, 1])
    em.ft_even_phase(2, bad_mu, npol=3)

# def test_equivalence_ft_phase_and_phase():
#     em = setup_func_em()
#     em.set_max_mode(4)
#     mu = setup_mu()
#     phi = np.arange(0., 2. * np.pi, 2. * np.pi / mu.size)
#     phi_diff = phi - phi[:, np.newaxis]
#     p = em.phase(mu, phi)
#     pft = em.ft_phase(0, mu)
#     # Construct phi_diff matrix to recombine ft_phase
#     npol = 2
#     n = len(phi_diff)
#     pd = np.empty((npol * n, npol * n))
#     pd[0::npol, 0::npol] = phi_diff
#     pd[0::npol, 1::npol] = phi_diff
#     pd[1::npol, 0::npol] = phi_diff
#     pd[1::npol, 1::npol] = phi_diff
#     # Sum over decomposition modes
#     for m in range(1, 3):
#         pft += em.ft_phase(m, mu).real * np.cos(m * pd) + em.ft_phase(m, mu).imag * np.sin(m * pd)  # Imaginary component should be zero
#     phase_diff = p - pft
#     ok_(phase_diff.all() < TOLERANCE)
项目:bx-python    作者:bxlab    | 项目源码 | 文件源码
def tests(): 
    for i in range(len(trees)):
        _ = lambda: ok_( newick_parser.parse_string( trees[i] ) == results[i] )
        _.description = "check tree parsing " + str(i)
        yield _,
项目:web    作者:pyjobs    | 项目源码 | 文件源码
def test_index(self):
        """The front page is working properly"""
        response = self.app.get('/')
        msg = 'TurboGears 2 is rapid web application development toolkit '\
              'designed to make your life easier.'
        # You can look for specific strings:
        ok_(msg in response)

        # You can also access a BeautifulSoup'ed response in your tests
        # (First run $ easy_install BeautifulSoup
        # and then uncomment the next two lines)

        # links = response.html.findAll('a')
        # print(links)
        # ok_(links, "Mummy, there are no links here!")
项目:web    作者:pyjobs    | 项目源码 | 文件源码
def test_environ(self):
        """Displaying the wsgi environ works"""
        response = self.app.get('/environ.html')
        ok_('The keys in the environment are:' in response)
项目:web    作者:pyjobs    | 项目源码 | 文件源码
def test_data_json(self):
        """The data display demo works with JSON"""
        resp = self.app.get('/data.json?a=1&b=2')
        ok_(
            dict(page='data', params={'a': '1', 'b': '2'}) == resp.json,
            resp.json
        )
项目:web    作者:pyjobs    | 项目源码 | 文件源码
def test_secc_with_manager(self):
        """The manager can access the secure controller"""
        # Note how authentication is forged:
        environ = {'REMOTE_USER': 'manager'}
        resp = self.app.get('/secc', extra_environ=environ, status=200)
        ok_('Secure Controller here' in resp.text, resp.text)
项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def test_as_dataframe_generic():
    df_hello, cohort = prep_test_cohort()
    # test that column names haven't changed
    df = cohort.as_dataframe(join_with="hello")
    # column names should match those in df_hello
    res = compare_column_names(expected = df_hello.columns,
                               observed = df.columns)
    ok_(res, 'columns names failed to match expected')
项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def test_as_dataframe_good_rename():
    df_hello, cohort = prep_alt_test_cohort()
    # test behavior with rename_cols=True. should not raise a warning
    df = cohort.as_dataframe(rename_cols=True, join_with='hello')
    res = compare_column_names(expected = strip_column_names(df_hello.columns),
                               observed = df.columns)
    ok_(res, 'column names failed to match expected')
项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def test_as_dataframe_bad_rename():
    df_hello, cohort = prep_test_cohort()
    # test behavior with rename_cols=True. should raise a warning
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        df = cohort.as_dataframe(rename_cols=True, join_with='hello')
        # skip test since warnings (for some reason) don't propagate
        #ok_(len(w) > 0, 'fail to generate dups warning when using rename_cols=True')
    res = compare_column_names(expected = df_hello.columns,
                               observed = df.columns)
    ok_(res, 'columns names failed to match expected')
项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def test_as_dataframe_drop_parens():
    df_hello, cohort = prep_test_cohort()
    # test behavior with keep_paren_contents=False
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        df = cohort.as_dataframe(rename_cols=True, keep_paren_contents=False, join_with='hello')
        # skip test for warning since warning doesn't propagate (not sure why)
        #ok_(len(w) > 0, 'no warning when duplicates resulting from rename_cols')
    res = compare_column_names(expected = df_hello.columns,
                               observed = df.columns)
    ok_(res, 'columns names failed to match expected')
项目:smrt    作者:smrt-model    | 项目源码 | 文件源码
def test_mixed_emmodel():
    # prepare inputs
    l = 2

    nl = l//2  # // Forces integer division
    thickness = np.array([0.1, 0.1]*nl)
    thickness[-1] = 100  # last one is semi-infinit
    radius = np.array([2e-4]*l)
    temperature = np.array([250.0, 250.0]*nl)
    density = [200, 400]*nl
    stickiness = [0.1, 0.1]*nl
    emmodel = ["dmrt_qcacp_shortrange", "iba"]*nl

    # create the snowpack
    snowpack = make_snowpack(thickness,
                             "sticky_hard_spheres",
                             density=density,
                             temperature=temperature,
                             radius=radius,
                             stickiness=stickiness)

    # create the EM Model
    m = make_model(emmodel, "dort")

    # create the sensor
    radiometer = sensor_list.amsre('37V')

    # run the model
    res = m.run(radiometer, snowpack)

    print(res.TbV(), res.TbH())

    #ok_((res.TbV() - 203.84730126016882) < 1e-4)
    #ok_((res.TbH() - 189.53130277932084) < 1e-4)



    #ok_((res.TbV() - 203.8473395866384) < 1e-4)
    #ok_((res.TbH() - 189.53346053779396) < 1e-4)

    ok_((res.TbV() - 204.62367102418355) < 1e-4)
    ok_((res.TbH() - 190.38540104288276) < 1e-4)