Debian Codegraph @

lib-python/3/distutils/tests/test_install_data.py

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