~xubuntu-dev/ubuntu-cdimage/xubuntu-base

« back to all changes in this revision

Viewing changes to lib/cdimage/tests/test_osextras.py

  • Committer: Sean Davis
  • Date: 2018-03-28 10:32:07 UTC
  • mfrom: (1559.1.156 ubuntu-cdimage)
  • Revision ID: smd.seandavis@gmail.com-20180328103207-o6s9d6h0hxxh8eqc
Merge lp:ubuntu-cdimage rev 1715

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
        mock_waitpid.side_effect = waitpid_side_effect
163
163
        self.assertRaises(Completed, osextras.waitpid_retry, -1, 0)
164
164
 
165
 
    def test_run_bounded_runs(self):
166
 
        sentinel = os.path.join(self.temp_dir, "foo")
167
 
        osextras.run_bounded(3600, ["touch", sentinel])
168
 
        self.assertTrue(os.path.exists(sentinel))
169
 
 
170
 
    def test_run_bounded_finite(self):
171
 
        osextras.run_bounded(.1, ["sh", "-c", "while :; do sleep 3600; done"])
172
 
 
173
165
    def test_fetch_empty(self):
174
166
        config = Config(read=False)
175
167
        target = os.path.join(self.temp_dir, "target")
206
198
            ["wget", "-nv", "http://example.org/source", "-O", target],
207
199
            mock_call.call_args[0][0])
208
200
 
209
 
    def test_shell_escape(self):
210
 
        self.assertEqual("foo", osextras.shell_escape("foo"))
211
 
        self.assertEqual("'  '", osextras.shell_escape("  "))
212
 
        self.assertEqual(
213
 
            "'shell'\\''s great'", osextras.shell_escape("shell's great"))
214
 
 
215
201
    def test_read_shell_config(self):
216
202
        os.environ["ONE"] = "one"
217
203
        config_path = os.path.join(self.temp_dir, "config")
225
211
        self.assertEqual("one two three", config_dict["ONE"])
226
212
        self.assertEqual("two", config_dict["TWO"])
227
213
        self.assertNotIn("three", config_dict)
 
214
 
 
215
    def test_pid_exists(self):
 
216
        self.assertTrue(osextras.pid_exists(os.getpid()))
 
217
        esrch = OSError(errno.ESRCH, "No such process")
 
218
        with mock.patch("os.kill", side_effect=esrch):
 
219
            self.assertFalse(osextras.pid_exists(os.getpid()))
 
220
        enoent = OSError(errno.ENOENT, "No such file or directory")
 
221
        with mock.patch("os.kill", side_effect=enoent):
 
222
            self.assertRaises(OSError, osextras.pid_exists, os.getpid())