[webkit-reviews] review granted: [Bug 215712] [webkitcorepy] Standard Popen mocking API : [Attachment 407317] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Aug 26 12:33:06 PDT 2020


dewei_zhu at apple.com has granted  review:
Bug 215712: [webkitcorepy] Standard Popen mocking API
https://bugs.webkit.org/show_bug.cgi?id=215712

Attachment 407317: Patch

https://bugs.webkit.org/attachment.cgi?id=407317&action=review




--- Comment #11 from dewei_zhu at apple.com ---
Comment on attachment 407317
  --> https://bugs.webkit.org/attachment.cgi?id=407317
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=407317&action=review

> Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/popen.py:237
> +    @property
> +    def universal_newlines(self):
> +	   return self.text_mode
> +
> +    @universal_newlines.setter
> +    def universal_newlines(self, universal_newlines):
> +	   self.text_mode = bool(universal_newlines)
> +
> +    def poll(self):
> +	   if not self._completion:
> +	       self.stdin.seek(0)
> +	       self._completion = Subprocess.completion_for(*self._args,
cwd=self._cwd, input=self.stdin.read())
> +
> +	       (self.stdout or
sys.stdout).write(string_utils.decode(self._completion.stdout,
target_type=self._stdout_type))
> +	       (self.stdout or sys.stdout).flush()
> +
> +	       (self.stderr or
sys.stderr).write(string_utils.decode(self._completion.stderr,
target_type=self._stderr_type))
> +	       (self.stderr or sys.stderr).flush()
> +
> +	   if self.returncode is not None and time.time() >= self._start_time +
self._completion.elapsed:
> +	       self.returncode = self._completion.returncode
> +	       if self.stdout:
> +		   self.stdout.seek(0)
> +	       if self.stderr:
> +		   self.stderr.seek(0)
> +
> +	   return self.returncode
> +
> +    def send_signal(self, sig):
> +	   if self.returncode is not None:
> +	       return
> +
> +	   if sig not in [signal.SIGTERM, signal.SIGKILL]:
> +	       raise ValueError('Mock Popen object cannot handle signal
{}'.format(sig))
> +	   log.critical('Mock process {} send signal {}'.format(self.pid, sig))
> +	   self.returncode = -1
> +
> +    def terminate(self):
> +	   self.send_signal(signal.SIGTERM)
> +
> +    def kill(self):
> +	   self.send_signal(signal.SIGKILL)

Those might fit better on the base class?


More information about the webkit-reviews mailing list