From 8cc1a68d733762ad6baaec439360a84ab8450d3a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 14 Oct 2020 09:24:24 +0300 Subject: chore: get global symbols via global() This lets the module be linted on its own, without the extra-Pythonic knowledge that they'll be available when this module is embedded into the test program. --- subplot/daemon.py | 3 +++ subplot/ewww.py | 10 ++++++---- subplot/http.py | 16 +++++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/subplot/daemon.py b/subplot/daemon.py index 585fe5a..c454b9b 100644 --- a/subplot/daemon.py +++ b/subplot/daemon.py @@ -9,6 +9,9 @@ import signal # Start a process in the background. def start_daemon(ctx, name, argv): + runcmd = globals()["runcmd"] + exit_code_is = globals()["exit_code_is"] + logging.debug(f"Starting daemon {name}") logging.debug(f" ctx={ctx.as_dict()}") logging.debug(f" name={name}") diff --git a/subplot/ewww.py b/subplot/ewww.py index 9282d64..43e5946 100644 --- a/subplot/ewww.py +++ b/subplot/ewww.py @@ -1,15 +1,11 @@ ############################################################################# # Some helpers to make step functions simpler. -import json import logging import os import random -import re import shutil -import signal import socket -import subprocess import time import urllib.parse @@ -18,6 +14,7 @@ import yaml # Name of Rust binary, debug-build. def _binary(name): + srcdir = globals()["srcdir"] return os.path.abspath(os.path.join(srcdir, "target", "debug", name)) @@ -56,6 +53,7 @@ def create_file(ctx, filename=None, content=None): # Copy test certificate from source tree, where it's been created previously by # ./check. def copy_test_certificate(ctx, cert=None, key=None): + srcdir = globals()["srcdir"] logging.debug(f"Copying test.pem, test.key from srcdir to {cert} and {key}") shutil.copy(os.path.join(srcdir, "test.pem"), cert) shutil.copy(os.path.join(srcdir, "test.key"), key) @@ -63,6 +61,8 @@ def copy_test_certificate(ctx, cert=None, key=None): # Start server using named configuration file. def start_server(ctx, filename=None): + get_file = globals()["get_file"] + start_daemon = globals()["start_daemon"] logging.debug(f"Starting ewww with config file {filename}") config = get_file(filename).decode("UTF-8") config = yaml.safe_load(config) @@ -95,12 +95,14 @@ def port_open(host, port, timeout): # Stop previously started server. def stop_server(ctx): + stop_daemon = globals()["stop_daemon"] logging.debug("Stopping ewww") stop_daemon(ctx, "ewww") # Make an HTTP request. def request(ctx, method=None, url=None): + http_request = globals()["http_request"] logging.debug(f"Making HTTP request to ewww: {method} {url}") url, host = _url(ctx, url) http_request(ctx, host=host, method=method, url=url) diff --git a/subplot/http.py b/subplot/http.py index 5cff887..424b2b1 100644 --- a/subplot/http.py +++ b/subplot/http.py @@ -1,22 +1,13 @@ ############################################################################# # Some helpers to make HTTP requests and examine responses -import json import logging -import os -import random -import re -import shutil -import signal -import subprocess -import time -import urllib.parse - -import yaml # Make an HTTP request. def http_request(ctx, host=None, method=None, url=None): + runcmd = globals()["runcmd"] + exit_code_is = globals()["exit_code_is"] logging.debug(f"Make HTTP request: {method} {url}") runcmd(ctx, ["curl", "-ksv", "-X", method, f"-HHost: {host}", url]) exit_code_is(ctx, 0) @@ -24,6 +15,7 @@ def http_request(ctx, host=None, method=None, url=None): # Check status code of latest HTTP request. def http_status_code_is(ctx, code=None): + assert_eq = globals()["assert_eq"] logging.debug(f"Verifying status code of previous HTTP request is {code}") logging.debug(f" stderr={ctx['stderr']}") pattern = f"\n< HTTP/2 {code} " @@ -32,6 +24,7 @@ def http_status_code_is(ctx, code=None): # Check a HTTP response header for latest request has a given value. def http_header_is(ctx, header=None, value=None): + assert_eq = globals()["assert_eq"] logging.debug(f"Verifying response has header {header}: {value}") s = ctx["stderr"] pattern = f"\n< {header}: {value}" @@ -40,6 +33,7 @@ def http_header_is(ctx, header=None, value=None): # Check a HTTP body response for latest request has a given value. def http_body_is(ctx, body=None): + assert_eq = globals()["assert_eq"] logging.debug(f"Verifying response body is {body!r}") logging.debug(f" actual body={ctx['stdout']!r}") s = ctx["stdout"] -- cgit v1.2.1