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

Python helpers.raises函数代码示例

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

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



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

示例1: test_unsat

def test_unsat():
    r.msd_cache = {}

    # scipy 0.12.0b1 is not built for numpy 1.5, only 1.6 and 1.7
    assert raises((RuntimeError, SystemExit), lambda: r.solve(["numpy 1.5*", "scipy 0.12.0b1"]), "conflict")
    # numpy 1.5 does not have a python 3 package
    assert raises((RuntimeError, SystemExit), lambda: r.solve(["numpy 1.5*", "python 3*"]), "conflict")
    assert raises((RuntimeError, SystemExit), lambda: r.solve(["numpy 1.5*", "numpy 1.6*"]), "conflict")
开发者ID:mdellorto,项目名称:conda,代码行数:8,代码来源:test_resolve.py


示例2: test_odd_even_merge

def test_odd_even_merge():
    for n in [1, 2, 4, 8, 16]:
        A = list(range(1, n+1))
        B = list(range(n+1, 2*n+1))
        C = Clauses(n)
        merged = C.odd_even_merge(A, B)
        for i in range(n+1):
            for j in range(n+1):
                # Test all possible mergings of sorted lists, like [1, 1, 0,
                # 0] and [1, 0, 0, 0] -> [1, 1, 1, 0, 0, 0, 0, 0].
                Asigns = [1]*i + [-1]*(n - i)
                Bsigns = [1]*j + [-1]*(n - j)
                As = {(s*a,) for s, a in zip(Asigns, A)}
                Bs = {(s*b,) for s, b in zip(Bsigns, B)}
                for sol in my_itersolve(C.clauses | As | Bs):
                    a = [i in sol for i in A]
                    b = [i in sol for i in B]
                    m = [i in sol for i in merged]
                    # Check we did the above correctly
                    assert a == sorted(a, reverse=True)
                    assert b == sorted(b, reverse=True)
                    # And check that the merge is correct
                    assert m == sorted(a + b, reverse=True)

    assert raises(ValueError, lambda: Clauses(4).odd_even_merge([1, 2], [2, 3, 4]))
开发者ID:aldanor,项目名称:conda,代码行数:25,代码来源:test_logic.py


示例3: test_odd_even_mergesort

def test_odd_even_mergesort():
    for n in [1, 2, 4, 8]:
        A = list(range(1, n+1))
        C = Clauses(n)
        S = C.odd_even_mergesort(A)
        # Note, the zero-one principle states we only need to test lists of
        # 0's and
        # 1's. https://en.wikipedia.org/wiki/Sorting_network#Zero-one_principle.
        for sol in my_itersolve(C.clauses):
            a = [i in sol for i in A]
            s = [i in sol for i in S]
            assert s == sorted(a, reverse=True)

    # TODO: n > 8 takes too long to test all combinations, but maybe we should test
    # some random combinations.

    assert raises(ValueError, lambda: Clauses(5).odd_even_mergesort([1, 2, 3,
    4, 5]))

    # Make sure it works with booleans
    for n in [1, 2, 4]:
        for item in product(*[[true, false]]*n):
            assert list(Clauses(0).odd_even_mergesort(item)) == sorted(item, reverse=True)

    # The most important use-case is extending a non-power of 2 length list
    # with false.
    for n in range(1, 9):
        next_power_of_2 = 2**ceil(log2(n))
        assert n <= next_power_of_2
        for item in product(*[[true, false]]*(next_power_of_2 - n)):

            A = list(range(1, n + 1)) + list(item)
            C = Clauses(n)
            S = C.odd_even_mergesort(A)

            for sol in my_itersolve(C.clauses):
                a = [boolize(i) if isinstance(boolize(i), bool) else
                    i in sol for i in A]
                s = [boolize(i) if isinstance(boolize(i), bool) else
                    i in sol for i in S]

                assert s == sorted(a, reverse=True), (a, s, sol)
开发者ID:aldanor,项目名称:conda,代码行数:42,代码来源:test_logic.py


示例4: test_minimal_unsatisfiable_subset

def test_minimal_unsatisfiable_subset():
    assert raises(ValueError, lambda: minimal_unsatisfiable_subset([[1]]))

    clauses = [[-10], [1], [5], [2, 3], [3, 4], [5, 2], [-7], [2], [3], [-2,
        -3, 5], [7, 8, 9, 10], [-8], [-9]]
    res = minimal_unsatisfiable_subset(clauses)
    assert sorted(res) == [[-10], [-9], [-8], [-7], [7, 8, 9, 10]]
    assert not sat(res)


    clauses = [[1, 3], [2, 3], [-1], [4], [3], [-3]]
    for perm in permutations(clauses):
        res = minimal_unsatisfiable_subset(clauses)
        assert sorted(res) == [[-3], [3]]
        assert not sat(res)

    clauses = [[1], [-1], [2], [-2], [3, 4], [4]]
    for perm in permutations(clauses):
        res = minimal_unsatisfiable_subset(perm)
        assert sorted(res) in [[[-1], [1]], [[-2], [2]]]
        assert not sat(res)
