Ejemplo n.º 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,)
Ejemplo n.º 2
0
    def test_log_details_handles_binary_data(self):
        fake_details = dict(
            TestBinary=Content(ContentType('image', 'png'), lambda: b'')
        )

        result = testresult.LoggedTestResultDecorator(None)
        result._log_details(0, fake_details)
Ejemplo n.º 3
0
    def __init__(self, options, stream=None):
        if subunit is None:
            raise Exception('Requires subunit 0.0.11 or better')
        if testtools is None:
            raise Exception('Requires testtools 0.9.30 or better')
        self.options = options

        if stream is None:
            stream = sys.stdout
        self._stream = stream
        self._subunit = self._subunit_factory(self._stream)

        # Used to track the last layer that was set up or torn down. Either
        # None or (layer_name, last_touched_time).
        self._last_layer = None
        self.UTC = Utc()
        # Content types used in the output.
        self.TRACEBACK_CONTENT_TYPE = ContentType(
            'text', 'x-traceback', {'language': 'python', 'charset': 'utf8'})
        self.PROFILE_CONTENT_TYPE = ContentType(
            'application', 'x-binary-profile')
        self.PLAIN_TEXT = ContentType('text', 'plain', {'charset': 'utf8'})
Ejemplo n.º 4
0
    def make_content():
        content_obj = content_from_stream(
            stream,
            ContentType('text', 'plain', {'charset': 'iso8859-1'}),
            buffer_now=True)

        # Work around a bug in older testtools where an empty file would result
        # in None being decoded and exploding.
        # See: https://bugs.launchpad.net/autopilot/+bug/1517289
        if list(content_obj.iter_text()) == []:
            _logger.warning('Followed stream is empty.')
            content_obj = safe_text_content('Unable to read file data.')

        test_case.addDetail(content_name, content_obj)
Ejemplo n.º 5
0
    def test_log_details_logs_binary_attachment_details(self):
        fake_test = Mock()
        fake_test.getDetails = lambda: dict(
            TestBinary=Content(ContentType('image', 'png'), lambda: b'')
        )

        result = testresult.LoggedTestResultDecorator(None)
        with patch.object(result, '_log') as p_log:
            result._log_details(0, fake_test)

            p_log.assert_called_once_with(
                0,
                "Binary attachment: \"{name}\" ({type})".format(
                    name="TestBinary",
                    type="image/png"
                )
            )
Ejemplo n.º 6
0
    def test_on_record_progress(self):
        """
        The on_record_progress callback is fired if an interim log detail is
        received.
        """
        records = []

        def callback(repository, record):
            records.append(record)

        record = TestRecord.create("bar", status=None)
        record.details["test.log"] = Content(ContentType("text", "x-log"),
                                             lambda: [b("hello")])

        self.repository.on_record_progress += callback
        self.repository.update_record(record)

        self.assertEqual([record], records)
Ejemplo n.º 7
0
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <http://www.gnu.org/licenses/>.

# Deprecated: Since GLib 2.62, gtester and gtester-report have been deprecated
# in favour of TAP.

import datetime
import optparse
import sys, re, xml.dom.minidom

try:
    import subunit
    from subunit import iso8601
    from testtools.content import Content, ContentType
    mime_utf8 = ContentType('text', 'plain', {'charset': 'utf8'})
except ImportError:
    subunit = None


# xml utilities
def find_child(node, child_name):
    for child in node.childNodes:
        if child.nodeName == child_name:
            return child
    return None


def list_children(node, child_name):
    rlist = []
    for child in node.childNodes: