Sebastian Rahlf avatar Sebastian Rahlf committed 86a078b

Enable test command to use version specifiers, ie. "devpi test my-pkg==0.3.1" (closes #71).

Comments (0)

Files changed (2)

client/devpi/remoteindex.py

+import pkg_resources
 from devpi_common.url import URL
 from devpi_common.metadata import splitbasename, Version
 from devpi_common.request import new_requests_session
         self.links = links
 
     def getnewestversion(self, pkgname):
+        """ returns newest applicable version of package """
+        req = next(pkg_resources.parse_requirements(pkgname))
         best = None
         for link in self.links:
             basename = URL(link.url).basename
             name, version = splitbasename(basename)[:2]
             ver = Version(version)
-            if name == pkgname:
+            if name == req.project_name and version in req:
                 if best is None or ver > best[0]:
                     best = ver, link
         return best and best[1] or None

client/testing/test_remoteindex.py

-
+import pytest
 from devpi.remoteindex import RemoteIndex, LinkSet, parselinks
 from devpi_common.url import URL
 from devpi.use import Current
         link = ri.getbestlink("pkg")
         assert link is None
 
+    @pytest.mark.parametrize("specs,link", [
+        ("pkg==0.2.8", "http://my/pkg-0.2.8.tar.gz"),
+        ("pkg<=0.2.8", "http://my/pkg-0.2.8.tar.gz"),
+        ("pkg<0.3", "http://my/pkg-0.2.8.tar.gz"),
+        ("pkg!=0.3", "http://my/pkg-0.2.8.tar.gz"),
+        ("pkg>0.2.8", "http://my/pkg-0.3.tar.gz"),
+        ("pkg>=0.2.8", "http://my/pkg-0.3.tar.gz"),
+        ("pkg<0.2.4,>0.2.2", "http://my/pkg-0.2.3.tar.gz"),
+    ])
+    def test_package_with_version_specs(self, monkeypatch, tmpdir, specs, link):
+        indexurl = "http://my/simple/"
+        current = Current(tmpdir.join("client"))
+        current.reconfigure(dict(simpleindex=indexurl))
+        ri = RemoteIndex(current)
+        def mockget(url):
+            assert url.startswith(indexurl)
+            return """
+                <a href="http://my/pkg-0.3.tar.gz"/>
+                <a href="http://my/pkg-0.2.8.tar.gz"/>
+                <a href="http://my/pkg-0.2.7.tar.gz"/>
+                <a href="http://my/pkg-0.2.6.tar.gz"/>
+                <a href="http://my/pkg-0.2.5.tar.gz"/>
+                <a href="http://my/pkg-0.2.5a1.tar.gz"/>
+                <a href="http://my/pkg-0.2.4.1.tar.gz"/>
+                <a href="http://my/pkg-0.2.4.tar.gz"/>
+                <a href="http://my/pkg-0.2.3.tar.gz"/>
+                <a href="http://my/pkg-0.2.2.tar.gz"/>
+                <a href="http://my/pkg-0.2.1.tar.gz"/>
+                <a href="http://my/pkg-0.2.0.tar.gz"/>
+            """
+        monkeypatch.setattr(ri, "getcontent", mockget)
+        lnk = ri.getbestlink(specs)
+        assert URL(lnk.url).url_nofrag == link
+
 def test_parselinks():
     content = """<html><a href="href" rel="rel">text</a></html>"""
     link = parselinks(content, "http://root")[0]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.