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