• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testing.assert_raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mdtraj.testing.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_raises函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_write_inconsistent

def test_write_inconsistent():
    coordinates = np.random.randn(4, 10,3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates)
        # since the first frames we saved didn't contain velocities, we
        # can't save more velocities
        assert_raises(ValueError, lambda: f.write(coordinates, velocities=coordinates))
开发者ID:anyuzx,项目名称:mdtraj,代码行数:7,代码来源:test_hdf5.py


示例2: test_write_inconsistent_2

def test_write_inconsistent_2():
    coordinates = np.random.randn(4, 10,3)
    with HDF5TrajectoryFile(temp, 'w') as f:
        f.write(coordinates, velocities=coordinates)
        # we're saving a deficient set of data, since before we wrote
        # more information.
        assert_raises(ValueError, lambda: f.write(coordinates))
开发者ID:anyuzx,项目名称:mdtraj,代码行数:7,代码来源:test_hdf5.py


示例3: test_nematic_order_args

def test_nematic_order_args():
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices='dog'))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices='O'))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=1))
    # Input indices with wrong "shapes".
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=[[1, [2]], [2]]))
    assert_raises(ValueError, lambda: order.compute_nematic_order(TRAJ2, indices=[1, 2, 3]))
开发者ID:OndrejMarsalek,项目名称:mdtraj,代码行数:7,代码来源:test_order.py


示例4: test_write_units_mismatch

def test_write_units_mismatch():
    velocoties = units.Quantity(np.random.randn(4, 10,3), units.angstroms/units.picosecond)

    with HDF5TrajectoryFile(temp, 'w') as f:
        # if you try to write coordinates that are unitted and not
        # in the correct units, we find that
        assert_raises(TypeError, lambda: f.write(coordinates=velocoties))
开发者ID:anyuzx,项目名称:mdtraj,代码行数:7,代码来源:test_hdf5.py


示例5: test_select_atom_indices

def test_select_atom_indices():
    top = md.load(get_fn("native.pdb")).topology

    yield lambda: eq(top.select_atom_indices("alpha"), np.array([8]))
    yield lambda: eq(top.select_atom_indices("minimal"), np.array([4, 5, 6, 8, 10, 14, 15, 16, 18]))

    assert_raises(ValueError, lambda: top.select_atom_indices("sdfsdfsdf"))
开发者ID:rafwiewiora,项目名称:mdtraj,代码行数:7,代码来源:test_topology.py


示例6: test_atoms_by_name

def test_atoms_by_name():
    top = md.load(get_fn('bpti.pdb')).topology

    atoms = list(top.atoms)
    for atom1, atom2 in zip(top.atoms_by_name('CA'), top.chain(0).atoms_by_name('CA')):
        assert atom1 == atom2
        assert atom1 in atoms
        assert atom1.name == 'CA'

    assert len(list(top.atoms_by_name('CA'))) == sum(1 for _ in atoms if _.name == 'CA')
    assert top.residue(15).atom('CA') == [a for a in top.residue(15).atoms if a.name == 'CA'][0]

    assert_raises(KeyError, lambda: top.residue(15).atom('sdfsdsdf'))
开发者ID:schilli,项目名称:mdtraj,代码行数:13,代码来源:test_topology.py


示例7: test_1

def test_1():
    # https://github.com/rmcgibbo/mdtraj/issues/438
    try:
        traj = md.load(get_fn('frame0.h5'))
        np.save('temp.npy', traj.xyz)

        traj.xyz = np.load('temp.npy', mmap_mode='r')

        # since traj isn't precentered, this requires centering
        # the coordinates which is done inplace. but that's not possible
        # with mmap_mode = 'r'
        assert_raises(ValueError, md.rmsd, traj, traj, 0)

        # this should work
        traj.xyz = np.load('temp.npy', mmap_mode='c')
        md.rmsd(traj, traj, 0)

    finally:
        del traj
        os.unlink('temp.npy')
开发者ID:ChayaSt,项目名称:mdtraj,代码行数:20,代码来源:test_rmsd_memmap.py


示例8: test_immutable

