Example #1
0
  def testExitStatus(self):
    command = SubprocessCommand(self.__action, ["foo"])

    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "", None)
    self.assertTrue(command.run(context, cStringIO.StringIO()))

    context = MockCommandContext(self.__dir)
    context.subprocess_result = (1, "", None)
    self.assertFalse(command.run(context, cStringIO.StringIO()))

    context = MockCommandContext(self.__dir)
    context.subprocess_result = (-1, "", None)
    self.assertFalse(command.run(context, cStringIO.StringIO()))

    # Redirect exit status.
    command = SubprocessCommand(self.__action, ["foo"],
                                capture_exit_status = self.__artifact)
    self.assertEquals("foo && echo true > filename || echo false > filename\n",
                      _print_command(command))

    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "", None)
    self.assertTrue(command.run(context, cStringIO.StringIO()))
    self.assertEquals("true", self.__dir.read("filename"))

    context = MockCommandContext(self.__dir)
    context.subprocess_result = (1, "", None)
    self.assertTrue(command.run(context, cStringIO.StringIO()))
    self.assertEquals("false", self.__dir.read("filename"))
Example #2
0
    def testExitStatus(self):
        command = SubprocessCommand(self.__action, ["foo"])

        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "", None)
        self.assertTrue(command.run(context, cStringIO.StringIO()))

        context = MockCommandContext(self.__dir)
        context.subprocess_result = (1, "", None)
        self.assertFalse(command.run(context, cStringIO.StringIO()))

        context = MockCommandContext(self.__dir)
        context.subprocess_result = (-1, "", None)
        self.assertFalse(command.run(context, cStringIO.StringIO()))

        # Redirect exit status.
        command = SubprocessCommand(self.__action, ["foo"],
                                    capture_exit_status=self.__artifact)
        self.assertEquals(
            "foo && echo true > filename || echo false > filename\n",
            _print_command(command))

        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "", None)
        self.assertTrue(command.run(context, cStringIO.StringIO()))
        self.assertEquals("true", self.__dir.read("filename"))

        context = MockCommandContext(self.__dir)
        context.subprocess_result = (1, "", None)
        self.assertTrue(command.run(context, cStringIO.StringIO()))
        self.assertEquals("false", self.__dir.read("filename"))
Example #3
0
  def assertFormattedAs(self, args, result, printed = None):
    context = MockCommandContext(self.__dir, diskpath_prefix = "disk/")
    command = SubprocessCommand(self.__action, list(args))
    self.assertTrue(command.run(context, cStringIO.StringIO()))
    self.assertEquals(result, context.subprocess_args)

    if printed is None:
      printed = " ".join(result)
    self.assertEquals(printed + "\n", _print_command(command))
Example #4
0
    def assertFormattedAs(self, args, result, printed=None):
        context = MockCommandContext(self.__dir, diskpath_prefix="disk/")
        command = SubprocessCommand(self.__action, list(args))
        self.assertTrue(command.run(context, cStringIO.StringIO()))
        self.assertEquals(result, context.subprocess_args)

        if printed is None:
            printed = " ".join(result)
        self.assertEquals(printed + "\n", _print_command(command))
