added tests to the install_headers command

This commit is contained in:
Tarek Ziadé 2009-03-31 20:55:21 +00:00
parent a961a0444d
commit 899dd1221d
2 changed files with 46 additions and 6 deletions

View File

@ -8,7 +8,8 @@ __revision__ = "$Id$"
from distutils.core import Command
class install_headers (Command):
# XXX force is never used
class install_headers(Command):
description = "install C/C++ header files"
@ -20,18 +21,18 @@ class install_headers (Command):
boolean_options = ['force']
def initialize_options (self):
def initialize_options(self):
self.install_dir = None
self.force = 0
self.outfiles = []
def finalize_options (self):
def finalize_options(self):
self.set_undefined_options('install',
('install_headers', 'install_dir'),
('force', 'force'))
def run (self):
def run(self):
headers = self.distribution.headers
if not headers:
return
@ -41,10 +42,10 @@ class install_headers (Command):
(out, _) = self.copy_file(header, self.install_dir)
self.outfiles.append(out)
def get_inputs (self):
def get_inputs(self):
return self.distribution.headers or []
def get_outputs (self):
def get_outputs(self):
return self.outfiles
# class install_headers

View File

@ -0,0 +1,39 @@
"""Tests for distutils.command.install_headers."""
import sys
import os
import unittest
import getpass
from distutils.command.install_headers import install_headers
from distutils.tests import support
class InstallHeadersTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
def test_simple_run(self):
# we have two headers
header_list = self.mkdtemp()
header1 = os.path.join(header_list, 'header1')
header2 = os.path.join(header_list, 'header2')
self.write_file(header1)
self.write_file(header2)
headers = [header1, header2]
pkg_dir, dist = self.create_dist(headers=headers)
cmd = install_headers(dist)
self.assertEquals(cmd.get_inputs(), headers)
# let's run the command
cmd.install_dir = os.path.join(pkg_dir, 'inst')
cmd.ensure_finalized()
cmd.run()
# let's check the results
self.assertEquals(len(cmd.get_outputs()), 2)
def test_suite():
return unittest.makeSuite(InstallHeadersTestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")