Example #1
0
    def publish_installer_images(self, args, expect_error=False, extra_enviroment=None):
        """
        Call ``publish-installer-images`` capturing stdout and stderr.
        """
        working_directory = self.make_temporary_directory()
        environment = os.environ.copy()
        if extra_enviroment is not None:
            environment.update(extra_enviroment)
        # XXX Don't use TMPDIR because it breaks packer
        # https://github.com/mitchellh/packer/issues/2792
        environment["TEMP"] = working_directory.path
        stdout_path = working_directory.child("stdout")
        stderr_path = working_directory.child("stderr")
        self.addDetail("stdout {!r}".format(args), content_from_file(stdout_path.path, ContentType("text", "plain")))
        self.addDetail("stderr {!r}".format(args), content_from_file(stderr_path.path, ContentType("text", "plain")))

        with stdout_path.open("w") as stdout:
            with stderr_path.open("w") as stderr:
                try:
                    return_code = check_call([self.script.path] + args, env=environment, stdout=stdout, stderr=stderr)
                except CalledProcessError as e:
                    self.addDetail("CalledProcessError {!r}".format(args), text_content(str(e)))

                    if expect_error:
                        return_code = e.returncode
                    else:
                        raise

        return (return_code, stdout_path, stderr_path)
Example #2
0
 def test_from_file_eager_loading(self):
     fd, path = tempfile.mkstemp()
     os.write(fd, _b("some data"))
     os.close(fd)
     content = content_from_file(path, UTF8_TEXT, buffer_now=True)
     os.remove(path)
     self.assertThat("".join(content.iter_text()), Equals("some data"))
Example #3
0
 def test_from_file(self):
     fd, path = tempfile.mkstemp()
     self.addCleanup(os.remove, path)
     os.write(fd, _b("some data"))
     os.close(fd)
     content = content_from_file(path, UTF8_TEXT, chunk_size=2)
     self.assertThat(list(content.iter_bytes()), Equals([_b("so"), _b("me"), _b(" d"), _b("at"), _b("a")]))
 def test_from_file(self):
     fd, path = tempfile.mkstemp()
     self.addCleanup(os.remove, path)
     os.write(fd, 'some data')
     os.close(fd)
     content = content_from_file(path, UTF8_TEXT, chunk_size=2)
     self.assertThat(
         list(content.iter_bytes()), Equals(['so', 'me', ' d', 'at', 'a']))
 def test_from_file_eager_loading(self):
     fd, path = tempfile.mkstemp()
     os.write(fd, 'some data')
     os.close(fd)
     content = content_from_file(path, UTF8_TEXT, buffer_now=True)
     os.remove(path)
     self.assertThat(
         _b('').join(content.iter_bytes()), Equals('some data'))
Example #6
0
 def test_from_file_with_whence_seek(self):
     f = tempfile.NamedTemporaryFile()
     f.write(_b('some data'))
     f.flush()
     self.addCleanup(f.close)
     content = content_from_file(
         f.name, UTF8_TEXT, chunk_size=50, seek_offset=-4, seek_whence=2)
     self.assertThat(
         list(content.iter_bytes()), Equals([_b('data')]))
Example #7
0
 def _spawn(self):
     """Spawn the RabbitMQ server process."""
     cmd = os.path.join(RABBITBIN, 'rabbitmq-server')
     env = dict(os.environ, HOME=self.config.homedir)
     with open(self.config.logfile, "wb") as logfile:
         with open(os.devnull, "rb") as devnull:
             self.process = subprocess.Popen(
                 [cmd], stdin=devnull, stdout=logfile, stderr=logfile,
                 close_fds=True, cwd=self.config.homedir, env=env,
                 preexec_fn=preexec_fn)
     self.addDetail(
         os.path.basename(self.config.logfile),
         content_from_file(self.config.logfile))
 def profiler_stats(self, stats):
     """Report profiler stats."""
     fd, filename = tempfile.mkstemp(prefix='zope.testrunner-')
     os.close(fd)
     try:
         stats.dump_stats(filename)
         profile_content = content_from_file(
             filename, content_type=self.PROFILE_CONTENT_TYPE)
         details = {'profiler-stats': profile_content}
         # Name the test 'zope:profiler_stats' just like its tag.
         self._emit_fake_test(
             self.TAG_PROFILER_STATS, self.TAG_PROFILER_STATS, details)
     finally:
         os.unlink(filename)
Example #9
0
 def test_from_file_default_type(self):
     content = content_from_file("/nonexistent/path")
     self.assertThat(content.content_type, Equals(UTF8_TEXT))
Example #10
0
 def test_from_nonexistent_file(self):
     directory = tempfile.mkdtemp()
     nonexistent = os.path.join(directory, "nonexistent-file")
     content = content_from_file(nonexistent)
     self.assertThat(content.iter_bytes, raises(IOError))
Example #11
0
 def addDetailFromLog(self):
     content = content_from_file(self.log_filename, buffer_now=True)
     self.addDetail("log", content)
Example #12
0
 def test_from_nonexistent_file(self):
     directory = tempfile.mkdtemp()
     nonexistent = os.path.join(directory, 'nonexistent-file')
     content = content_from_file(nonexistent)
     self.assertThat(content.iter_bytes, raises(IOError))
Example #13
0
 def test_from_file_default_type(self):
     content = content_from_file('/nonexistent/path')
     self.assertThat(content.content_type, Equals(UTF8_TEXT))