Example #5
0
  def testRedirectStreams(self):
    # No redirection.
    command = SubprocessCommand(self.__action, ["foo"])
    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "some text", None)
    log = cStringIO.StringIO()
    self.assertTrue(command.run(context, log))
    self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
    self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.STDOUT)
    self.assertEquals("some text", log.getvalue())
    self.assertEquals("foo\n", _print_command(command))

    # Redirect stdout.
    command = SubprocessCommand(self.__action, ["foo"],
                                capture_stdout = self.__artifact)
    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "some text", "error text")
    log = cStringIO.StringIO()
    self.assertTrue(command.run(context, log))
    self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
    self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
    self.assertEquals("some text", self.__dir.read("filename"))
    self.assertEquals("error text", log.getvalue())
    self.assertEquals("foo > filename\n", _print_command(command))

    # Redirect stderr.
    command = SubprocessCommand(self.__action, ["foo"],
                                capture_stderr = self.__artifact)
    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "some text", "error text")
    log = cStringIO.StringIO()
    self.assertTrue(command.run(context, log))
    # TODO(kenton): Uncomment when bug with writing to log is solved.
    #self.assertTrue(context.subprocess_kwargs["stdout"] is log)
    self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
    self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
    self.assertEquals("some text", log.getvalue())
    self.assertEquals("error text", self.__dir.read("filename"))
    self.assertEquals("foo 2> filename\n", _print_command(command))

    # Redirect both.
    command = SubprocessCommand(self.__action, ["foo"],
                                capture_stdout = self.__artifact,
                                capture_stderr = Artifact("file2", None))
    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "output", "error")
    log = cStringIO.StringIO()
    self.assertTrue(command.run(context, log))
    self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
    self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
    self.assertEquals("output", self.__dir.read("filename"))
    self.assertEquals("error", self.__dir.read("file2"))
    self.assertEquals("foo > filename 2> file2\n", _print_command(command))

    # Redirect both to same destination.
    command = SubprocessCommand(self.__action, ["foo"],
                                capture_stdout = self.__artifact,
                                capture_stderr = self.__artifact)
    context = MockCommandContext(self.__dir)
    context.subprocess_result = (0, "combined text", None)
    log = cStringIO.StringIO()
    self.assertTrue(command.run(context, log))
    self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
    self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.STDOUT)
    self.assertEquals("combined text", self.__dir.read("filename"))
    self.assertEquals("foo > filename 2>&1\n", _print_command(command))
Example #6
0
    def testRedirectStreams(self):
        # No redirection.
        command = SubprocessCommand(self.__action, ["foo"])
        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "some text", None)
        log = cStringIO.StringIO()
        self.assertTrue(command.run(context, log))
        self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
        self.assertTrue(
            context.subprocess_kwargs["stderr"] is subprocess.STDOUT)
        self.assertEquals("some text", log.getvalue())
        self.assertEquals("foo\n", _print_command(command))

        # Redirect stdout.
        command = SubprocessCommand(self.__action, ["foo"],
                                    capture_stdout=self.__artifact)
        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "some text", "error text")
        log = cStringIO.StringIO()
        self.assertTrue(command.run(context, log))
        self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
        self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
        self.assertEquals("some text", self.__dir.read("filename"))
        self.assertEquals("error text", log.getvalue())
        self.assertEquals("foo > filename\n", _print_command(command))

        # Redirect stderr.
        command = SubprocessCommand(self.__action, ["foo"],
                                    capture_stderr=self.__artifact)
        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "some text", "error text")
        log = cStringIO.StringIO()
        self.assertTrue(command.run(context, log))
        # TODO(kenton): Uncomment when bug with writing to log is solved.
        #self.assertTrue(context.subprocess_kwargs["stdout"] is log)
        self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
        self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
        self.assertEquals("some text", log.getvalue())
        self.assertEquals("error text", self.__dir.read("filename"))
        self.assertEquals("foo 2> filename\n", _print_command(command))

        # Redirect both.
        command = SubprocessCommand(self.__action, ["foo"],
                                    capture_stdout=self.__artifact,
                                    capture_stderr=Artifact("file2", None))
        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "output", "error")
        log = cStringIO.StringIO()
        self.assertTrue(command.run(context, log))
        self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
        self.assertTrue(context.subprocess_kwargs["stderr"] is subprocess.PIPE)
        self.assertEquals("output", self.__dir.read("filename"))
        self.assertEquals("error", self.__dir.read("file2"))
        self.assertEquals("foo > filename 2> file2\n", _print_command(command))

        # Redirect both to same destination.
        command = SubprocessCommand(self.__action, ["foo"],
                                    capture_stdout=self.__artifact,
                                    capture_stderr=self.__artifact)
        context = MockCommandContext(self.__dir)
        context.subprocess_result = (0, "combined text", None)
        log = cStringIO.StringIO()
        self.assertTrue(command.run(context, log))
        self.assertTrue(context.subprocess_kwargs["stdout"] is subprocess.PIPE)
        self.assertTrue(
            context.subprocess_kwargs["stderr"] is subprocess.STDOUT)
        self.assertEquals("combined text", self.__dir.read("filename"))
        self.assertEquals("foo > filename 2>&1\n", _print_command(command))