[Python-checkins] distutils2: added a test for the unpack API
tarek.ziade
python-checkins at python.org
Sun Jan 30 14:49:25 CET 2011
tarek.ziade pushed 2b01c666abd7 to distutils2:
http://hg.python.org/distutils2/rev/2b01c666abd7
changeset: 977:2b01c666abd7
parent: 967:cc0a674dca07
user: Tarek Ziade <tarek at ziade.org>
date: Sun Jan 30 14:48:53 2011 +0100
summary:
added a test for the unpack API
files:
distutils2/_backport/shutil.py
distutils2/index/dist.py
distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz
distutils2/tests/test_index_dist.py
diff --git a/distutils2/_backport/shutil.py b/distutils2/_backport/shutil.py
--- a/distutils2/_backport/shutil.py
+++ b/distutils2/_backport/shutil.py
@@ -764,3 +764,5 @@
if func is None:
raise ValueError('Unknown archive format: %s' % filename)
+
+ return extract_dir
diff --git a/distutils2/index/dist.py b/distutils2/index/dist.py
--- a/distutils2/index/dist.py
+++ b/distutils2/index/dist.py
@@ -149,6 +149,16 @@
dist = self.dists.values()[0]
return dist
+ def unpack(self, path=None, prefer_source=True):
+ """Unpack the distribution to the given path.
+
+ If not destination is given, creates a temporary location.
+
+ Returns the location of the extracted files (root).
+ """
+ return self.get_distribution(prefer_source=prefer_source)\
+ .unpack(path=path)
+
def download(self, temp_path=None, prefer_source=True):
"""Download the distribution, using the requirements.
@@ -312,7 +322,7 @@
if path is None:
path = tempfile.mkdtemp()
- filename = self.download()
+ filename = self.download(path)
content_type = mimetypes.guess_type(filename)[0]
self._unpacked_dir = unpack_archive(filename)
@@ -332,8 +342,11 @@
% (hashval.hexdigest(), expected_hashval))
def __repr__(self):
+ if self.release is None:
+ return "<? ? %s>" % self.dist_type
+
return "<%s %s %s>" % (
- self.release.name, self.release.version, self.dist_type or "")
+ self.release.name, self.release.version, self.dist_type or "")
class ReleasesList(IndexReference):
diff --git a/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz b/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz
index 0000000000000000000000000000000000000000..333961eb18a6e7db80fefd41c339ab218d5180c4
GIT binary patch
literal 110
zc$|~(=3uy!>FUeC{PvtR-ysJc)&sVu<PP%fK3N&$;N1M<j{R(=POen}XGQA#H*w#;
z=4~0pQ=DD>?9yZ7`(A1Di)P(6s!I71JWZ;--fWND`LA)=lAmk-7Jbj=XMlnFEsQ#U
Kd|Vkc7#IK&xGYxy
diff --git a/distutils2/tests/test_index_dist.py b/distutils2/tests/test_index_dist.py
--- a/distutils2/tests/test_index_dist.py
+++ b/distutils2/tests/test_index_dist.py
@@ -127,7 +127,7 @@
url = "%s/simple/foobar/foobar-0.1.tar.gz" % server.full_address
# check md5 if given
dist = Dist(url=url, hashname="md5",
- hashval="d41d8cd98f00b204e9800998ecf8427e")
+ hashval="fe18804c5b722ff024cabdf514924fc4")
dist.download(self.mkdtemp())
# a wrong md5 fails
@@ -157,6 +157,24 @@
hashname="invalid_hashname",
hashval="value")
+ @use_pypi_server('downloads_with_md5')
+ def test_unpack(self, server):
+ url = "%s/simple/foobar/foobar-0.1.tar.gz" % server.full_address
+ dist = Dist(url=url)
+ # doing an unpack
+ here = self.mkdtemp()
+ there = dist.unpack(here)
+ result = os.listdir(there)
+ self.assertIn('paf', result)
+
+ def test_hashname(self):
+ # Invalid hashnames raises an exception on assignation
+ Dist(hashname="md5", hashval="value")
+
+ self.assertRaises(UnsupportedHashName, Dist,
+ hashname="invalid_hashname",
+ hashval="value")
+
class TestReleasesList(unittest.TestCase):
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list