开发者ID:AvdN,项目名称:conda,代码行数:21,代码来源:test_logic.py


示例5: test_minimal_unsatisfiable_subset

def test_minimal_unsatisfiable_subset():
    def sat(val):
        return Clauses(max(abs(v) for v in chain(*val))).sat(val)
    assert raises(ValueError, lambda: minimal_unsatisfiable_subset([[1]], sat))

    clauses = [[-10], [1], [5], [2, 3], [3, 4], [5, 2], [-7], [2], [3],
        [-2, -3, 5], [7, 8, 9, 10], [-8], [-9]]
    res = minimal_unsatisfiable_subset(clauses, sat)
    assert sorted(res) == [[-10], [-9], [-8], [-7], [7, 8, 9, 10]]
    assert not sat(res)

    clauses = [[1, 3], [2, 3], [-1], [4], [3], [-3]]
    for perm in permutations(clauses):
        res = minimal_unsatisfiable_subset(clauses, sat)
        assert sorted(res) == [[-3], [3]]
        assert not sat(res)

    clauses = [[1], [-1], [2], [-2], [3, 4], [4]]
    for perm in permutations(clauses):
        res = minimal_unsatisfiable_subset(perm, sat)
        assert sorted(res) in [[[-1], [1]], [[-2], [2]]]
        assert not sat(res)
开发者ID:groutr,项目名称:conda,代码行数:22,代码来源:test_logic.py


示例6: test_package_ordering

def test_package_ordering():
    sympy_071 = Package("sympy-0.7.1-py27_0.tar.bz2", r.index["sympy-0.7.1-py27_0.tar.bz2"])
    sympy_072 = Package("sympy-0.7.2-py27_0.tar.bz2", r.index["sympy-0.7.2-py27_0.tar.bz2"])
    python_275 = Package("python-2.7.5-0.tar.bz2", r.index["python-2.7.5-0.tar.bz2"])
    numpy = Package("numpy-1.7.1-py27_0.tar.bz2", r.index["numpy-1.7.1-py27_0.tar.bz2"])
    numpy_mkl = Package("numpy-1.7.1-py27_p0.tar.bz2", r.index["numpy-1.7.1-py27_p0.tar.bz2"])

    assert sympy_071 < sympy_072
    assert not sympy_071 < sympy_071
    assert not sympy_072 < sympy_071
    raises(TypeError, lambda: sympy_071 < python_275)

    assert sympy_071 <= sympy_072
    assert sympy_071 <= sympy_071
    assert not sympy_072 <= sympy_071
    assert raises(TypeError, lambda: sympy_071 <= python_275)

    assert sympy_071 == sympy_071
    assert not sympy_071 == sympy_072
    assert (sympy_071 == python_275) is False
    assert (sympy_071 == 1) is False

    assert not sympy_071 != sympy_071
    assert sympy_071 != sympy_072
    assert (sympy_071 != python_275) is True

    assert not sympy_071 > sympy_072
    assert not sympy_071 > sympy_071
    assert sympy_072 > sympy_071
    raises(TypeError, lambda: sympy_071 > python_275)

    assert not sympy_071 >= sympy_072
    assert sympy_071 >= sympy_071
    assert sympy_072 >= sympy_071
    assert raises(TypeError, lambda: sympy_071 >= python_275)

    # The first four are a bit arbitrary. For now, we just test that it
    # doesn't prefer the mkl version.
    assert not numpy < numpy_mkl
    assert not numpy <= numpy_mkl
    assert numpy > numpy_mkl
    assert numpy >= numpy_mkl
    assert (numpy != numpy_mkl) is True
    assert (numpy == numpy_mkl) is False
开发者ID:mdellorto,项目名称:conda,代码行数:44,代码来源:test_resolve.py


示例7: test_nonexistent_deps


