1 | n/a | """Tests for distutils.command.install_data.""" |
---|
2 | n/a | import os |
---|
3 | n/a | import unittest |
---|
4 | n/a | |
---|
5 | n/a | from distutils.command.install_data import install_data |
---|
6 | n/a | from distutils.tests import support |
---|
7 | n/a | from test.support import run_unittest |
---|
8 | n/a | |
---|
9 | n/a | class InstallDataTestCase(support.TempdirManager, |
---|
10 | n/a | support.LoggingSilencer, |
---|
11 | n/a | support.EnvironGuard, |
---|
12 | n/a | unittest.TestCase): |
---|
13 | n/a | |
---|
14 | n/a | def test_simple_run(self): |
---|
15 | n/a | pkg_dir, dist = self.create_dist() |
---|
16 | n/a | cmd = install_data(dist) |
---|
17 | n/a | cmd.install_dir = inst = os.path.join(pkg_dir, 'inst') |
---|
18 | n/a | |
---|
19 | n/a | # data_files can contain |
---|
20 | n/a | # - simple files |
---|
21 | n/a | # - a tuple with a path, and a list of file |
---|
22 | n/a | one = os.path.join(pkg_dir, 'one') |
---|
23 | n/a | self.write_file(one, 'xxx') |
---|
24 | n/a | inst2 = os.path.join(pkg_dir, 'inst2') |
---|
25 | n/a | two = os.path.join(pkg_dir, 'two') |
---|
26 | n/a | self.write_file(two, 'xxx') |
---|
27 | n/a | |
---|
28 | n/a | cmd.data_files = [one, (inst2, [two])] |
---|
29 | n/a | self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])]) |
---|
30 | n/a | |
---|
31 | n/a | # let's run the command |
---|
32 | n/a | cmd.ensure_finalized() |
---|
33 | n/a | cmd.run() |
---|
34 | n/a | |
---|
35 | n/a | # let's check the result |
---|
36 | n/a | self.assertEqual(len(cmd.get_outputs()), 2) |
---|
37 | n/a | rtwo = os.path.split(two)[-1] |
---|
38 | n/a | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
---|
39 | n/a | rone = os.path.split(one)[-1] |
---|
40 | n/a | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
---|
41 | n/a | cmd.outfiles = [] |
---|
42 | n/a | |
---|
43 | n/a | # let's try with warn_dir one |
---|
44 | n/a | cmd.warn_dir = 1 |
---|
45 | n/a | cmd.ensure_finalized() |
---|
46 | n/a | cmd.run() |
---|
47 | n/a | |
---|
48 | n/a | # let's check the result |
---|
49 | n/a | self.assertEqual(len(cmd.get_outputs()), 2) |
---|
50 | n/a | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
---|
51 | n/a | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
---|
52 | n/a | cmd.outfiles = [] |
---|
53 | n/a | |
---|
54 | n/a | # now using root and empty dir |
---|
55 | n/a | cmd.root = os.path.join(pkg_dir, 'root') |
---|
56 | n/a | inst3 = os.path.join(cmd.install_dir, 'inst3') |
---|
57 | n/a | inst4 = os.path.join(pkg_dir, 'inst4') |
---|
58 | n/a | three = os.path.join(cmd.install_dir, 'three') |
---|
59 | n/a | self.write_file(three, 'xx') |
---|
60 | n/a | cmd.data_files = [one, (inst2, [two]), |
---|
61 | n/a | ('inst3', [three]), |
---|
62 | n/a | (inst4, [])] |
---|
63 | n/a | cmd.ensure_finalized() |
---|
64 | n/a | cmd.run() |
---|
65 | n/a | |
---|
66 | n/a | # let's check the result |
---|
67 | n/a | self.assertEqual(len(cmd.get_outputs()), 4) |
---|
68 | n/a | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
---|
69 | n/a | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
---|
70 | n/a | |
---|
71 | n/a | def test_suite(): |
---|
72 | n/a | return unittest.makeSuite(InstallDataTestCase) |
---|
73 | n/a | |
---|
74 | n/a | if __name__ == "__main__": |
---|
75 | n/a | run_unittest(test_suite()) |
---|