示例#1
0
 def _kill_process_and_attach_logs(self, process, app_path):
     stdout, stderr, return_code = _kill_process(process)
     self.caseAddDetail('process-return-code (%s)' % app_path,
                        safe_text_content(str(return_code)))
     self.caseAddDetail('process-stdout (%s)' % app_path,
                        safe_text_content(stdout))
     self.caseAddDetail('process-stderr (%s)' % app_path,
                        safe_text_content(stderr))
示例#2
0
 def _tearDownLogging(self):
     root_logger = logging.getLogger()
     self._log_handler.flush()
     self._log_buffer.seek(0)
     self.caseAddDetail('test-log',
                        safe_text_content(self._log_buffer.getvalue()))
     root_logger.removeHandler(self._log_handler)
     self._log_buffer = None
示例#3
0
 def _attach_application_log(self, app_id):
     j = journal.Reader()
     j.log_level(journal.LOG_INFO)
     j.add_match(_SYSTEMD_USER_UNIT=self._get_user_unit_match(app_id))
     log_data = ''
     for i in j:
         log_data += str(i) + '\n'
     if len(log_data) > 0:
         self.caseAddDetail('Application Log (%s)' % app_id,
                            safe_text_content(log_data))
示例#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)
示例#5
0
    def _stop_video_capture(self, test_instance):
        """Stop the video capture. If the test failed, save the resulting
        file."""

        if self._test_passed:
            # SIGABRT terminates the program and removes
            # the specified output file.
            self._capture_process.send_signal(signal.SIGABRT)
            self._capture_process.wait()
        else:
            self._capture_process.terminate()
            self._capture_process.wait()
            if self._capture_process.returncode != 0:
                test_instance.addDetail(
                    'video capture log',
                    safe_text_content(self._capture_process.stdout.read()))
        self._capture_process = None
        self._currently_recording_description = None
示例#6
0
def follow_file(path, test_case, content_name=None):
    """Start monitoring a file.

    Use this convenience function to attach the contents of a file to a test.

    :param path: The path to the file on disk you want to monitor.
    :param test_case: An object that supports attaching details and cleanup
        actions (i.e.- has the ``addDetail`` and ``addCleanup`` methods).
    :param content_name: A name to give this content. If not specified, the
        file path will be used instead.
    """
    try:
        file_obj = io.open(path, mode='rb')
    except IOError as e:
        _logger.error("Could not add content object '%s' due to IO Error: %s",
                      content_name, str(e))
        return safe_text_content('')
    else:
        file_obj.seek(0, io.SEEK_END)
        return follow_stream(file_obj, test_case, content_name
                             or file_obj.name)
示例#7
0
 def test_returns_text_content_object(self):
     example_string = self.getUniqueString()
     content_obj = safe_text_content(example_string)
     self.assertTrue(isinstance(content_obj, Content))
示例#8
0
 def test_raises_TypeError_on_non_texttype(self):
     self.assertThat(lambda: safe_text_content(None), raises(TypeError))