ยปCore Development>Code coverage>Lib/distutils/tests/test_install_data.py

Python code coverage for Lib/distutils/tests/test_install_data.py

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