Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 1 | """Tests for packaging.command.install_scripts.""" |
| 2 | import os |
| 3 | |
| 4 | from packaging.tests import unittest, support |
| 5 | from packaging.command.install_scripts import install_scripts |
| 6 | from packaging.dist import Distribution |
| 7 | |
| 8 | |
| 9 | class InstallScriptsTestCase(support.TempdirManager, |
| 10 | support.LoggingCatcher, |
| 11 | unittest.TestCase): |
| 12 | |
| 13 | def test_default_settings(self): |
| 14 | dist = Distribution() |
| 15 | dist.command_obj["build"] = support.DummyCommand( |
| 16 | build_scripts="/foo/bar") |
| 17 | dist.command_obj["install_dist"] = support.DummyCommand( |
| 18 | install_scripts="/splat/funk", |
| 19 | force=True, |
| 20 | skip_build=True, |
| 21 | ) |
| 22 | cmd = install_scripts(dist) |
| 23 | self.assertFalse(cmd.force) |
| 24 | self.assertFalse(cmd.skip_build) |
| 25 | self.assertIs(cmd.build_dir, None) |
| 26 | self.assertIs(cmd.install_dir, None) |
| 27 | |
| 28 | cmd.finalize_options() |
| 29 | |
| 30 | self.assertTrue(cmd.force) |
| 31 | self.assertTrue(cmd.skip_build) |
| 32 | self.assertEqual(cmd.build_dir, "/foo/bar") |
| 33 | self.assertEqual(cmd.install_dir, "/splat/funk") |
| 34 | |
| 35 | def test_installation(self): |
| 36 | source = self.mkdtemp() |
| 37 | expected = [] |
| 38 | |
| 39 | def write_script(name, text): |
| 40 | expected.append(name) |
Victor Stinner | 21a9c74 | 2011-05-19 15:51:27 +0200 | [diff] [blame] | 41 | with open(os.path.join(source, name), "w") as f: |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 42 | f.write(text) |
Tarek Ziade | 1231a4e | 2011-05-19 13:07:25 +0200 | [diff] [blame] | 43 | |
| 44 | write_script("script1.py", ("#! /usr/bin/env python2.3\n" |
| 45 | "# bogus script w/ Python sh-bang\n" |
| 46 | "pass\n")) |
| 47 | write_script("script2.py", ("#!/usr/bin/python\n" |
| 48 | "# bogus script w/ Python sh-bang\n" |
| 49 | "pass\n")) |
| 50 | write_script("shell.sh", ("#!/bin/sh\n" |
| 51 | "# bogus shell script w/ sh-bang\n" |
| 52 | "exit 0\n")) |
| 53 | |
| 54 | target = self.mkdtemp() |
| 55 | dist = Distribution() |
| 56 | dist.command_obj["build"] = support.DummyCommand(build_scripts=source) |
| 57 | dist.command_obj["install_dist"] = support.DummyCommand( |
| 58 | install_scripts=target, |
| 59 | force=True, |
| 60 | skip_build=True, |
| 61 | ) |
| 62 | cmd = install_scripts(dist) |
| 63 | cmd.finalize_options() |
| 64 | cmd.run() |
| 65 | |
| 66 | installed = os.listdir(target) |
| 67 | for name in expected: |
| 68 | self.assertIn(name, installed) |
| 69 | |
| 70 | |
| 71 | def test_suite(): |
| 72 | return unittest.makeSuite(InstallScriptsTestCase) |
| 73 | |
| 74 | if __name__ == "__main__": |
| 75 | unittest.main(defaultTest="test_suite") |