#.........这里部分代码省略.........
    }

    assert set(r.get_dists(["mypackage"], max_only=True).keys()) == {
        "mypackage-1.1-py33_0.tar.bz2",
        "nose-1.3.0-py26_0.tar.bz2",
        "nose-1.3.0-py27_0.tar.bz2",
        "nose-1.3.0-py33_0.tar.bz2",
        "openssl-1.0.1c-0.tar.bz2",
        "python-2.6.8-6.tar.bz2",
        "python-2.7.5-0.tar.bz2",
        "python-3.3.2-0.tar.bz2",
        "readline-6.2-0.tar.bz2",
        "sqlite-3.7.13-0.tar.bz2",
        "system-5.8-1.tar.bz2",
        "tk-8.5.13-0.tar.bz2",
        "zlib-1.2.7-0.tar.bz2",
    }

    assert (
        r.solve(["mypackage"])
        == r.solve(["mypackage 1.1"])
        == [
            "mypackage-1.1-py33_0.tar.bz2",
            "nose-1.3.0-py33_0.tar.bz2",
            "openssl-1.0.1c-0.tar.bz2",
            "python-3.3.2-0.tar.bz2",
            "readline-6.2-0.tar.bz2",
            "sqlite-3.7.13-0.tar.bz2",
            "system-5.8-1.tar.bz2",
            "tk-8.5.13-0.tar.bz2",
            "zlib-1.2.7-0.tar.bz2",
        ]
    )
    assert raises(NoPackagesFound, lambda: r.solve(["mypackage 1.0"]))

    assert r.solve(["anotherpackage 1.0"]) == [
        "anotherpackage-1.0-py33_0.tar.bz2",
        "mypackage-1.1-py33_0.tar.bz2",
        "nose-1.3.0-py33_0.tar.bz2",
        "openssl-1.0.1c-0.tar.bz2",
        "python-3.3.2-0.tar.bz2",
        "readline-6.2-0.tar.bz2",
        "sqlite-3.7.13-0.tar.bz2",
        "system-5.8-1.tar.bz2",
        "tk-8.5.13-0.tar.bz2",
        "zlib-1.2.7-0.tar.bz2",
    ]

    assert r.solve(["anotherpackage"]) == [
        "anotherpackage-2.0-py33_0.tar.bz2",
        "mypackage-1.1-py33_0.tar.bz2",
        "nose-1.3.0-py33_0.tar.bz2",
        "openssl-1.0.1c-0.tar.bz2",
        "python-3.3.2-0.tar.bz2",
        "readline-6.2-0.tar.bz2",
        "sqlite-3.7.13-0.tar.bz2",
        "system-5.8-1.tar.bz2",
        "tk-8.5.13-0.tar.bz2",
        "zlib-1.2.7-0.tar.bz2",
    ]

    # This time, the latest version is messed up
    index3 = index.copy()
    index3["mypackage-1.1-py33_0.tar.bz2"] = {
        "build": "py33_0",
        "build_number": 0,
开发者ID:mdellorto,项目名称:conda,代码行数:67,代码来源:test_resolve.py


示例8: test_nonexistent

def test_nonexistent():
    r.msd_cache = {}

    assert raises(NoPackagesFound, lambda: r.solve(["notarealpackage 2.0*"]), "No packages found")
    # This exact version of NumPy does not exist
    assert raises(NoPackagesFound, lambda: r.solve(["numpy 1.5"]), "No packages found")
开发者ID:mdellorto,项目名称:conda,代码行数:6,代码来源:test_resolve.py


示例9: test_nonexistent_deps

def test_nonexistent_deps():
    index2 = index.copy()
    index2['mypackage-1.0-py33_0.tar.bz2'] = Record(**{
        'build': 'py33_0',
        'build_number': 0,
        'depends': ['nose', 'python 3.3*', 'notarealpackage 2.0*'],
        'name': 'mypackage',
        'requires': ['nose 1.2.1', 'python 3.3'],
        'version': '1.0',
    })
    index2['mypackage-1.1-py33_0.tar.bz2'] = Record(**{
        'build': 'py33_0',
        'build_number': 0,
        'depends': ['nose', 'python 3.3*'],
        'name': 'mypackage',
        'requires': ['nose 1.2.1', 'python 3.3'],
        'version': '1.1',
    })
    index2['anotherpackage-1.0-py33_0.tar.bz2'] = Record(**{
        'build': 'py33_0',
        'build_number': 0,
        'depends': ['nose', 'mypackage 1.1'],
        'name': 'anotherpackage',
        'requires': ['nose', 'mypackage 1.1'],
        'version': '1.0',
    })
    index2['anotherpackage-2.0-py33_0.tar.bz2'] = Record(**{
        'build': 'py33_0',
        'build_number': 0,
        'depends': ['nose', 'mypackage'],
        'name': 'anotherpackage',
        'requires': ['nose', 'mypackage'],
        'version': '2.0',
    })
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r = Resolve(index2)

    assert set(r.find_matches(MatchSpec('mypackage'))) == {
        Dist('mypackage-1.0-py33_0.tar.bz2'),
        Dist('mypackage-1.1-py33_0.tar.bz2'),
    }
    assert set(d.to_filename() for d in r.get_reduced_index(['mypackage']).keys()) == {
        'mypackage-1.1-py33_0.tar.bz2',
        'nose-1.1.2-py33_0.tar.bz2',
        'nose-1.2.1-py33_0.tar.bz2',
        'nose-1.3.0-py33_0.tar.bz2',
        'openssl-1.0.1c-0.tar.bz2',
        'python-3.3.0-2.tar.bz2',
        'python-3.3.0-3.tar.bz2',
        'python-3.3.0-4.tar.bz2',
        'python-3.3.0-pro0.tar.bz2',
        'python-3.3.0-pro1.tar.bz2',
        'python-3.3.1-0.tar.bz2',
        'python-3.3.2-0.tar.bz2',
        'readline-6.2-0.tar.bz2',
        'sqlite-3.7.13-0.tar.bz2',
        'system-5.8-0.tar.bz2',
        'system-5.8-1.tar.bz2',
        'tk-8.5.13-0.tar.bz2',
        'zlib-1.2.7-0.tar.bz2'}

    assert r.install(['mypackage']) == r.install(['mypackage 1.1']) == [Dist(dname) for dname in [
        'mypackage-1.1-py33_0.tar.bz2',
        'nose-1.3.0-py33_0.tar.bz2',
        'openssl-1.0.1c-0.tar.bz2',
        'python-3.3.2-0.tar.bz2',
        'readline-6.2-0.tar.bz2',
        'sqlite-3.7.13-0.tar.bz2',
        'system-5.8-1.tar.bz2',
        'tk-8.5.13-0.tar.bz2',
        'zlib-1.2.7-0.tar.bz2',
    ]]
    assert raises(NoPackagesFoundError, lambda: r.install(['mypackage 1.0']))
    assert raises(NoPackagesFoundError, lambda: r.install(['mypackage 1.0', 'burgertime 1.0']))

    assert r.install(['anotherpackage 1.0']) == [Dist(dname) for dname in [
        'anotherpackage-1.0-py33_0.tar.bz2',
        'mypackage-1.1-py33_0.tar.bz2',
        'nose-1.3.0-py33_0.tar.bz2',
        'openssl-1.0.1c-0.tar.bz2',
        'python-3.3.2-0.tar.bz2',
        'readline-6.2-0.tar.bz2',
        'sqlite-3.7.13-0.tar.bz2',
        'system-5.8-1.tar.bz2',
        'tk-8.5.13-0.tar.bz2',
        'zlib-1.2.7-0.tar.bz2',
    ]]

    assert r.install(['anotherpackage']) == [Dist(dname) for dname in [
        'anotherpackage-2.0-py33_0.tar.bz2',
        'mypackage-1.1-py33_0.tar.bz2',
        'nose-1.3.0-py33_0.tar.bz2',
        'openssl-1.0.1c-0.tar.bz2',
        'python-3.3.2-0.tar.bz2',
        'readline-6.2-0.tar.bz2',
        'sqlite-3.7.13-0.tar.bz2',
        'system-5.8-1.tar.bz2',
        'tk-8.5.13-0.tar.bz2',
        'zlib-1.2.7-0.tar.bz2',
    ]]
#.........这里部分代码省略.........
开发者ID:Korijn,项目名称:conda,代码行数:101,代码来源:test_resolve.py


示例10: test_nonexistent

def test_nonexistent():
    assert raises(NoPackagesFoundError, lambda: r.get_pkgs('notarealpackage 2.0*'))
    assert raises(NoPackagesFoundError, lambda: r.install(['notarealpackage 2.0*']))
    # This exact version of NumPy does not exist
    assert raises(NoPackagesFoundError, lambda: r.install(['numpy 1.5']))
开发者ID:Korijn,项目名称:conda,代码行数:5,代码来源:test_resolve.py


示例11: test_unsat

def test_unsat():
    # scipy 0.12.0b1 is not built for numpy 1.5, only 1.6 and 1.7
    assert raises(UnsatisfiableError, lambda: r.install(['numpy 1.5*', 'scipy 0.12.0b1']))
    # numpy 1.5 does not have a python 3 package
    assert raises(UnsatisfiableError, lambda: r.install(['numpy 1.5*', 'python 3*']))
    assert raises(UnsatisfiableError, lambda: r.install(['numpy 1.5*', 'numpy 1.6*']))
开发者ID:Korijn,项目名称:conda,代码行数:6,代码来源:test_resolve.py


示例12: test_nonexistent

def test_nonexistent():
    assert not r.find_matches(MatchSpec('notarealpackage 2.0*'))
    assert raises(NoPackagesFoundError, lambda: r.install(['notarealpackage 2.0*']))
    # This exact version of NumPy does not exist
    assert raises(NoPackagesFoundError, lambda: r.install(['numpy 1.5']))
开发者ID:ESSS,项目名称:conda,代码行数:5,代码来源:test_resolve.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python helpers.run_conda_command函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.homogeneous函数代码示例发布时间: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