Bug 1494631 [wpt PR 13239] - browser.py code cleanup, a=testonly

Automatic update from web-platform-testsbrowser.py code cleanup

Some code cleanup that was recommended in https://github.com/web-platform-tests/wpt/pull/13185

--

wpt-commits: 7c568fdbd98ccdb92152c14521d3cc8c729a45a2
wpt-pr: 13239
This commit is contained in:
Ahilya Sinha 2018-11-13 13:41:29 +00:00 коммит произвёл moz-wptsync-bot
Родитель 2e7b7afa19
Коммит 620e67c514
2 изменённых файлов: 26 добавлений и 44 удалений

Просмотреть файл

@ -67,22 +67,28 @@ class Firefox(Browser):
platform_ini = "browsers/firefox/platform.ini"
requirements = "requirements_firefox.txt"
def platform_string_geckodriver(self):
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "macos"
}.get(uname[0])
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "macos"
}.get(uname[0])
if platform is None:
application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}
def platform_string_geckodriver(self):
if self.platform is None:
raise ValueError("Unable to construct a valid Geckodriver package name for current platform")
if platform in ("linux", "win"):
if self.platform in ("linux", "win"):
bits = "64" if uname[4] == "x86_64" else "32"
else:
bits = ""
return "%s%s" % (platform, bits)
return "%s%s" % (self.platform, bits)
def install(self, dest=None, channel="nightly"):
"""Install Firefox."""
@ -102,24 +108,14 @@ class Firefox(Browser):
"beta": "latest-beta",
"nightly": "latest"
}
application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}
if channel not in branch:
raise ValueError("Unrecognised release channel: %s" % channel)
from mozdownload import FactoryScraper
import mozinstall
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])
if platform is None:
if self.platform is None:
raise ValueError("Unable to construct a valid Firefox package name for current platform")
if dest is None:
@ -136,10 +132,10 @@ class Firefox(Browser):
try:
mozinstall.install(filename, dest)
except mozinstall.mozinstall.InstallError:
if platform == "mac" and os.path.exists(os.path.join(dest, application_name[channel])):
if self.platform == "macos" and os.path.exists(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app"))):
# mozinstall will fail if nightly is already installed in the venv because
# mac installation uses shutil.copy_tree
mozinstall.uninstall(os.path.join(dest, application_name[channel]))
mozinstall.uninstall(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app")))
mozinstall.install(filename, dest)
else:
raise
@ -150,46 +146,31 @@ class Firefox(Browser):
def find_binary_path(self,path=None, channel="nightly"):
"""Looks for the firefox binary in the virtual environment"""
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])
application_name = {
"stable": "Firefox.app",
"beta": "Firefox.app",
"nightly": "Firefox Nightly.app"
}.get(channel)
if path is None:
#os.getcwd() doesn't include the venv path
path = os.path.join(os.getcwd(), "_venv", "browsers", channel)
binary = None
if platform == "linux":
if self.platform == "linux":
binary = find_executable("firefox", os.path.join(path, "firefox"))
elif platform == "win":
elif self.platform == "win":
import mozinstall
binary = mozinstall.get_binary(path, "firefox")
elif platform == "mac":
binary = find_executable("firefox", os.path.join(path, application_name,
elif self.platform == "macos":
binary = find_executable("firefox", os.path.join(path, self.application_name.get(channel, "Firefox Nightly.app"),
"Contents", "MacOS"))
return binary
def find_binary(self, venv_path=None, channel=None):
def find_binary(self, venv_path=None, channel="nightly"):
if venv_path is None:
venv_path = os.path.join(os.getcwd(), "_venv")
if channel is None:
channel = "nightly"
path = os.path.join(venv_path, "browsers", channel)
binary = self.find_binary_path(path, channel)
if not binary and uname[0] == "Darwin":
if not binary and self.platform == "macos":
macpaths = ["/Applications/Firefox Nightly.app/Contents/MacOS",
os.path.expanduser("~/Applications/Firefox Nightly.app/Contents/MacOS"),
"/Applications/Firefox Developer Edition.app/Contents/MacOS",

Просмотреть файл

@ -179,6 +179,7 @@ class Firefox(BrowserSetup):
def setup_kwargs(self, kwargs):
if kwargs["binary"] is None:
if kwargs["browser_channel"] is None:
kwargs["browser_channel"] = "nightly"
logger.info("No browser channel specified. Running nightly instead.")
binary = self.browser.find_binary(self.venv.path,