def test_output_of_failed_command(self): with output_catcher() as (out, err): command = Command("which " + self.INVALID_COMMAND, self.TEST_MSG) command.run() output = out.getvalue().strip() self.assertEquals(self.TEST_MSG + " " + command.NOT_OK, output) self.assertFalse(command.was_successful)
def test_output_of_valid_command(self): with output_catcher() as (out, err): command = Command("echo test", self.TEST_MSG) command.run() output = out.getvalue().strip() self.assertEquals(self.TEST_MSG + " " + command.OK, output) self.assertEquals("test", command.stdout) self.assertTrue(command.was_successful)
def test_output_of_invalid_command(self): msg = "Checking for invalid command." command = Command(self.INVALID_COMMAND, msg) command.run() self.assertFalse(command.was_successful) self.assertEqual( Command.INVALID_COMMAND_ERROR_MSG.format( command=self.INVALID_COMMAND), command.stderr) self.assertEqual("", command.stdout)
def test_required_command_exits_on_failure(self): with self.assertRaises(installer.InstallationFailedException): Command(self.INVALID_COMMAND, "", exit_on_failure=True).run() with self.assertRaises(installer.InstallationFailedException): Command("which " + self.INVALID_COMMAND, "", exit_on_failure=True).run()