blob: 377ae86e2f2e5168e8a1ecd32dcaf53f417c0495 [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
9
10class InstallDataTestCase(support.TempdirManager,
11 support.LoggingSilencer,
Tarek Ziadé430fb632009-10-18 11:34:51 +000012 support.EnvironGuard,
Tarek Ziadébaf51802009-03-31 21:37:16 +000013 unittest.TestCase):
14
15 def test_simple_run(self):
16 pkg_dir, dist = self.create_dist()
17 cmd = install_data(dist)
18 cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
19
20 # data_files can contain
21 # - simple files
22 # - a tuple with a path, and a list of file
23 one = os.path.join(pkg_dir, 'one')
24 self.write_file(one, 'xxx')
25 inst2 = os.path.join(pkg_dir, 'inst2')
26 two = os.path.join(pkg_dir, 'two')
27 self.write_file(two, 'xxx')
28
29 cmd.data_files = [one, (inst2, [two])]
30 self.assertEquals(cmd.get_inputs(), [one, (inst2, [two])])
31
32 # let's run the command
33 cmd.ensure_finalized()
34 cmd.run()
35
36 # let's check the result
37 self.assertEquals(len(cmd.get_outputs()), 2)
38 rtwo = os.path.split(two)[-1]
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000039 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000040 rone = os.path.split(one)[-1]
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000041 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000042 cmd.outfiles = []
43
44 # let's try with warn_dir one
45 cmd.warn_dir = 1
46 cmd.ensure_finalized()
47 cmd.run()
48
49 # let's check the result
50 self.assertEquals(len(cmd.get_outputs()), 2)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000051 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
52 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000053 cmd.outfiles = []
54
55 # now using root and empty dir
56 cmd.root = os.path.join(pkg_dir, 'root')
57 inst3 = os.path.join(cmd.install_dir, 'inst3')
58 inst4 = os.path.join(pkg_dir, 'inst4')
59 three = os.path.join(cmd.install_dir, 'three')
60 self.write_file(three, 'xx')
61 cmd.data_files = [one, (inst2, [two]),
62 ('inst3', [three]),
63 (inst4, [])]
64 cmd.ensure_finalized()
65 cmd.run()
66
67 # let's check the result
68 self.assertEquals(len(cmd.get_outputs()), 4)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +000069 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
70 self.assertTrue(os.path.exists(os.path.join(inst, rone)))
Tarek Ziadébaf51802009-03-31 21:37:16 +000071
72def test_suite():
73 return unittest.makeSuite(InstallDataTestCase)
74
75if __name__ == "__main__":
76 unittest.main(defaultTest="test_suite")