mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-07 13:41:24 +00:00
pylint fixes
This commit is contained in:
parent
3782a33060
commit
f57dd83d1a
@ -14,7 +14,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from requests import ConnectionError, RequestException
|
from requests import ConnectionError, RequestException
|
||||||
@ -25,6 +24,7 @@ from wlauto.core.extension import Extension
|
|||||||
|
|
||||||
REMOTE_ASSETS_URL = 'https://github.com/ARM-software/wa-assets/raw/master/dependencies'
|
REMOTE_ASSETS_URL = 'https://github.com/ARM-software/wa-assets/raw/master/dependencies'
|
||||||
|
|
||||||
|
|
||||||
class GetAssetsCommand(Command):
|
class GetAssetsCommand(Command):
|
||||||
name = 'get-assets'
|
name = 'get-assets'
|
||||||
description = '''
|
description = '''
|
||||||
@ -40,14 +40,14 @@ class GetAssetsCommand(Command):
|
|||||||
def initialize(self, context):
|
def initialize(self, context):
|
||||||
self.parser.add_argument('-f', '--force', action='store_true',
|
self.parser.add_argument('-f', '--force', action='store_true',
|
||||||
help='Always fetch the assets, even if matching versions exist in local cache.')
|
help='Always fetch the assets, even if matching versions exist in local cache.')
|
||||||
self.parser.add_argument('--url', metavar='URL', type=self.not_empty, default=self.assets_url,
|
self.parser.add_argument('--url', metavar='URL', type=not_empty, default=self.assets_url,
|
||||||
help='''The location from which to download the files. If not provided,
|
help='''The location from which to download the files. If not provided,
|
||||||
config setting ``remote_assets_url`` will be used if available, else
|
config setting ``remote_assets_url`` will be used if available, else
|
||||||
uses the default REMOTE_ASSETS_URL parameter in the script.''')
|
uses the default REMOTE_ASSETS_URL parameter in the script.''')
|
||||||
group = self.parser.add_mutually_exclusive_group(required=True)
|
group = self.parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument('-a', '--all', action='store_true',
|
group.add_argument('-a', '--all', action='store_true',
|
||||||
help='Download assets for all extensions found in the index. Cannot be used with -e.')
|
help='Download assets for all extensions found in the index. Cannot be used with -e.')
|
||||||
group.add_argument('-e', dest='exts', metavar='EXT', nargs='+', type=self.not_empty,
|
group.add_argument('-e', dest='exts', metavar='EXT', nargs='+', type=not_empty,
|
||||||
help='One or more extensions whose assets to download. Cannot be used with --all.')
|
help='One or more extensions whose assets to download. Cannot be used with --all.')
|
||||||
|
|
||||||
def execute(self, args):
|
def execute(self, args):
|
||||||
@ -100,12 +100,6 @@ class GetAssetsCommand(Command):
|
|||||||
for asset in all_assets[ext_name]:
|
for asset in all_assets[ext_name]:
|
||||||
getter.get(File(owner, asset)) # Download the files
|
getter.get(File(owner, asset)) # Download the files
|
||||||
|
|
||||||
def not_empty(self, val):
|
|
||||||
if val:
|
|
||||||
return val
|
|
||||||
else:
|
|
||||||
raise argparse.ArgumentTypeError('Extension name cannot be blank')
|
|
||||||
|
|
||||||
def exit_with_error(self, message, code=1):
|
def exit_with_error(self, message, code=1):
|
||||||
self.logger.error(message)
|
self.logger.error(message)
|
||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
@ -117,5 +111,12 @@ class NamedExtension(Extension):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
|
def not_empty(val):
|
||||||
|
if val:
|
||||||
|
return val
|
||||||
|
else:
|
||||||
|
raise argparse.ArgumentTypeError('Extension name cannot be blank')
|
||||||
|
|
||||||
|
|
||||||
def _instantiate(cls, *args, **kwargs):
|
def _instantiate(cls, *args, **kwargs):
|
||||||
return cls(*args, **kwargs)
|
return cls(*args, **kwargs)
|
||||||
|
@ -22,12 +22,11 @@ from wlauto.core.extension import Parameter
|
|||||||
from wlauto.core.workload import Workload
|
from wlauto.core.workload import Workload
|
||||||
from wlauto.core.resource import NO_ONE
|
from wlauto.core.resource import NO_ONE
|
||||||
from wlauto.common.android.resources import ApkFile
|
from wlauto.common.android.resources import ApkFile
|
||||||
from wlauto.common.resources import ExtensionAsset, Executable
|
from wlauto.common.resources import ExtensionAsset, Executable, File
|
||||||
from wlauto.exceptions import WorkloadError, ResourceError, ConfigError, DeviceError
|
from wlauto.exceptions import WorkloadError, ResourceError, ConfigError, DeviceError
|
||||||
from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS, UNSUPPORTED_PACKAGES
|
from wlauto.utils.android import ApkInfo, ANDROID_NORMAL_PERMISSIONS, UNSUPPORTED_PACKAGES
|
||||||
from wlauto.utils.types import boolean
|
from wlauto.utils.types import boolean
|
||||||
from wlauto.utils.revent import ReventParser
|
from wlauto.utils.revent import ReventParser
|
||||||
from wlauto import File
|
|
||||||
import wlauto.utils.statedetect as state_detector
|
import wlauto.utils.statedetect as state_detector
|
||||||
import wlauto.common.android.resources
|
import wlauto.common.android.resources
|
||||||
|
|
||||||
@ -346,6 +345,8 @@ class ReventWorkload(Workload):
|
|||||||
self.revent_run_file = None
|
self.revent_run_file = None
|
||||||
self.on_device_setup_revent = None
|
self.on_device_setup_revent = None
|
||||||
self.on_device_run_revent = None
|
self.on_device_run_revent = None
|
||||||
|
self.statedefs_dir = None
|
||||||
|
self.check_states = None
|
||||||
|
|
||||||
def initialize(self, context):
|
def initialize(self, context):
|
||||||
self.revent_setup_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'setup'))
|
self.revent_setup_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'setup'))
|
||||||
@ -419,6 +420,7 @@ class ReventWorkload(Workload):
|
|||||||
msg = "State definitions or template files missing or invalid ({}). Skipping state detection."
|
msg = "State definitions or template files missing or invalid ({}). Skipping state detection."
|
||||||
self.logger.warning(msg.format(e.message))
|
self.logger.warning(msg.format(e.message))
|
||||||
|
|
||||||
|
|
||||||
class AndroidUiAutoBenchmark(UiAutomatorWorkload, AndroidBenchmark):
|
class AndroidUiAutoBenchmark(UiAutomatorWorkload, AndroidBenchmark):
|
||||||
|
|
||||||
supported_platforms = ['android']
|
supported_platforms = ['android']
|
||||||
@ -525,7 +527,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
|
|||||||
ApkWorkload.init_resources(self, context)
|
ApkWorkload.init_resources(self, context)
|
||||||
ReventWorkload.init_resources(self, context)
|
ReventWorkload.init_resources(self, context)
|
||||||
if self.check_states:
|
if self.check_states:
|
||||||
self._check_statedetection_files(self, context)
|
self._check_statedetection_files(context)
|
||||||
|
|
||||||
def setup(self, context):
|
def setup(self, context):
|
||||||
ApkWorkload.setup(self, context)
|
ApkWorkload.setup(self, context)
|
||||||
@ -535,7 +537,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
|
|||||||
|
|
||||||
# state detection check if it's enabled in the config
|
# state detection check if it's enabled in the config
|
||||||
if self.check_states:
|
if self.check_states:
|
||||||
self.check_state(self, context, "setup_complete")
|
self.check_state(context, "setup_complete")
|
||||||
|
|
||||||
def do_post_install(self, context):
|
def do_post_install(self, context):
|
||||||
ApkWorkload.do_post_install(self, context)
|
ApkWorkload.do_post_install(self, context)
|
||||||
@ -558,7 +560,7 @@ class GameWorkload(ApkWorkload, ReventWorkload):
|
|||||||
def teardown(self, context):
|
def teardown(self, context):
|
||||||
# state detection check if it's enabled in the config
|
# state detection check if it's enabled in the config
|
||||||
if self.check_states:
|
if self.check_states:
|
||||||
self.check_state(self, context, "run_complete")
|
self.check_state(context, "run_complete")
|
||||||
|
|
||||||
if not self.saved_state_file:
|
if not self.saved_state_file:
|
||||||
ApkWorkload.teardown(self, context)
|
ApkWorkload.teardown(self, context)
|
||||||
|
@ -42,8 +42,7 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class StateDefinitionError(RuntimeError):
|
class StateDefinitionError(RuntimeError):
|
||||||
def __init__(self, arg):
|
pass
|
||||||
self.args = arg
|
|
||||||
|
|
||||||
|
|
||||||
def auto_canny(image, sigma=0.33):
|
def auto_canny(image, sigma=0.33):
|
||||||
@ -59,9 +58,9 @@ def auto_canny(image, sigma=0.33):
|
|||||||
return edged
|
return edged
|
||||||
|
|
||||||
|
|
||||||
def match_state(screenshot_file, defpath, state_definitions):
|
def match_state(screenshot_file, defpath, state_definitions): # pylint: disable=too-many-locals
|
||||||
# check dependencies
|
# check dependencies
|
||||||
if np == None or cv2 == None or imutils == None:
|
if np is None or cv2 is None or imutils is None:
|
||||||
raise RuntimeError("State detection requires numpy, opencv (cv2) and imutils.")
|
raise RuntimeError("State detection requires numpy, opencv (cv2) and imutils.")
|
||||||
|
|
||||||
# check if file exists, then load screenshot into opencv and create edge map
|
# check if file exists, then load screenshot into opencv and create edge map
|
||||||
@ -78,15 +77,14 @@ def match_state(screenshot_file, defpath, state_definitions):
|
|||||||
|
|
||||||
# check all template PNGs exist
|
# check all template PNGs exist
|
||||||
for template_png in template_list:
|
for template_png in template_list:
|
||||||
if not os.path.isfile(os.path.join(defpath, 'templates', template_png+'.png')):
|
if not os.path.isfile(os.path.join(defpath, 'templates', template_png + '.png')):
|
||||||
raise StateDefinitionError("Missing template PNG file: " + template_png + ".png")
|
raise StateDefinitionError("Missing template PNG file: " + template_png + ".png")
|
||||||
|
|
||||||
# try to match each PNG
|
# try to match each PNG
|
||||||
matched_templates = []
|
matched_templates = []
|
||||||
for template_png in template_list:
|
for template_png in template_list:
|
||||||
template = cv2.imread(os.path.join(defpath, 'templates', template_png+'.png'), 0)
|
template = cv2.imread(os.path.join(defpath, 'templates', template_png + '.png'), 0)
|
||||||
template_edge = auto_canny(template)
|
template_edge = auto_canny(template)
|
||||||
w, h = template.shape[::-1]
|
|
||||||
|
|
||||||
res = cv2.matchTemplate(img_edge, template_edge, cv2.TM_CCOEFF_NORMED)
|
res = cv2.matchTemplate(img_edge, template_edge, cv2.TM_CCOEFF_NORMED)
|
||||||
threshold = 0.5
|
threshold = 0.5
|
||||||
@ -117,7 +115,7 @@ def verify_state(screenshot_file, state_defs_path, workload_phase):
|
|||||||
# load and parse state definition file
|
# load and parse state definition file
|
||||||
statedefs_file = os.path.join(state_defs_path, 'definition.yaml')
|
statedefs_file = os.path.join(state_defs_path, 'definition.yaml')
|
||||||
if not os.path.isfile(statedefs_file):
|
if not os.path.isfile(statedefs_file):
|
||||||
raise StateDefinitionError("Missing state definitions yaml file: "+statedefs_file)
|
raise StateDefinitionError("Missing state definitions yaml file: " + statedefs_file)
|
||||||
with open(statedefs_file) as fh:
|
with open(statedefs_file) as fh:
|
||||||
state_definitions = yaml.load(fh)
|
state_definitions = yaml.load(fh)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user