[Python-checkins] distutils2: added zip_dir_into
tarek.ziade
python-checkins at python.org
Sun Jul 4 11:48:38 CEST 2010
tarek.ziade pushed 3804252d385c to distutils2:
http://hg.python.org/distutils2/rev/3804252d385c
changeset: 269:3804252d385c
user: Konrad Delong <konryd at gmail.com>
date: Thu May 13 22:02:57 2010 +0200
summary: added zip_dir_into
files: src/distutils2/command/upload_docs.py, src/distutils2/tests/test_upload_docs.py
diff --git a/src/distutils2/command/upload_docs.py b/src/distutils2/command/upload_docs.py
--- a/src/distutils2/command/upload_docs.py
+++ b/src/distutils2/command/upload_docs.py
@@ -1,6 +1,19 @@
-import os.path
+import os.path, tempfile, zipfile
from distutils2.core import Command
+def zip_dir_into(directory, destination):
+ """Compresses recursively contents of directory into a zipfile located
+ under given destination.
+ """
+ zip_file = zipfile.ZipFile(destination, "w")
+ for root, dirs, files in os.walk(directory):
+ for name in files:
+ full = os.path.join(root, name)
+ relative = root[len(directory):].lstrip(os.path.sep)
+ dest = os.path.join(relative, name)
+ zip_file.write(full, dest)
+ zip_file.close()
+
class upload_docs(Command):
user_options = [
diff --git a/src/distutils2/tests/test_upload_docs.py b/src/distutils2/tests/test_upload_docs.py
--- a/src/distutils2/tests/test_upload_docs.py
+++ b/src/distutils2/tests/test_upload_docs.py
@@ -1,32 +1,52 @@
"""Tests for distutils.command.upload_docs."""
# -*- encoding: utf8 -*-
-import os, os.path, unittest2
+import os, os.path, tempfile, unittest2, zipfile
-from distutils2.command.upload_docs import upload_docs
+from distutils2.command.upload_docs import upload_docs, zip_dir_into
from distutils2.core import Distribution
+from distutils2.tests import support
from distutils2.tests.pypi_server import PyPIServer
from distutils2.tests.test_upload import PyPIServerTestCase
from distutils2.tests.test_config import PYPIRC, PyPIRCCommandTestCase
-class UploadDocsTestCase(PyPIServerTestCase, PyPIRCCommandTestCase):
+class UploadDocsTestCase(PyPIServerTestCase,
+ support.TempdirManager,
+ unittest2.TestCase):
def setUp(self):
super(UploadDocsTestCase, self).setUp()
self.dist = Distribution()
self.cmd = upload_docs(self.dist)
- def test_generates_uploaddir_if_none(self):
+ def test_generates_uploaddir_name_not_given(self):
self.cmd.ensure_finalized()
self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
+ def test_zip_dir_into(self):
+ source_dir = tempfile.mkdtemp()
+ os.mkdir(os.path.join(source_dir, "some_dir"))
+ some_file = open(os.path.join(source_dir, "some_dir", "some_file"), "w")
+ some_file.write("Ce mortel ennui")
+ some_file.close()
+ dest_dir = tempfile.mkdtemp()
+ destination = os.path.join(dest_dir, "archive.zip")
+ zip_dir_into(source_dir, destination)
+
+ self.assertTrue(zipfile.is_zipfile(destination))
+ zip_f = zipfile.ZipFile(destination)
+ self.assertEqual(zip_f.namelist(), ['some_dir/some_file'])
+
def test_zip_dir(self):
pass
def test_upload(self):
pass
+ def test_honours_dry_run(self):
+ pass
+
def test_suite():
return unittest2.makeSuite(UploadDocsTestCase)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list