def test_immutable():
    def f():
        element.hydrogen.mass = 1
    def g():
        element.radium.symbol = 'sdfsdfsdf'
    def h():
        element.iron.name = 'sdfsdf'

    assert_raises(AttributeError, f)
    assert_raises(AttributeError, g)
    assert_raises(AttributeError, h)
    assert element.hydrogen.mass == 1.007947
    assert element.radium.symbol == 'Ra'
    assert element.iron.name == 'iron'
开发者ID:ChayaSt,项目名称:mdtraj,代码行数:14,代码来源:test_element.py


示例9: test_2

def test_2():
    # https://github.com/mdtraj/mdtraj/issues/438
    try:
        dir = tempfile.mkdtemp()
        fn = os.path.join(dir, 'temp.npy')
        traj = md.load(get_fn('frame0.h5'))
        # precenter the coordinates
        traj.center_coordinates()
        traces = traj._rmsd_traces
        np.save(fn, traj.xyz)
        traj.xyz = np.load(fn, mmap_mode='r')
        traj._rmsd_traces = traces

        with assert_raises(ValueError):
            md.rmsd(traj, traj, 0, precentered=True)

    finally:
        del traj
        os.unlink(fn)
        os.rmdir(dir)
开发者ID:anyuzx,项目名称:mdtraj,代码行数:20,代码来源:test_rmsd_memmap.py


示例10: test_1

def test_1():
    # https://github.com/mdtraj/mdtraj/issues/438
    try:
        dir = tempfile.mkdtemp()
        fn = os.path.join(dir, 'temp.npy')
        traj = md.load(get_fn('frame0.h5'))
        np.save(fn, traj.xyz)

        traj.xyz = np.load(fn, mmap_mode='r')

        # since traj isn't precentered, this requires centering
        # the coordinates which is done inplace. but that's not possible
        # with mmap_mode = 'r'
        with assert_raises(ValueError):
            md.rmsd(traj, traj, 0)

        # this should work
        traj.xyz = np.load(fn, mmap_mode='c')
        md.rmsd(traj, traj, 0)

    finally:
        del traj
        os.unlink(fn)
        os.rmdir(dir)
开发者ID:anyuzx,项目名称:mdtraj,代码行数:24,代码来源:test_rmsd_memmap.py


示例11: test_raises

def test_raises():
    assert_raises(ValueError, lambda: parse_selection('or'))
    assert_raises(ValueError, lambda: parse_selection('a <'))
开发者ID:ChayaSt,项目名称:mdtraj,代码行数:3,代码来源:test_selection.py


示例12: test_mismatch

def test_mismatch():
    # loading a 22 atoms xtc with a topology that has 2,000 atoms
    # some kind of error should happen!
    assert_raises(ValueError, lambda: md.load(get_fn('frame0.xtc'), top=get_fn('4ZUO.pdb')))
开发者ID:huynhqu1,项目名称:mdtraj,代码行数:4,代码来源:test_trajectory.py


示例13: test_raises2

def test_raises2():
    assert_raises(ValueError, lambda: parse_selection('dog 5'))
    assert_raises(ValueError, lambda: parse_selection('dog == 5'))
    assert_raises(ValueError, lambda: parse_selection('dog frog'))
    assert_raises(ValueError, lambda: parse_selection('not dog'))
    assert_raises(ValueError, lambda: parse_selection('protein or dog'))
    assert_raises(ValueError, lambda: parse_selection('dog 1 to 5'))
    assert_raises(ValueError, lambda: parse_selection('dog'))
开发者ID:schwancr,项目名称:mdtraj,代码行数:8,代码来源:test_selection.py


示例14: test_2

 def test_2():
     fn = 'temp-2%s' % ext
     open(fn, 'w').close()
     assert_raises(IOError,
                   lambda: t_ref.save(fn, force_overwrite=False))
开发者ID:msultan,项目名称:mdtraj,代码行数:5,代码来源:test_trajectory.py



注:本文中的mdtraj.testing.assert_raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.eq函数代码示例发布时间:2022-05-27
下一篇:
Python io.loadh函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap