python类Environment()的实例源码

test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras(self):
        """Extras are also evaluated as markers at resolution time."""
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'")))
        )
        ad.add(Foo)
        assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        res = list(ws.resolve(parse_requirements("Foo[baz]"), ad))
        assert res == [Foo, quux]
test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_multiple_extras(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'\n"
                               "Provides-Extra: bar\n"
                               "Requires-Dist: fred; extra=='bar'\n")))
        )
        ad.add(Foo)
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        fred = Distribution.from_filename("/foo_dir/fred-0.1.dist-info")
        ad.add(fred)
        res = list(ws.resolve(parse_requirements("Foo[baz,bar]"), ad))
        assert sorted(res) == [fred, quux, Foo]
test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras_loop(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        a = Distribution.from_filename(
            "/foo_dir/a-0.2.dist-info",
            metadata=Metadata(("METADATA", str("Requires-Dist: c[a]")))
        )
        b = Distribution.from_filename(
            "/foo_dir/b-0.3.dist-info",
            metadata=Metadata(("METADATA", str("Requires-Dist: c[b]")))
        )
        c = Distribution.from_filename(
            "/foo_dir/c-1.0.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: a\n"
                               "Requires-Dist: b;extra=='a'\n"
                               "Provides-Extra: b\n"
                               "Requires-Dist: foo;extra=='b'")))
        )
        foo = Distribution.from_filename("/foo_dir/foo-0.1.dist-info")
        for dist in (a, b, c, foo):
            ad.add(dist)
        res = list(ws.resolve(parse_requirements("a"), ad))
        assert res == [a, c, b, foo]
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_multiple_extras(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", "Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'\n"
                               "Provides-Extra: bar\n"
                               "Requires-Dist: fred; extra=='bar'\n"))
        )
        ad.add(Foo)
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        fred = Distribution.from_filename("/foo_dir/fred-0.1.dist-info")
        ad.add(fred)
        res = list(ws.resolve(parse_requirements("Foo[baz,bar]"), ad))
        assert sorted(res) == [fred, quux, Foo]
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras_loop(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        a = Distribution.from_filename(
            "/foo_dir/a-0.2.dist-info",
            metadata=Metadata(("METADATA", "Requires-Dist: c[a]"))
        )
        b = Distribution.from_filename(
            "/foo_dir/b-0.3.dist-info",
            metadata=Metadata(("METADATA", "Requires-Dist: c[b]"))
        )
        c = Distribution.from_filename(
            "/foo_dir/c-1.0.dist-info",
            metadata=Metadata(("METADATA", "Provides-Extra: a\n"
                               "Requires-Dist: b;extra=='a'\n"
                               "Provides-Extra: b\n"
                               "Requires-Dist: foo;extra=='b'"))
        )
        foo = Distribution.from_filename("/foo_dir/foo-0.1.dist-info")
        for dist in (a, b, c, foo):
            ad.add(dist)
        res = list(ws.resolve(parse_requirements("a"), ad))
        assert res == [a, c, b, foo]
test_resources.py 文件源码 项目:browser_vuln_check 作者: lcatro 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras(self):
        """Extras are also evaluated as markers at resolution time."""
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'")))
        )
        ad.add(Foo)
        assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        res = list(ws.resolve(parse_requirements("Foo[baz]"), ad))
        assert res == [Foo, quux]
test_resources.py 文件源码 项目:browser_vuln_check 作者: lcatro 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_multiple_extras(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'\n"
                               "Provides-Extra: bar\n"
                               "Requires-Dist: fred; extra=='bar'\n")))
        )
        ad.add(Foo)
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        fred = Distribution.from_filename("/foo_dir/fred-0.1.dist-info")
        ad.add(fred)
        res = list(ws.resolve(parse_requirements("Foo[baz,bar]"), ad))
        assert sorted(res) == [fred, quux, Foo]
test_resources.py 文件源码 项目:browser_vuln_check 作者: lcatro 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras_loop(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Metadata needs to be native strings due to cStringIO behaviour in
        # 2.6, so use str().
        a = Distribution.from_filename(
            "/foo_dir/a-0.2.dist-info",
            metadata=Metadata(("METADATA", str("Requires-Dist: c[a]")))
        )
        b = Distribution.from_filename(
            "/foo_dir/b-0.3.dist-info",
            metadata=Metadata(("METADATA", str("Requires-Dist: c[b]")))
        )
        c = Distribution.from_filename(
            "/foo_dir/c-1.0.dist-info",
            metadata=Metadata(("METADATA", str("Provides-Extra: a\n"
                               "Requires-Dist: b;extra=='a'\n"
                               "Provides-Extra: b\n"
                               "Requires-Dist: foo;extra=='b'")))
        )
        foo = Distribution.from_filename("/foo_dir/foo-0.1.dist-info")
        for dist in (a, b, c, foo):
            ad.add(dist)
        res = list(ws.resolve(parse_requirements("a"), ad))
        assert res == [a, c, b, foo]
egg.py 文件源码 项目:dockeroo 作者: dockeroo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def install_source(self, source, destkey='location'):
        if 'build-directory' not in source:
            return
        env = Environment([source['build-directory']])
        self.recipe.mkdir(source[destkey])
        for dists in [env[x] for x in env]:
            for src_dist in dists:
                dst_dist = src_dist.clone(
                    location=os.path.join(source[destkey],
                                          "{}.{}".format(src_dist.egg_name(), {
                                              EGG_DIST: 'egg',
                                              DEVELOP_DIST: 'egg-link',
                                          }[src_dist.precedence])))
                {
                    EGG_DIST: lambda src, dst:
                              self.recipe.copy(src, dst)
                              if os.path.isdir(src) else
                              self.recipe.extract_archive(src, dst),
                    DEVELOP_DIST: os.rename,
                }[src_dist.precedence](src_dist.location, dst_dist.location)
                # redo_pyc(newloc)
                self.working_set.add_entry(dst_dist.location)
                self.logger.info('''Got {}.'''.format(
                    str(dst_dist.egg_name())))
test_resources.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
test_resources.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
views.py 文件源码 项目:fallball-service 作者: ingrammicro 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get(self, *args, **kwargs):
        env = pkg_resources.Environment()
        res = env._distmap.get('fallball', [None])[0]
        version = res.version if res else ''
        return Response({'description': 'Fallball - File sharing, that everyone learns',
                         'version': version})
test_resources.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
test_resources.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
tests.py 文件源码 项目:gmailtool 作者: adamandpaul 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_suite(package_name='gmailtool', pattern='*_test.py'):
    """Create the test suite used for the test runer

    Discover tests and load them into a test suite.

    Args:
        package_name (str): The package we are interested in loading a test suite for
        pattern (str): The glob patten used for test discovery

    Returns:
        TestSuite: The test suite to be used for the test runner
    """

    # The egg info object is needed to get the top_level_dir value
    environment = pkg_resources.Environment()
    assert len(environment[package_name]), 'we should only have a single environment to deal with'
    this_egg_info = environment[package_name][0]

    # Find the top_level_dir, because namespaces don't work too good with unittest
    top_level_dir = this_egg_info.location

    test_loader = unittest.TestLoader()
    suite = test_loader.discover(package_name,
                                 pattern=pattern,
                                 top_level_dir=top_level_dir)
    return suite
test_resources.py 文件源码 项目:chalktalk_docs 作者: loremIpsum1771 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        assert list(ws.resolve([], ad)) == []
        # Request something not in the collection -> DistributionNotFound
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo"), ad)

        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            assert targets == [Foo]
            list(map(ws.add,targets))
        with pytest.raises(VersionConflict):
            ws.resolve(parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo[bar]"), ad)
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) ==[Foo,Baz]
        # Requests for conflicting versions produce VersionConflict
        with pytest.raises(VersionConflict) as vc:
            ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)

        msg = 'Foo 0.9 is installed but Foo==1.2 is required'
        assert vc.value.report() == msg
test_resources.py 文件源码 项目:Flask-NvRay-Blog 作者: rui7157 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
test_resources.py 文件源码 项目:NeuroMobile 作者: AndrewADykman 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        self.assertEqual(list(ws.resolve([],ad)), [])
        # Request something not in the collection -> DistributionNotFound
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad
        )
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            self.assertEqual(targets, [Foo])
            list(map(ws.add,targets))
        self.assertRaises(VersionConflict, ws.resolve,
            parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        self.assertRaises(
            pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad
        )
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        self.assertEqual(
            list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz]
        )
        # Requests for conflicting versions produce VersionConflict
        self.assertRaises(VersionConflict,
            ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
test_resources.py 文件源码 项目:Sudoku-Solver 作者: ayush1997 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        assert list(ws.resolve([], ad)) == []
        # Request something not in the collection -> DistributionNotFound
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo"), ad)

        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            assert targets == [Foo]
            list(map(ws.add,targets))
        with pytest.raises(VersionConflict):
            ws.resolve(parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([]) # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo[bar]"), ad)
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) ==[Foo,Baz]
        # Requests for conflicting versions produce VersionConflict
        with pytest.raises(VersionConflict) as vc:
            ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)

        msg = 'Foo 0.9 is installed but Foo==1.2 is required'
        assert vc.value.report() == msg
test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        assert list(ws.resolve([], ad)) == []
        # Request something not in the collection -> DistributionNotFound
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo"), ad)

        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            assert targets == [Foo]
            list(map(ws.add, targets))
        with pytest.raises(VersionConflict):
            ws.resolve(parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([])  # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo[bar]"), ad)
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) == [Foo, Baz]
        # Requests for conflicting versions produce VersionConflict
        with pytest.raises(VersionConflict) as vc:
            ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)

        msg = 'Foo 0.9 is installed but Foo==1.2 is required'
        assert vc.value.report() == msg
