From b1507c04160665bda7269bc4bcfd0e8c577642e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarek=20Ziad=C3=A9?= Date: Wed, 18 Sep 2019 15:16:57 +0000 Subject: [PATCH] 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 --- .flake8 | 2 +- testing/condprofile/condprof/helpers.py | 57 +++++++++++++++++++ .../condprofile/condprof/scenarii/heavy.py | 4 +- testing/condprofile/condprof/util.py | 55 ------------------ 4 files changed, 61 insertions(+), 57 deletions(-) create mode 100644 testing/condprofile/condprof/helpers.py diff --git a/.flake8 b/.flake8 index 4768a5e41eac..5e784dfea8c3 100644 --- a/.flake8 +++ b/.flake8 @@ -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, diff --git a/testing/condprofile/condprof/helpers.py b/testing/condprofile/condprof/helpers.py new file mode 100644 index 000000000000..674cfc8cf310 --- /dev/null +++ b/testing/condprofile/condprof/helpers.py @@ -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)) diff --git a/testing/condprofile/condprof/scenarii/heavy.py b/testing/condprofile/condprof/scenarii/heavy.py index 98c762720a2d..0aaa2716be08 100644 --- a/testing/condprofile/condprof/scenarii/heavy.py +++ b/testing/condprofile/condprof/scenarii/heavy.py @@ -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: diff --git a/testing/condprofile/condprof/util.py b/testing/condprofile/condprof/util.py index ae9131108497..670156aedf8f 100644 --- a/testing/condprofile/condprof/util.py +++ b/testing/condprofile/condprof/util.py @@ -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