Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profusion-mobi.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FVsSzq9dkE9kcDdp9wBnNGihZxYOqCzEO3ZBu30zH10=; b=yxZKOwHm/equd/3MWW1oFaTfpqYp1kTcoJCWuWUJUb4jUXKEqJlQ0p83dVMPBtcAu+ 2EZAGik9t56n0ag7JcToku0RIBODTokR7r25z7MiTl3iocc03A0yu1m2YajHUaMHLISE Yz6c4Yan56UjJGDagmxZlbqhGh7jo/lkb3NYSEQMqKdxmPDL/mQdi+K7AiPYbXDNtXzk 4oXqV/7XFH6O5fySwv8WljfiyOegHW6R0T3qWOAD8b43pedbXKRJG26G+W0dHKgBteiQ roJ/H87c5xd0ZIk+KfSY3NjWEa2BzVM8DTgJ6R8uRKkbBLNtOHegLrsnCd8Q0vJQxBqW 0mtA== From: Guilherme Campos Camargo Date: Tue, 3 Apr 2018 14:56:49 -0300 Message-Id: <20180403175653.5458-5-guicc@profusion.mobi> In-Reply-To: <20180403175653.5458-1-guicc@profusion.mobi> References: <20180403175653.5458-1-guicc@profusion.mobi> Subject: [Fuego] [PATCH 4/8] Replace single-quote with double-quotes on long strings List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Use double-quotes to avoid having to scape single-quotes and apostrophes. All long strings, that represent something that's human readable has also been surrounded with double-quotes for consistency. Short strings that are only used internally on the code (dictionary keys and commands for example, are kept with single-quotes. Signed-off-by: Guilherme Campos Camargo --- .../Functional.fuego_release_test/test_run.py | 130 ++++++++++----------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/engine/tests/Functional.fuego_release_test/test_run.py b/engine/tests/Functional.fuego_release_test/test_run.py index cdf735d..1b4b62e 100755 --- a/engine/tests/Functional.fuego_release_test/test_run.py +++ b/engine/tests/Functional.fuego_release_test/test_run.py @@ -19,21 +19,21 @@ import selenium.common.exceptions as selenium_exceptions LOGGER = logging.getLogger('test_run') STREAM_HANDLER = logging.StreamHandler() STREAM_HANDLER.setFormatter( - logging.Formatter('%(name)s:%(levelname)s: %(message)s')) + logging.Formatter("%(name)s:%(levelname)s: %(message)s")) LOGGER.setLevel(logging.DEBUG) LOGGER.addHandler(STREAM_HANDLER) def loop_until_timeout(func, timeout=10, num_tries=5): - LOGGER.debug('Running %s()', func.__name__) + LOGGER.debug("Running %s()", func.__name__) for _ in range(num_tries): - LOGGER.debug(' Try number %s...', _ + 1) + LOGGER.debug(" Try number %s...", _ + 1) if func(): - LOGGER.debug(' Success') + LOGGER.debug(" Success") return True time.sleep(timeout/num_tries) - LOGGER.debug(' Failure') + LOGGER.debug(" Failure") return False @@ -42,7 +42,7 @@ class SeleniumCommand: def exec(self, selenium_ctx): self.driver = selenium_ctx.driver self.driver.refresh() - LOGGER.debug('Executing Selenium Command \'%s\'', + LOGGER.debug("Executing Selenium Command '%s'", self.__class__.__name__) @staticmethod @@ -50,28 +50,28 @@ class SeleniumCommand: try: if text in element.text: LOGGER.\ - debug(' Text \'%s\' matches element.text \'%s\'', + debug(" Text '%s' matches element.text '%s'", text, element.text) return True else: LOGGER.\ - debug(' Text \'%s\' does not match element.text \'%s\'', + debug(" Text '%s' does not match element.text '%s'", text, element.text) return False except (selenium_exceptions.ElementNotVisibleException, selenium_exceptions.NoSuchAttributeException,): - LOGGER.error(' Element has no visible Text') + LOGGER.error(" Element has no visible Text") return False @staticmethod def click_element(element): try: element.click() - LOGGER.debug(' Element clicked') + LOGGER.debug(" Element clicked") return True except (selenium_exceptions.ElementClickInterceptedException, selenium_exceptions.ElementNotVisibleException,): - LOGGER.error(' Element is not clickable') + LOGGER.error(" Element is not clickable") return False @staticmethod @@ -79,10 +79,10 @@ class SeleniumCommand: try: element = context.driver.find_element(locator, pattern) except selenium_exceptions.NoSuchElementException: - LOGGER.error(' Element not found') + LOGGER.error(" Element not found") return None - LOGGER.debug(' Element found') + LOGGER.debug(" Element found") return element @@ -95,16 +95,16 @@ class Visit(SeleniumCommand): def exec(self, selenium_ctx): super().exec(selenium_ctx) - LOGGER.debug(' Visiting \'%s\'', self.url) + LOGGER.debug(" Visiting '%s'", self.url) self.driver.get(self.url) r = requests.get(self.url) if r.status_code != self.expected_result: - LOGGER.debug(' HTTP Status Code \'%s\' is different ' - 'from the expected \'%s\'', r.status_cod, self.url) + LOGGER.debug(" HTTP Status Code '%s' is different " + "from the expected '%s'", r.status_cod, self.url) return False - LOGGER.debug(' HTTP Status Code is same as expected \'%s\'', + LOGGER.debug(" HTTP Status Code is same as expected '%s'", r.status_code) return True @@ -147,7 +147,7 @@ class Back(SeleniumCommand): def exec(self, selenium_ctx): super().exec(selenium_ctx) - LOGGER.debug(' Going back') + LOGGER.debug(" Going back") self.driver.back() return True @@ -170,7 +170,7 @@ class ShExpect(): def exec(self, pexpect_ctx): self.client = pexpect_ctx.client - LOGGER.debug('Executing command \'%s\'', self.cmd) + LOGGER.debug("Executing command '%s'", self.cmd) try: self.client.sendline('{}=$({} 2>&1)'.format( self.OUTPUT_VARIABLE, self.cmd)) @@ -188,22 +188,22 @@ class ShExpect(): out = self.client.match.group(1) if result != self.expected_result: - LOGGER.error('The command \'%s\' returned the code \'%d\', ' - 'but the expected code is \'%d\'' - '\nCommand output: \'%s\'', + LOGGER.error("The command '%s' returned the code '%d', " + "but the expected code is '%d'" + "\nCommand output: '%s'", self.cmd, result, self.expected_result, out) return False if self.expected_output is not None and \ re.search(self.expected_output, out) is None: - LOGGER.error('Wrong output for command \'%s\'. ' - 'Expected \'%s\'\nReceived \'%s\'', + LOGGER.error("Wrong output for command '%s'. " + "Expected '%s'\nReceived '%s'", self.cmd, self.expected_output, out) return False except pexpect.exceptions.TIMEOUT: - LOGGER.error('Timeout for command \'%s\'', self.cmd) + LOGGER.error("Timeout for command '%s'", self.cmd) return False except pexpect.exceptions.EOF: - LOGGER.error('Lost connection with docker. Aborting') + LOGGER.error("Lost connection with docker. Aborting") return False return True @@ -220,10 +220,10 @@ class FuegoContainer: def __del__(self): if self.container: if self.rm_after_test: - LOGGER.debug('Removing Container') + LOGGER.debug("Removing Container") self.container.remove(force=True) else: - LOGGER.debug('Not Removing the test container') + LOGGER.debug("Not Removing the test container") def install(self): self.docker_client = docker.APIClient() @@ -254,25 +254,25 @@ class FuegoContainer: inspect_container(container_id)['Mounts'] for mount in mounts: - LOGGER.debug(' Trying to find %s mountpoint in the host', + LOGGER.debug(" Trying to find '%s' mountpoint in the host", mount['source']) for host_mount in host_mounts: if mount['source'].startswith(host_mount['Destination']): mount['source'] = mount['source'].\ replace(host_mount['Destination'], host_mount['Source'], 1) - LOGGER.debug(' Found: %s', mount['source']) + LOGGER.debug(" Found: '%s'", mount['source']) break else: - LOGGER.debug(' Not Found') + LOGGER.debug(" Not Found") mount['source'] = None cmd = './{} {}'.format(self.install_script, self.image_name) - LOGGER.debug('Running \'%s\' to install the docker image. ' - 'This may take a while....', cmd) + LOGGER.debug("Running '%s' to install the docker image. " + "This may take a while....", cmd) status = subprocess.call(cmd, shell=True) - LOGGER.debug('Install output code: %s', status) + LOGGER.debug("Install output code: %s", status) if status != 0: return None @@ -282,7 +282,7 @@ class FuegoContainer: all=True, filters={'name': self.container_name}) if containers: LOGGER.debug( - 'Erasing the container \'%s\', so a new one can be created', + "Erasing the container '%s', so a new one can be created", self.container_name) containers[0].remove(force=True) @@ -304,13 +304,13 @@ class FuegoContainer: our_id = this_container_id() if our_id: - LOGGER.debug('Running inside the Docker container %s', our_id) + LOGGER.debug("Running inside the Docker container %s", our_id) map_to_host(mounts, our_id) else: - LOGGER.debug('Not running inside a Docker container') + LOGGER.debug("Not running inside a Docker container") - LOGGER.debug('Creating container with the following mountpoints:') - LOGGER.debug(' %s', mounts) + LOGGER.debug("Creating container with the following mountpoints:") + LOGGER.debug(" %s", mounts) container = docker_client.containers.create( self.image_name, @@ -322,7 +322,7 @@ class FuegoContainer: for m in mounts], name=self.container_name, command='/bin/bash') - LOGGER.debug('Container \'%s\' created', self.container_name) + LOGGER.debug("Container '%s' created", self.container_name) return container def is_running(self): @@ -352,7 +352,7 @@ class FuegoContainer: return False if container_addr is None else True if not loop_until_timeout(fetch_ip, timeout=10): - LOGGER.error('Could not fetch the container IP address') + LOGGER.error("Could not fetch the container IP address") return None return container_addr @@ -375,7 +375,7 @@ class PexpectContainerSession(): def start(self): LOGGER.debug( - 'Starting container \'%s\'', self.container.container_name) + "Starting container '%s'", self.container.container_name) self.client = pexpect.spawnu( '{} {}'.format( self.start_script, self.container.container_name), @@ -408,7 +408,7 @@ class PexpectContainerSession(): status = resp.status conn.close() LOGGER.debug( - ' HTTP Response code: \'%d\' - Jenkins Version: \'%s\'', + " HTTP Response code: '%d' - Jenkins Version: '%s'", status, version) if status == http.client.OK and version is not None: return True @@ -420,12 +420,12 @@ class PexpectContainerSession(): container_addr = self.container.get_ip() if container_addr is None: return False - LOGGER.debug('Trying to reach jenkins at container \'%s\' via ' - 'the container\'s IP \'%s\' at port \'%d\'', + LOGGER.debug("Trying to reach jenkins at container '%s' via " + "the container's IP '%s' at port '%d'", self.container.container_name, container_addr, self.container.jenkins_port) if not loop_until_timeout(ping_jenkins, timeout=60): - LOGGER.error('Could not connect to jenkins') + LOGGER.error("Could not connect to jenkins") return False return True @@ -450,7 +450,7 @@ class SeleniumContainerSession(): self.driver.get(self.root_url) - LOGGER.debug('Started a Selenium Session on %s', self.root_url) + LOGGER.debug("Started a Selenium Session on %s", self.root_url) return True def __del__(self): @@ -467,7 +467,7 @@ def main(): DEFAULT_JENKINS_PORT = 8080 def execute_tests(timeout): - LOGGER.debug('Starting tests') + LOGGER.debug("Starting tests") ctx_mapper = { ShExpect: pexpect_session, @@ -483,51 +483,51 @@ def main(): break if tests_ok: - LOGGER.debug('Tests finished.') + LOGGER.debug("Tests finished.") return tests_ok parser = argparse.ArgumentParser() - parser.add_argument('working_dir', help='The working directory', type=str) + parser.add_argument('working_dir', help="The working directory", type=str) parser.add_argument('-s', '--install-script', - help='The script that will be used to install the ' - 'docker image. Defaults to \'{}\'' + help="The script that will be used to install the " + "docker image. Defaults to '{}'" .format(DEFAULT_INSTALL_SCRIPT), default=DEFAULT_INSTALL_SCRIPT, type=str) parser.add_argument('-a', '--start-script', - help='The script used to start the container. ' - 'Defaults to \'{}\'' + help="The script used to start the container. " + "Defaults to '{}'" .format(DEFAULT_START_SCRIPT), default=DEFAULT_START_SCRIPT, type=str) parser.add_argument('-i', '--image-name', default=DEFAULT_IMAGE_NAME, - help='The image name that should be used. ' - 'Defaults to \'{}\'' + help="The image name that should be used. " + "Defaults to '{}'" .format(DEFAULT_IMAGE_NAME), type=str) parser.add_argument('-c', '--container-name', default=DEFAULT_CONTAINER_NAME, - help='The container name that should be used for the ' - 'test. Defaults to \'{}\'' + help="The container name that should be used for the " + "test. Defaults to '{}'" .format(DEFAULT_CONTAINER_NAME), type=str) - parser.add_argument('-t', '--timeout', help='The timeout value for ' - 'commands. Defaults to {}' + parser.add_argument('-t', '--timeout', help="The timeout value for " + "commands. Defaults to {}" .format(DEFAULT_TIMEOUT), default=DEFAULT_TIMEOUT, type=int) parser.add_argument('-j', '--jenkins-port', - help='The port where the jenkins is running on the ' - 'test container. Defaults to {}' + help="The port where the jenkins is running on the " + "test container. Defaults to {}" .format(DEFAULT_JENKINS_PORT), default=DEFAULT_JENKINS_PORT, type=int) parser.add_argument('--no-rm-container', - help='Do not remove the container after tests are ' - 'complete.', + help="Do not remove the container after tests are " + "complete.", dest='rm_test_container', default=True, action='store_false') args = parser.parse_args() - LOGGER.debug('Changing working dir to \'%s\'', args.working_dir) + LOGGER.debug("Changing working dir to '%s'", args.working_dir) os.chdir(args.working_dir) container = FuegoContainer(args.install_script, args.image_name, -- 2.16.3