blob: 6b3b4c82ce5be48525ffaf4e36b20084fbdfe397 [file] [log] [blame]
Tarek Ziadébaf51802009-03-31 21:37:16 +00001"""Tests for distutils.command.install_data."""
2import sys
3import os
4import unittest
5import getpass
6
7from distutils.command.install_data import install_data
8from distutils.tests import support
Éric Araujo70ec44a2010-11-06 02:44:43 +00009from test.support import run_unittest
Tarek Ziadébaf51802009-03-31 21:37:16 +000010
11class InstallDataTestCase(support.TempdirManager,
12 support.LoggingSilencer,
Tarek Ziadé430fb632009-10-18 11:34:51 +000013 support.EnvironGuard,
Tarek Ziadébaf51802009-03-31 21:37:16 +000014 unittest.TestCase):
15
16 def test_simple_run(self):
17 pkg_dir, dist = self.create_dist()
18 cmd = install_data(dist)
19 cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
20
21 # data_files can contain
22 # - simple files
23 # - a tuple with a path, and a list of file
24 one = os.path.join(pkg_dir, 'one')
25 self.write_file(one, 'xxx')
26 inst2 = os.path.join(pkg_dir, 'inst2')
27 two = os.path.join(pkg_dir, 'two')
28 self.write_file(two, 'xxx')
29
30 cmd.data_files = [one, (inst2, [two])]
31 self.assertEquals(cmd.get_inputs(), [one, (inst2, [two])])
32
33 # let's run the command
34 cmd.ensure_finalized()
35 cmd.run()
36
37 # let's check the result
38 self.assertEquals(len(cmd.get_outputs()), 2)
39 rtwo = os.path.split(two)[-1]
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000040 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000041 rone = os.path.split(one)[-1]
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000042 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000043 cmd.outfiles = []
44
45 # let's try with warn_dir one
46 cmd.warn_dir = 1
47 cmd.ensure_finalized()
48 cmd.run()
49
50 # let's check the result
51 self.assertEquals(len(cmd.get_outputs()), 2)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000052 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
53 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000054 cmd.outfiles = []
55
56 # now using root and empty dir
57 cmd.root = os.path.join(pkg_dir, 'root')
58 inst3 = os.path.join(cmd.install_dir, 'inst3')
59 inst4 = os.path.join(pkg_dir, 'inst4')
60 three = os.path.join(cmd.install_dir, 'three')
61 self.write_file(three, 'xx')
62 cmd.data_files = [one, (inst2, [two]),
63 ('inst3', [three]),
64 (inst4, [])]
65 cmd.ensure_finalized()
66 cmd.run()
67
68 # let's check the result
69 self.assertEquals(len(cmd.get_outputs()), 4)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000070 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
71 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000072
73def test_suite():
74 return unittest.makeSuite(InstallDataTestCase)
75
76if __name__ == "__main__":
Éric Araujo70ec44a2010-11-06 02:44:43 +000077 run_unittest(test_suite())