def start_service_subprocess(self): # Make sure this plugin is exposed to the subprocess # SLOOWWW (~2 seconds, which is why we are doing the work anyway) fd, tempname = tempfile.mkstemp(prefix='tmp-log-bzr-lp-forking-') # I'm not 100% sure about when cleanup runs versus addDetail, but I # think this will work. self.addCleanup(os.remove, tempname) def read_log(): f = os.fdopen(fd) f.seek(0) content = f.read() f.close() return [content] self.addDetail('server-log', content.Content( content.ContentType('text', 'plain', {"charset": "utf8"}), read_log)) service_fd, path = tempfile.mkstemp(prefix='tmp-lp-service-', suffix='.sock') os.close(service_fd) # The service wants to create this file as a socket. os.remove(path) env_changes = { 'BZR_PLUGIN_PATH': lpserve.__path__[0], 'BZR_LOG': tempname, } proc = self._start_subprocess(path, env_changes) return proc, path
def __init__(self, options): if subunit is None: raise Exception("Requires subunit 0.0.5 or better") if content is None: raise Exception("Requires testtools 0.9.2 or better") self.options = options self._stream = sys.stdout self._subunit = subunit.TestProtocolClient(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 = content.ContentType( 'text', 'x-traceback', dict(language='python', charset='utf8')) self.PROFILE_CONTENT_TYPE = content.ContentType( 'application', 'x-binary-profile') self.PLAIN_TEXT = content.ContentType('text', 'plain', {'charset': 'utf8'})
def check_forbidden_modules(self, err, forbidden_imports): """Check for forbidden modules in stderr. :param err: Standard error :param forbidden_imports: List of forbidden modules """ self.addDetail('subprocess_stderr', content.Content(content.ContentType("text", "plain"), lambda:[err])) bad_modules = [] for module_name in forbidden_imports: if err.find("\nimport %s " % module_name) != -1: bad_modules.append(module_name) if bad_modules: self.fail("command loaded forbidden modules %r" % (bad_modules,))
def _add_reason(self, reason): self.addDetail('reason', content.Content( content.ContentType('text', 'plain'), lambda: [reason.encode('utf8')]))
def get_content(self): return content.Content( content.ContentType("text", "foo"), lambda: ['foo'])