def test_chroot(self): """Test the preexec function""" cmd = ["python3", "-c", "import sys; print('Failure is always an option'); sys.exit(0)"] # There is no python3 in /tmp so this is expected to fail with self.assertRaises(FileNotFoundError): startProgram(cmd, root="/tmp/")
def test_startProgram(self): cmd = ["python3", "-c", "import os; print(os.environ['LC_ALL'])"] proc = startProgram(cmd, reset_lang=True) (stdout, _stderr) = proc.communicate() self.assertEqual(stdout.strip(), b"C") cmd = ["python3", "-c", "import os; print(os.environ['LORAX_TEST'])"] proc = startProgram(cmd, env_add={"LORAX_TEST": "beefy miracle"}) (stdout, _stderr) = proc.communicate() self.assertEqual(stdout.strip(), b"beefy miracle") cmd = ["python3", "-c", "import os; print('HOME' in os.environ)"] proc = startProgram(cmd, env_prune=["HOME"]) (stdout, _stderr) = proc.communicate() self.assertEqual(stdout.strip(), b"False")
def test_childenv(self): """Test setting a child environmental variable""" setenv("LORAX_CHILD_TEST", "mustard IS progress") cmd = ["python3", "-c", "import os; print(os.environ['LORAX_CHILD_TEST'])"] proc = startProgram(cmd) (stdout, _stderr) = proc.communicate() self.assertEqual(stdout.strip(), b"mustard IS progress")
def test_preexec(self): """Test the preexec function""" cmd = ["python3", "-c", "import sys; print('Failure is always an option'); sys.exit(0)"] # There is no python3 in /tmp so this is expected to fail proc = startProgram(cmd, reset_handlers=True, preexec_fn=lambda: True) (stdout, _stderr) = proc.communicate() self.assertEqual(stdout.strip(), b"Failure is always an option")