test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_environment_marker_evaluation_negative(self):
        """Environment markers are evaluated at resolution time."""
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        res = ws.resolve(parse_requirements("Foo;python_version<'2'"), ad)
        assert list(res) == []
test_resources.py 文件源码 项目:pkg_resources 作者: pypa 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_environment_marker_evaluation_positive(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        Foo = Distribution.from_filename("/foo_dir/Foo-1.2.dist-info")
        ad.add(Foo)
        res = ws.resolve(parse_requirements("Foo;python_version>='2'"), ad)
        assert list(res) == [Foo]
cli.py 文件源码 项目:compatify 作者: hatooku 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_deps(self):
        """
        Show dependencies for package(s)

        @returns: 0 - sucess  1 - No dependency info supplied
        """

        pkgs = pkg_resources.Environment()

        for pkg in pkgs[self.project_name]:
            if not self.version:
                print pkg.project_name, pkg.version

            i = len(pkg._dep_map.values()[0])
            if i:
                while i:
                    if not self.version or self.version and \
                            pkg.version == self.version:
                        if self.version and i == len(pkg._dep_map.values()[0]):
                            print pkg.project_name, pkg.version
                        print "  " + str(pkg._dep_map.values()[0][i - 1])
                    i -= 1
            else:
                self.logger.info(\
                    "No dependency information was supplied with the package.")
                return 1
        return 0
yolklib.py 文件源码 项目:compatify 作者: hatooku 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self):
        """init"""

        self.environment = pkg_resources.Environment()
        self.working_set = pkg_resources.WorkingSet()
cli.py 文件源码 项目:compatify 作者: hatooku 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_deps(self):
        """
        Show dependencies for package(s)

        @returns: 0 - sucess  1 - No dependency info supplied
        """

        pkgs = pkg_resources.Environment()

        for pkg in pkgs[self.project_name]:
            if not self.version:
                print pkg.project_name, pkg.version

            i = len(pkg._dep_map.values()[0])
            if i:
                while i:
                    if not self.version or self.version and \
                            pkg.version == self.version:
                        if self.version and i == len(pkg._dep_map.values()[0]):
                            print pkg.project_name, pkg.version
                        print "  " + str(pkg._dep_map.values()[0][i - 1])
                    i -= 1
            else:
                self.logger.info(\
                    "No dependency information was supplied with the package.")
                return 1
        return 0
yolklib.py 文件源码 项目:compatify 作者: hatooku 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self):
        """init"""

        self.environment = pkg_resources.Environment()
        self.working_set = pkg_resources.WorkingSet()
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def testResolve(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        # Resolving no requirements -> nothing to install
        assert list(ws.resolve([], ad)) == []
        # Request something not in the collection -> DistributionNotFound
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo"), ad)

        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.egg",
            metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0"))
        )
        ad.add(Foo)
        ad.add(Distribution.from_filename("Foo-0.9.egg"))

        # Request thing(s) that are available -> list to activate
        for i in range(3):
            targets = list(ws.resolve(parse_requirements("Foo"), ad))
            assert targets == [Foo]
            list(map(ws.add, targets))
        with pytest.raises(VersionConflict):
            ws.resolve(parse_requirements("Foo==0.9"), ad)
        ws = WorkingSet([])  # reset

        # Request an extra that causes an unresolved dependency for "Baz"
        with pytest.raises(pkg_resources.DistributionNotFound):
            ws.resolve(parse_requirements("Foo[bar]"), ad)
        Baz = Distribution.from_filename(
            "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo"))
        )
        ad.add(Baz)

        # Activation list now includes resolved dependency
        assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) == [Foo, Baz]
        # Requests for conflicting versions produce VersionConflict
        with pytest.raises(VersionConflict) as vc:
            ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)

        msg = 'Foo 0.9 is installed but Foo==1.2 is required'
        assert vc.value.report() == msg
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_environment_marker_evaluation_negative(self):
        """Environment markers are evaluated at resolution time."""
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        res = ws.resolve(parse_requirements("Foo;python_version<'2'"), ad)
        assert list(res) == []
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_environment_marker_evaluation_positive(self):
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        Foo = Distribution.from_filename("/foo_dir/Foo-1.2.dist-info")
        ad.add(Foo)
        res = ws.resolve(parse_requirements("Foo;python_version>='2'"), ad)
        assert list(res) == [Foo]
test_resources.py 文件源码 项目:setuptools 作者: pypa 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_marker_evaluation_with_extras(self):
        """Extras are also evaluated as markers at resolution time."""
        ad = pkg_resources.Environment([])
        ws = WorkingSet([])
        Foo = Distribution.from_filename(
            "/foo_dir/Foo-1.2.dist-info",
            metadata=Metadata(("METADATA", "Provides-Extra: baz\n"
                               "Requires-Dist: quux; extra=='baz'"))
        )
        ad.add(Foo)
        assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
        quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
        ad.add(quux)
        res = list(ws.resolve(parse_requirements("Foo[baz]"), ad))
        assert res == [Foo, quux]


问题


面经


文章

微信
公众号

扫码关注公众号