Bug 1581818 - Make sure client.py stays Python 2 compatible r=stephendonner

We need to keep util.py python 2 compatible. The Python 3 helper class
that's used to generate conditioned profiles is moved to its own
module and we're reactivating util.py in flake8

Differential Revision: https://phabricator.services.mozilla.com/D46259

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tarek Ziadé 2019-09-18 15:16:57 +00:00
parent d49f8aea06
commit b1507c0416
4 changed files with 61 additions and 57 deletions

View File

@ -32,7 +32,7 @@ exclude =
testing/condprofile/condprof/runner.py,
testing/condprofile/condprof/scenarii/heavy.py,
testing/condprofile/condprof/scenarii/cold.py,
testing/condprofile/condprof/util.py,
testing/condprofile/condprof/helpers.py,
testing/jsshell/benchmark.py,
testing/marionette/mach_commands.py,
testing/mozharness/docs,

View File

@ -0,0 +1,57 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
""" Helpers to build scenarii
"""
from condprof.util import ERROR
class TabSwitcher:
""" Helper used to create tabs and circulate in them.
"""
def __init__(self, session, options):
self.handles = None
self.current = 0
self.session = session
self._max = options.get("max_urls", 10)
self.platform = options.get("platform", "")
self.num_tabs = self._max >= 100 and 100 or self._max
self._mobile = "fenix" in self.platform or "gecko" in self.platform
async def create_windows(self):
# on mobile we don't use tabs for now
# see https://bugzil.la/1559120
if self._mobile:
return
# creating tabs
for i in range(self.num_tabs):
# see https://github.com/HDE/arsenic/issues/71
await self.session._request(
url="/window/new", method="POST", data={"type": "tab"}
)
async def switch(self):
if self._mobile:
return
try:
if self.handles is None:
self.handles = await self.session.get_window_handles()
self.current = 0
except Exception:
ERROR("Could not get window handles")
return
if self.current not in self.handles:
ERROR("Handle %s not in current set of windows" % str(self.current))
return
handle = self.handles[self.current]
if self.current == len(self.handles) - 1:
self.current = 0
else:
self.current += 1
try:
await self.session.switch_to_window(handle)
except Exception:
ERROR("Could not switch to handle %s" % str(handle))

View File

@ -1,8 +1,10 @@
import random
import os
from condprof.util import get_logger, TabSwitcher
import asyncio
from condprof.util import get_logger
from condprof.helpers import TabSwitcher
WORDS = os.path.join(os.path.dirname(__file__), "words.txt")
with open(WORDS) as f:

View File

@ -303,61 +303,6 @@ def get_current_platform():
return plat + arch
def is_mobile(platform):
return "fenix" in platform or "gecko" in platform
class TabSwitcher(object):
""" Helper used to create tabs and circulate in them.
"""
def __init__(self, session, options):
self.handles = None
self.current = 0
self.session = session
self._max = options.get("max_urls", 10)
self.platform = options.get("platform", "")
self.num_tabs = self._max >= 100 and 100 or self._max
self._mobile = is_mobile(self.platform)
async def create_windows(self):
# on mobile we don't use tabs for now
# see https://bugzil.la/1559120
if self._mobile:
return
# creating tabs
for i in range(self.num_tabs):
# see https://github.com/HDE/arsenic/issues/71
await self.session._request(
url="/window/new", method="POST", data={"type": "tab"}
)
async def switch(self):
if self._mobile:
return
try:
if self.handles is None:
self.handles = await self.session.get_window_handles()
self.current = 0
except Exception:
ERROR("Could not get window handles")
return
if self.current not in self.handles:
ERROR("Handle %s not in current set of windows" % str(self.current))
return
handle = self.handles[self.current]
if self.current == len(self.handles) - 1:
self.current = 0
else:
self.current += 1
try:
await self.session.switch_to_window(handle)
except Exception:
ERROR("Could not switch to handle %s" % str(handle))
class BaseEnv:
def __init__(self, profile, firefox, geckodriver, archive, device_name):
self.profile = profile