~ubuntu-branches/ubuntu/precise/distribute/precise

« back to all changes in this revision

Viewing changes to setuptools/tests/test_upload_docs.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-12-28 23:52:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091228235240-mw9ruki1uprxfmo2
Tags: 0.6.10-1
* New upstream version.
* Stop building for python2.4. Closes: #557000.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""build_ext tests
 
2
"""
 
3
import sys, os, shutil, tempfile, unittest, site, zipfile
 
4
from setuptools.command.upload_docs import upload_docs
 
5
from setuptools.dist import Distribution
 
6
 
 
7
SETUP_PY = """\
 
8
from setuptools import setup
 
9
 
 
10
setup(name='foo')
 
11
"""
 
12
 
 
13
class TestUploadDocsTest(unittest.TestCase):
 
14
    def setUp(self):
 
15
        self.dir = tempfile.mkdtemp()
 
16
        setup = os.path.join(self.dir, 'setup.py')
 
17
        f = open(setup, 'w')
 
18
        f.write(SETUP_PY)
 
19
        f.close()
 
20
        self.old_cwd = os.getcwd()
 
21
        os.chdir(self.dir)
 
22
        
 
23
        self.upload_dir = os.path.join(self.dir, 'build')
 
24
        os.mkdir(self.upload_dir)
 
25
        
 
26
        # A test document.
 
27
        f = open(os.path.join(self.upload_dir, 'index.html'), 'w')
 
28
        f.write("Hello world.")
 
29
        f.close()
 
30
        
 
31
        # An empty folder.
 
32
        os.mkdir(os.path.join(self.upload_dir, 'empty'))
 
33
        
 
34
        if sys.version >= "2.6":
 
35
            self.old_base = site.USER_BASE
 
36
            site.USER_BASE = upload_docs.USER_BASE = tempfile.mkdtemp()
 
37
            self.old_site = site.USER_SITE
 
38
            site.USER_SITE = upload_docs.USER_SITE = tempfile.mkdtemp()
 
39
    
 
40
    def tearDown(self):
 
41
        os.chdir(self.old_cwd)
 
42
        shutil.rmtree(self.dir)
 
43
        if sys.version >= "2.6":
 
44
            shutil.rmtree(site.USER_BASE)
 
45
            shutil.rmtree(site.USER_SITE)
 
46
            site.USER_BASE = self.old_base
 
47
            site.USER_SITE = self.old_site
 
48
 
 
49
    def test_create_zipfile(self):
 
50
        # Test to make sure zipfile creation handles common cases.
 
51
        # This explicitly includes a folder containing an empty folder.
 
52
        
 
53
        dist = Distribution()
 
54
        
 
55
        cmd = upload_docs(dist)
 
56
        cmd.upload_dir = self.upload_dir
 
57
        zip_file = cmd.create_zipfile()
 
58
        
 
59
        assert zipfile.is_zipfile(zip_file)
 
60
        
 
61
        zip_f = zipfile.ZipFile(zip_file) # woh...
 
62
        
 
63
        assert zip_f.namelist() == ['index.html']
 
64
        
 
65