Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 1 | """Tests for distutils.command.install_data.""" |
| 2 | import sys |
| 3 | import os |
| 4 | import unittest |
| 5 | import getpass |
| 6 | |
| 7 | from distutils.command.install_data import install_data |
| 8 | from distutils.tests import support |
| 9 | |
| 10 | class InstallDataTestCase(support.TempdirManager, |
| 11 | support.LoggingSilencer, |
Tarek Ziadé | 430fb63 | 2009-10-18 11:34:51 +0000 | [diff] [blame^] | 12 | support.EnvironGuard, |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 13 | 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 Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 39 | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 40 | rone = os.path.split(one)[-1] |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 41 | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 42 | 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 Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 51 | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
| 52 | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 53 | 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 Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 69 | self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
| 70 | self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
Tarek Ziadé | baf5180 | 2009-03-31 21:37:16 +0000 | [diff] [blame] | 71 | |
| 72 | def test_suite(): |
| 73 | return unittest.makeSuite(InstallDataTestCase) |
| 74 | |
| 75 | if __name__ == "__main__": |
| 76 | unittest.main(defaultTest="test_suite") |