From 498d82b8661c8df6829933749700648945c65b33 Mon Sep 17 00:00:00 2001 From: Donghoon Shin Date: Tue, 9 May 2017 02:27:00 +0900 Subject: [PATCH] Remove pep8 warnings and update descriptions --- litmus/core/manager.py | 5 +- litmus/device/device.py | 28 +++++++--- litmus/device/devicestandalone.py | 7 +-- litmus/helper/gt.py | 18 +++++-- litmus/helper/helper.py | 46 +++++++++------- litmus/helper/tests.py | 75 +++++++++++++------------- litmus/templates/artik10/userscript.py | 1 - litmus/templates/artik5/userscript.py | 1 - tools/litmus | 55 ++++++++++--------- 9 files changed, 137 insertions(+), 99 deletions(-) diff --git a/litmus/core/manager.py b/litmus/core/manager.py index 300e7ce..55236b1 100644 --- a/litmus/core/manager.py +++ b/litmus/core/manager.py @@ -60,7 +60,8 @@ Lightweight test manager for tizen automated testing def __init__(self, *args, **kwargs): """ :param str topology: topology file path - :param str project_path: project path. If this is None then cwd will be used as project path + :param str project_path: project path. If this is None then cwd will \ + be used as project path :param bool verbose: init logger to print all logs """ super(manager, self).__init__() @@ -282,7 +283,7 @@ Lightweight test manager for tizen automated testing os.chdir(self._workingdir) else: workingdir_name = str((hashlib.sha1(str(datetime.now()) - .encode()).hexdigest())) + .encode()).hexdigest())) workspace_path = os.path.join(self._tmpdir, workingdir_name) os.mkdir(workspace_path) os.chdir(workspace_path) diff --git a/litmus/device/device.py b/litmus/device/device.py index f9337d6..400f84d 100644 --- a/litmus/device/device.py +++ b/litmus/device/device.py @@ -35,7 +35,7 @@ from litmus import _path_for_locks_ class device(object): """ Litmus device class. - User can control device in topology by this class methods. + User can control device in topology by these class methods. """ _baudrate = 115200 @@ -130,9 +130,13 @@ class device(object): def on(self, powercut_delay=1): """ - Turn on the device acquired. + Turn on the acquired device. :param float powercut_delay: power-cut delay for cutter + + Example: + >>> dut.on() + """ logging.debug('=================Turn on device {}==================' .format(self.get_name())) @@ -161,9 +165,13 @@ class device(object): def off(self, powercut_delay=1): """ - Trun off the device acquired. + Trun off the acquired device. :param float powercut_delay: power-cut delay for cutter + + Example: + >>> dut.off() + """ logging.debug('=================Turn off device {}=================' .format(self.get_name())) @@ -402,7 +410,8 @@ class device(object): def _screenshot_wayland(self, filename): """docstring for _screenshot_wayland""" # Find all viewable window id - p_winid = '.*(0x[a-zA-Z0-9]{8})\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+(\d+).*\sViewable.*' + p_winid = '.*(0x[a-zA-Z0-9]{8})\s+\d+\s+\d+\s+\d+' \ + '\s+\d+\s+(\d+)\s+(\d+).*\sViewable.*' winids = find_all_pattern(p_winid, self.run_cmd('enlightenment_info -topvwins', timeout=20)) @@ -547,7 +556,8 @@ class device(object): logging.debug(tar_cmd) call(tar_cmd, shell=True, timeout=30) - heimdall_cmd = 'heimdall flash --usbbus {0} --usbdevaddr {1}'.format(busaddr, devaddr) + heimdall_cmd = 'heimdall flash --usbbus {0}' \ + ' --usbdevaddr {1}'.format(busaddr, devaddr) for key, elem in partition_bin_mappings.items(): heimdall_cmd += ' --{}'.format(key) heimdall_cmd += ' {}'.format(elem) @@ -663,7 +673,13 @@ class device(object): pass def sdb_root_on(self): - """docstring for sdb_root_on""" + """ + Set root mode of device + + Example: + >>> dut.sdb_root_on() + + """ logging.debug('=================sdb root on for {}==================' .format(self.get_name())) call('sdb -s {} root on'.format(self.get_id()).split(), timeout=10) diff --git a/litmus/device/devicestandalone.py b/litmus/device/devicestandalone.py index ad1b033..90e0091 100644 --- a/litmus/device/devicestandalone.py +++ b/litmus/device/devicestandalone.py @@ -23,7 +23,7 @@ from litmus.core.util import call class devicestandalone(device): """ Litmus device class. - User can control device in topology by this class methods. + User can control device in topology by these class methods. """ _booting_time = 60 @@ -114,7 +114,8 @@ class devicestandalone(device): :param dict filenames: filename string or dict :param string flasher: external flashing tool name :param float waiting: waiting time to acquire cdc_acm device - :param dict partition_bin_mappings: partition table for device which use heimdall flasher + :param dict partition_bin_mappings: partition table for device which \ + use heimdall flasher Example: >>> dut.flash(['boot.tar.gz','platform.tar.gz']) @@ -135,7 +136,7 @@ class devicestandalone(device): self.run_cmd('reboot -f download', timeout=20) time.sleep(waiting) if flasher == 'lthor': - if self._usbid == None: + if self._usbid is None: busid = self._find_usb_busid() else: busid = self._usbid diff --git a/litmus/helper/gt.py b/litmus/helper/gt.py index a51a13f..4302080 100644 --- a/litmus/helper/gt.py +++ b/litmus/helper/gt.py @@ -60,10 +60,18 @@ class generate_topology_sdb_device(object): p = '.*Microchip Technology.*' try: smartpower_names = ['/dev/{}'.format(s) - for s in check_output('ls /dev | grep hidraw', + for s in check_output('ls /dev ' + '| grep hidraw', shell=True).split() if find_pattern(p, check_output(['cat', - '/sys/class/hidraw/{}/device/uevent'.format(s)]))] + '/sys/' + 'class/' + 'hidraw/' + '{}/' + 'device/' + 'uevent' + .format(s) + ]))] except AttributeError: smartpower_names = [] logging.debug('smart powers : {0}'.format(smartpower_names)) @@ -146,7 +154,8 @@ class generate_topology_sdb_device(object): """docstring for enter_bootloader_prompt""" # create threads for entering bootloader prompt - delay = (5 + (len(self.cleware4s) * 2 * 4 + len(self.smartpowers) * 2 * 2)) * 30 + delay = (5 + (len(self.cleware4s) * 2 * 4 + + len(self.smartpowers) * 2 * 2)) * 30 threads = [] for l in self.uarts: @@ -240,7 +249,8 @@ class generate_topology_sdb_device(object): # recognize device type for l in self.uarts: - logging.debug('[Recognize device type for uart : {}]'.format(l.name)) + logging.debug('[Recognize device type for uart : ' + '{}]'.format(l.name)) cfg = self.recognize_device(config, l) if cfg: cfgs.append(cfg) diff --git a/litmus/helper/helper.py b/litmus/helper/helper.py index 8a965cb..0f54135 100644 --- a/litmus/helper/helper.py +++ b/litmus/helper/helper.py @@ -16,9 +16,12 @@ import re import sys import time +import shutil import logging import requests +import tempfile import urllib.parse +from subprocess import DEVNULL from bs4 import BeautifulSoup from litmus.core.util import find_pattern, find_all_pattern from litmus.core.util import call @@ -26,7 +29,8 @@ from litmus.core.util import call def tizen_snapshot_downloader(url, pattern_bin='tar.gz$', username='', password='', - pattern_version='tizen[a-zA-Z0-9-_.^/]*[0-9]{8}.[0-9]{1,2}', + pattern_version='tizen[a-zA-Z0-9-_.^/]' + '*[0-9]{8}.[0-9]{1,2}', version=None, timeout=10, maxretry=20, @@ -34,19 +38,23 @@ def tizen_snapshot_downloader(url, pattern_bin='tar.gz$', """ Download snapshot images from web server. - :param str url: url for downloading binaries. This has to include 'latest' string - :param str pattern_bin: filename pattern to find correct binary under the url + :param str url: url for downloading binaries. This has to include \ + 'latest' string + :param str pattern_bin: filename pattern to find correct binary \ + under the url :param str username: username to access http server :param str password: password to access http server :param str pattern_version: pattern of tizen snapshot version string - :param str version: specific version string of tizen snapshot what you want to download + :param str version: specific version string of tizen snapshot \ + what you want to download :param float timeout: timeout :param int maxretry: max retry count to attempt the url for downloading :param float waiting_for_retry: delay for each retry Example: >>> from litmus.helper.helper import tizen_snapshot_downloader - >>> tizen_snapshot_downloader(url=\'http://download.tizen.org/snapshots/tizen/tv/latest/images/arm-wayland/tv-wayland-armv7l-odroidu3/\') + >>> tizen_snapshot_downloader( + url='http://download.tizen.org/snapshots/tizen/tv/latest/images/arm-wayland/tv-wayland-armv7l-odroidu3/') [\'tizen-tv_20160516.2_tv-wayland-armv7l-odroidu3.tar.gz\'] :returns list: filenames of downloaded binaries @@ -92,7 +100,8 @@ def tizen_snapshot_downloader(url, pattern_bin='tar.gz$', soup = BeautifulSoup(f.text, 'html.parser') filenames = [] - for l in soup.findAll('a', attrs={'href': re.compile(pattern_bin)}): + for l in soup.findAll('a', + attrs={'href': re.compile(pattern_bin)}): filename = l['href'] fileurl = urllib.parse.urljoin(url, filename) logging.debug(fileurl) @@ -104,18 +113,19 @@ def tizen_snapshot_downloader(url, pattern_bin='tar.gz$', stream=True) total_length = resp.headers.get('Content-Length') - + cs = 1024 * 1024 if total_length is None: f.write(resp.content) else: downloaded_data = 0 total_length = int(total_length) - for download_data in resp.iter_content(chunk_size=1024 * 1024): + for download_data in resp.iter_content(chunk_size=cs): downloaded_data += len(download_data) f.write(download_data) done = int(50 * downloaded_data / total_length) sys.stdout.write('\r[{0}{1}]'.format('#'*done, - ' '*(50-done))) + ' '*(50-done) + )) sys.stdout.flush() logging.debug('') filenames.append(filename) @@ -141,15 +151,11 @@ def tizen_snapshot_downloader(url, pattern_bin='tar.gz$', return filenames -import tempfile -import shutil -from subprocess import DEVNULL - - def install_plugin_from_git(dut, url, branch, script, waiting=5, timeout=180, commitid=None): """ - Clone a git project which include tizen plugins and install the plugins on device. + Clone a git project which include tizen plugins and install the plugins \ + on device. This helper function turn on device and turn off device automatically. :param device dut: device instance @@ -160,7 +166,8 @@ def install_plugin_from_git(dut, url, branch, script, :param float timeout: timeout :param str commitid: commitid which you want to clone - .. note:: You have to configure your open-ssh key if you want to use ssh protocol to clone the git project. + .. note:: You have to configure your open-ssh key if you want to use ssh \ + protocol to clone the git project. Example: >>> from litmus.helper.helper import install_plugin_from_git @@ -188,8 +195,11 @@ def install_plugin_from_git(dut, url, branch, script, call('git --git-dir={0}/.git checkout {1}'.format(tmpdir, commitid), shell=True) - call('find ./{0} -exec perl -pi -e "s/sdb\s+(-d\s+)*(root|shell|push|pull)/sdb -s {1} \\2/g" {{}} \;'.format(tmpdir, dut.get_id()), stderr=DEVNULL, shell=True) - call('find ./{0} -exec perl -pi -e "s/sdb\s+.*reboot.*//g" {{}} \;'.format(tmpdir), stderr=DEVNULL, shell=True) + call('find ./{0} -exec perl -pi -e "s/sdb\s+(-d\s+)*(root|shell|push|pull)' + '/sdb -s {1} \\2/g" {{}} \;'.format(tmpdir, dut.get_id()), + stderr=DEVNULL, shell=True) + call('find ./{0} -exec perl -pi -e "s/sdb\s+.*reboot.*//g"' + ' {{}} \;'.format(tmpdir), stderr=DEVNULL, shell=True) script_path = '/'.join(script.split('/')[:-1]) script_name = script.split('/')[-1] diff --git a/litmus/helper/tests.py b/litmus/helper/tests.py index 24e3531..da41afb 100644 --- a/litmus/helper/tests.py +++ b/litmus/helper/tests.py @@ -16,8 +16,12 @@ import os import re import sys +import time +import queue import logging import subprocess +from threading import Thread +from litmus.core.util import convert_single_item_to_list def add_test_helper(dut, testcases): @@ -36,28 +40,23 @@ def add_test_helper(dut, testcases): tc.yaml example: >>> testcases: - - - name: verify_process_is_running - from: litmus.helper.tests - result_dir : result - plan: - - - name: dbus_is_running - param: dbus - pattern: .*/usr/bin/dbus-daemon.* - - - name: enlightenment_is_running - param: enlightenment - pattern: .*/usr/bin/enlightenment.* - - - name: verify_dmesg - from: litmus.helper.tests - result_dir : result - plan: - - - name: panel_is_alive - param: panel - pattern: .*panel is dead.* + - name: verify_process_is_running + from: litmus.helper.tests + result_dir: result + plan: + - name: dbus_is_running + param: dbus + pattern: .*/usr/bin/dbus-daemon.* + - name: enlightenment_is_running + param: enlightenment + pattern: .*/usr/bin/enlightenment.* + - name: verify_dmesg + from: litmus.helper.tests + result_dir: result + plan: + - name: panel_is_alive + param: panel + pattern: .*panel is dead.* """ @@ -83,14 +82,14 @@ def verify_process_is_running(dut, plan, result_dir): Example: >>> from litmus.helper.tests import verify_process_is_running >>> verify_wifi_is_working(dut, - [{\'name\': \'dbus_is_running\', - \'param\': \'dbus\', - \'pattern\': \'.*/usr/bin/dbus-daemon.*\'}, - {\'name\': \'deviced_is_runing\', - \'param\': \'deviced\', - \'pattern\': \'.*/usr/bin/deviced.*\'}, + [{'name': 'dbus_is_running', + 'param': 'dbus', + 'pattern': '.*/usr/bin/dbus-daemon.*'}, + {'name': 'deviced_is_runing', + 'param': 'deviced', + 'pattern': '.*/usr/bin/deviced.*'}, ], - \'result\') + 'result') """ test_name = 'verify_process_is_running' @@ -131,7 +130,8 @@ def verify_process_is_running(dut, plan, result_dir): def _save_result(result, result_dir): """docstring for _save_result""" - with open(os.path.join(result_dir, 'testresult_process_is_running.xml'), 'w') as f: + with open(os.path.join(result_dir, + 'testresult_process_is_running.xml'), 'w') as f: f.write(result) _save_result(_run(), os.path.abspath(result_dir)) @@ -200,12 +200,6 @@ def verify_dmesg(dut, plan, result_dir): _save_result(_run(), os.path.abspath(result_dir)) -import time -import queue -from threading import Thread -from litmus.core.util import convert_single_item_to_list - - def verify_wifi_is_working(dut, wifi_apname, wifi_password, result_dir): """ Try to connect wifi ap and publish the test result as a xml file. @@ -297,8 +291,10 @@ def verify_wifi_is_working(dut, wifi_apname, wifi_password, result_dir): if wifi_password and wifi_password != '': _write_cmd(wifi_password, 'Connection step finished', - ['Wi-Fi Activation Failed! error : OPERATION_FAILED', - 'Device state changed callback, state : Deactivated', + ['Wi-Fi Activation Failed! error : ' + 'OPERATION_FAILED', + 'Device state changed callback, state : ' + 'Deactivated', 'Operation failed!']) _write_cmd('6', ['Success to get connection state : Connected', @@ -308,7 +304,8 @@ def verify_wifi_is_working(dut, wifi_apname, wifi_password, result_dir): 'Device state changed callback, state : Deactivated', 'Operation failed!', 'Success to get connection state : Disconnected', - 'Connection state changed callback, state : Disconnected, AP name : {}'.format(wifi_apname)]) + 'Connection state changed callback, state : ' + 'Disconnected, AP name : {}'.format(wifi_apname)]) _write_cmd('0', 'exit', None) dict_for_output = {'tc_name': test_name, diff --git a/litmus/templates/artik10/userscript.py b/litmus/templates/artik10/userscript.py index 5b10849..60a1f95 100755 --- a/litmus/templates/artik10/userscript.py +++ b/litmus/templates/artik10/userscript.py @@ -3,7 +3,6 @@ import os from litmus.core.util import load_yaml from litmus.core.manager import manager from litmus.helper.helper import tizen_snapshot_downloader as downloader -from litmus.helper.helper import install_plugin_from_git from litmus.helper.tests import add_test_helper diff --git a/litmus/templates/artik5/userscript.py b/litmus/templates/artik5/userscript.py index fdc8961..523f078 100755 --- a/litmus/templates/artik5/userscript.py +++ b/litmus/templates/artik5/userscript.py @@ -3,7 +3,6 @@ import os from litmus.core.util import load_yaml from litmus.core.manager import manager from litmus.helper.helper import tizen_snapshot_downloader as downloader -from litmus.helper.helper import install_plugin_from_git from litmus.helper.tests import add_test_helper diff --git a/tools/litmus b/tools/litmus index e79b056..6d3bf88 100644 --- a/tools/litmus +++ b/tools/litmus @@ -46,10 +46,11 @@ def subparser(func): def adhoc_parser(parser): """run litmus project which is not imported. - This will run litmus project which is not imported help you to use CI for - testing. If you use seperated worker node of CI for running test project, - just copy project directory to worker node and use this command. If not, - you have to import litmus project on worker node before run it. + This will run litmus test project which is not imported. This command helps + you to use litmus with CI tool for testing. If you use seperated worker + node of CI tool for running test project, just copy project directory to + worker node and use this command. If not, you have to import litmus project + on worker node before running test. Examples: $ litmus adhoc @@ -66,9 +67,9 @@ def adhoc_parser(parser): def mk_parser(parser): """make new litmus project. - This will create a new directory for project and copy default templates. - You can locate more files and test scripts under this project directory - and run it with project name. + This will create new directory for project based on default templates. + You can locate more files and test scripts under new project directory to + customize your test project. Examples: $ litmus mk @@ -83,9 +84,9 @@ def mk_parser(parser): def rm_parser(parser): """remove litmus project. - This will remove both of your litmus project and project directory from - your host. WARNING: You can not recover your test project sources after - run this command. + This will remove both of your litmus project from project list and project + directory from your host file system. + WARNING: You can't recover your test project after run this command. Examples: $ litmus rm @@ -98,12 +99,12 @@ def rm_parser(parser): def run_parser(parser): """run litmus project. - This will run your litmus project. Project entry point is userscript.py in - your project directory. You can pass argument to project with -p option. + This will run your litmus project. Project's entry point is userscript.py + in your project directory. You can pass argument to project with -p option. You can also set working directory with -d option. If you don't set working directory then litmus creates a temporary directory under /tmp and run test on it, and remove it if test has done. Hence you have to use -d option to - keep test result and workspace. + keep test result and test workspace. Examples: $ litmus run @@ -120,8 +121,8 @@ def run_parser(parser): def ls_parser(parser): """list all litmus projects. - This will list all litmus projects on your host. Default project list is - located in ~/.litmus/projects. + This will list all litmus projects on your host. Default project list file + is located at ~/.litmus/projects. Examples: $ litmus ls @@ -135,7 +136,8 @@ def dev_parser(parser): This will list all available test devices in topology configuration. If you want to run test with real device, you have to set up topology - configuration. Default topology file is located in ~/.litmus/topology. + configuration properly before testing. + Default topology file is located at ~/.litmus/topology. Topology file example for standalone_tm1 is: @@ -153,11 +155,14 @@ def dev_parser(parser): def gt_parser(parser): """generate topology configuration. - This is a helper to generate topology configuration for non-standalone - devices. non-standalone device means that device is controlled by external - uart and power supply. xu3 and u3 device types are non-standard device. - This will find proper uart port and power supply node from your system. - Do not run this command if you use standalone type devices. + This is a helper to generate topology configuration automatically + for non-standalone devices. non-standalone device means that device is + controlled by external uart and power supply. + xu3 and u3 device types are non-standard devices. + This will find proper uart port and power supply node for your + non-standalone device from your system and make configurations. + Don't run this command if you use standalone type devices only. This + regenerate topology file then you will lose your configuration. Examples: $ litmus gt @@ -169,9 +174,8 @@ def gt_parser(parser): def cp_parser(parser): """copy litmus project. - This will create new litmus project from existed one. New project has - duplicated project directory from origin project and does not use default - template for project. + This will create new litmus project from existed one. New project duplicate + files from origin project directory. Examples: $ litmus cp @@ -187,7 +191,8 @@ def imp_parser(parser): """import litmus project. This command will import litmus project. Import means that add new project - authored by others into project list on your host. + which authored by others to project list on your host. If you get new test + project from remote git or archive, You can use this command to import it. Examples: $ litmus imp -- 2.34.1