Skip to content

Commit

Permalink
Simplify code converting os.environ to strings (avoiding six) (web-pl…
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip authored May 6, 2021
1 parent a01585a commit ff6a312
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 42 deletions.
5 changes: 2 additions & 3 deletions tools/wptrunner/wptrunner/browsers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
MarionettePrintRefTestExecutor, # noqa: F401
MarionetteWdspecExecutor, # noqa: F401
MarionetteCrashtestExecutor) # noqa: F401
from ..process import cast_env


here = os.path.dirname(__file__)
Expand Down Expand Up @@ -328,7 +327,7 @@ def start(self):
runner = FirefoxRunner(profile=profile,
binary=cmd[0],
cmdargs=cmd[1:],
env=cast_env(env),
env=env,
process_class=ProcessHandler,
process_args={"processOutputLine": [output_handler]})
instance = BrowserInstance(self.logger, runner, marionette_port,
Expand Down Expand Up @@ -683,7 +682,7 @@ def certutil(*args):
cmd = [self.certutil_binary] + list(args)
self.logger.process_output("certutil",
subprocess.check_output(cmd,
env=cast_env(env),
env=env,
stderr=subprocess.STDOUT),
" ".join(cmd))

Expand Down
3 changes: 1 addition & 2 deletions tools/wptrunner/wptrunner/browsers/firefox_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..executors.executormarionette import (MarionetteTestharnessExecutor, # noqa: F401
MarionetteRefTestExecutor, # noqa: F401
MarionetteCrashtestExecutor) # noqa: F401
from ..process import cast_env
from .base import (Browser,
ExecutorBrowser)
from .firefox import (get_timeout_multiplier, # noqa: F401
Expand Down Expand Up @@ -221,7 +220,7 @@ def start(self, **kwargs):
self.runner = FennecEmulatorRunner(app=self.package_name,
profile=self.profile,
cmdargs=cmd[1:],
env=cast_env(env),
env=env,
symbols_path=self.symbols_path,
serial=self.device_serial,
# TODO - choose appropriate log dir
Expand Down
5 changes: 2 additions & 3 deletions tools/wptrunner/wptrunner/browsers/servodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ..executors import executor_kwargs as base_executor_kwargs
from ..executors.executorservodriver import (ServoWebDriverTestharnessExecutor, # noqa: F401
ServoWebDriverRefTestExecutor) # noqa: F401
from ..process import cast_env

here = os.path.dirname(__file__)

Expand Down Expand Up @@ -132,11 +131,11 @@ def start(self, **kwargs):
if not self.debug_info or not self.debug_info.interactive:
self.proc = ProcessHandler(self.command,
processOutputLine=[self.on_output],
env=cast_env(env),
env=env,
storeOutput=False)
self.proc.run()
else:
self.proc = subprocess.Popen(self.command, env=cast_env(env))
self.proc = subprocess.Popen(self.command, env=env)

self.logger.debug("Servo Started")

Expand Down
13 changes: 6 additions & 7 deletions tools/wptrunner/wptrunner/executors/executorservo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
WdspecProtocol)
from .process import ProcessTestExecutor
from ..browsers.base import browser_command
from ..process import cast_env
from ..webdriver_server import ServoDriverServer


Expand Down Expand Up @@ -103,11 +102,11 @@ def do_test(self, test):
self.proc = ProcessHandler(self.command,
processOutputLine=[self.on_output],
onFinish=self.on_finish,
env=cast_env(env),
env=env,
storeOutput=False)
self.proc.run()
else:
self.proc = subprocess.Popen(self.command, env=cast_env(env))
self.proc = subprocess.Popen(self.command, env=env)

try:
timeout = test.timeout * self.timeout_multiplier
Expand Down Expand Up @@ -235,7 +234,7 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
if not self.interactive:
self.proc = ProcessHandler(self.command,
processOutputLine=[self.on_output],
env=cast_env(env))
env=env)


try:
Expand All @@ -247,7 +246,7 @@ def screenshot(self, test, viewport_size, dpi, page_ranges):
raise
else:
self.proc = subprocess.Popen(self.command,
env=cast_env(env))
env=env)
try:
rv = self.proc.wait()
except KeyboardInterrupt:
Expand Down Expand Up @@ -357,11 +356,11 @@ def do_crashtest(self, protocol, url, timeout):

if not self.interactive:
self.proc = ProcessHandler(command,
env=cast_env(env),
env=env,
storeOutput=False)
self.proc.run()
else:
self.proc = subprocess.Popen(command, env=cast_env(env))
self.proc = subprocess.Popen(command, env=env)

self.proc.wait()

Expand Down
8 changes: 0 additions & 8 deletions tools/wptrunner/wptrunner/process.py

This file was deleted.

8 changes: 3 additions & 5 deletions tools/wptrunner/wptrunner/webdriver_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import mozprocess

from .process import cast_env


__all__ = ["SeleniumServer", "ChromeDriverServer", "CWTChromeDriverServer",
"EdgeChromiumDriverServer", "OperaDriverServer", "GeckoDriverServer",
Expand Down Expand Up @@ -57,7 +55,7 @@ def _run(self, block):
self._proc = mozprocess.ProcessHandler(
self._cmd,
processOutputLine=self.on_output,
env=cast_env(self.env),
env=self.env,
storeOutput=False)

self.logger.debug("Starting WebDriver: %s" % ' '.join(self._cmd))
Expand Down Expand Up @@ -189,7 +187,7 @@ def __init__(self, logger, marionette_port=2828, binary="geckodriver",
WebDriverServer.__init__(self, logger, binary,
host=host,
port=port,
env=cast_env(env),
env=env,
args=args)
self.marionette_port = marionette_port

Expand Down Expand Up @@ -218,7 +216,7 @@ def __init__(self, logger, binary="servo", binary_args=None, host="127.0.0.1",
WebDriverServer.__init__(self, logger, binary,
host=host,
port=port,
env=cast_env(env),
env=env,
args=args)
self.binary_args = binary_args

Expand Down
17 changes: 3 additions & 14 deletions tools/wptserve/wptserve/sslutils/openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
CERT_EXPIRY_BUFFER = dict(hours=6)


def _ensure_str(s, encoding):
"""makes sure s is an instance of str, converting with encoding if needed"""
if isinstance(s, str):
return s
return s.decode(encoding)


class OpenSSL(object):
def __init__(self, logger, binary, base_path, conf_path, hosts, duration,
base_conf_path=None):
Expand Down Expand Up @@ -70,14 +63,10 @@ def __call__(self, cmd, *args, **kwargs):
self.cmd += ["-config", self.conf_path]
self.cmd += list(args)

# Copy the environment, converting to plain strings. Win32 StartProcess
# is picky about all the keys/values being str.
env = {}
for k, v in os.environ.items():
env[_ensure_str(k, "utf8")] = _ensure_str(v, "utf8")

# Copy the environment and add OPENSSL_CONF if available.
env = os.environ.copy()
if self.base_conf_path is not None:
env["OPENSSL_CONF"] = _ensure_str(self.base_conf_path, "utf-8")
env["OPENSSL_CONF"] = self.base_conf_path

self.proc = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
env=env)
Expand Down

0 comments on commit ff6a312

Please sign in to comment.