booth/SOURCES/0006-test-avoid-dangerous-mutable-sticky-default-value.patch
2021-10-08 09:57:23 +00:00

179 lines
7.0 KiB
Diff

From 34cc2fcda6804d42ee66fa5a417fc42b64fe3806 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
Date: Tue, 10 Jul 2018 19:45:56 +0200
Subject: [PATCH] test: avoid dangerous mutable/sticky default value
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Incl. slight refactoring towards more frequent use of tuples where
advantage of lists are dubious.
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
---
script/unit-test.py.in | 34 ++++++++++++++++------------------
test/assertions.py | 2 +-
test/boothrunner.py | 14 +++++++-------
test/clientenv.py | 4 ++--
test/serverenv.py | 4 ++--
5 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/script/unit-test.py.in b/script/unit-test.py.in
index 4f3cf62..fc98bc1 100644
--- a/script/unit-test.py.in
+++ b/script/unit-test.py.in
@@ -199,7 +199,7 @@ class UT():
self.booth.close( force=self.booth.isalive() )
- def start_a_process(self, bin, env_add=[], **args):
+ def start_a_process(self, bin, env_add=(), **args):
name = re.sub(r".*/", "", bin)
# How to get stderr, too?
expct = pexpect.spawn(bin,
@@ -220,16 +220,15 @@ class UT():
def start_processes(self, test):
self.booth = self.start_a_process(self.binary,
- args = [ "daemon", "-D",
- "-c", self.test_base + "/booth.conf",
- "-s", "127.0.0.1",
- "-l", self.lockfile,
- ],
- env_add=[ ('UNIT_TEST', test),
+ args = ["daemon", "-D",
+ "-c", self.test_base + "/booth.conf",
+ "-s", "127.0.0.1",
+ "-l", self.lockfile],
+ env_add=( ('UNIT_TEST', test),
('UNIT_TEST_FILE', os.path.realpath(test)),
# provide some space, so that strcpy(getenv()) works
('UNIT_TEST_AUX', "".zfill(1024)),
- ]);
+ ));
logging.info("started booth with PID %d, lockfile %s" % (self.booth.pid, self.lockfile))
self.booth.expect("BOOTH site \S+ \(build \S+\) daemon is starting", timeout=2)
@@ -237,16 +236,15 @@ class UT():
self.gdb = self.start_a_process("gdb",
args=["-quiet",
- "-p", str(self.booth.pid),
- # Don't use .gdbinit
- "-nx", "-nh",
- # Run until the defined point.
- # This is necessary so that ticket state setting doesn't
- # happen _before_ the call to pcmk_load_ticket()
- # (which would overwrite our data)
- "-ex", "break ticket_cron",
- "-ex", "continue",
- ])
+ "-p", str(self.booth.pid),
+ # Don't use .gdbinit
+ "-nx", "-nh",
+ # Run until the defined point.
+ # This is necessary so that ticket state setting doesn't
+ # happen _before_ the call to pcmk_load_ticket()
+ # (which would overwrite our data)
+ "-ex", "break ticket_cron",
+ "-ex", "continue"])
logging.info("started GDB with PID %d" % self.gdb.pid)
self.gdb.expect("(gdb)")
self.gdb.sendline("set pagination off\n")
diff --git a/test/assertions.py b/test/assertions.py
index fafb291..db6fcd8 100644
--- a/test/assertions.py
+++ b/test/assertions.py
@@ -10,7 +10,7 @@ class BoothAssertions:
self.assertRegexpMatches(stderr, expected_error)
def assertLockFileError(self, config_file=None, config_text=None,
- lock_file=True, args=[]):
+ lock_file=True, args=()):
(pid, ret, stdout, stderr, runner) = \
self.run_booth(config_text=config_text, config_file=config_file,
lock_file=lock_file, args=args, expected_exitcode=1)
diff --git a/test/boothrunner.py b/test/boothrunner.py
index 31c2213..0285fe6 100644
--- a/test/boothrunner.py
+++ b/test/boothrunner.py
@@ -8,14 +8,14 @@ class BoothRunner:
def __init__(self, boothd_path, mode, args):
self.boothd_path = boothd_path
- self.args = [ mode ]
- self.final_args = args # will be appended to self.args
+ self.args = (mode, )
+ self.final_args = tuple(args) # will be appended to self.args
self.mode = mode
self.config_file = None
self.lock_file = None
def set_config_file_arg(self):
- self.args += [ '-c', self.config_file ]
+ self.args += ('-c', self.config_file)
def set_config_file(self, config_file):
self.config_file = config_file
@@ -23,16 +23,16 @@ class BoothRunner:
def set_lock_file(self, lock_file):
self.lock_file = lock_file
- self.args += [ '-l', self.lock_file ]
+ self.args += ('-l', self.lock_file)
def set_debug(self):
- self.args += [ '-D' ]
+ self.args += ('-D', )
def set_foreground(self):
- self.args += [ '-S' ]
+ self.args += ('-S', )
def all_args(self):
- return [ self.boothd_path ] + self.args + self.final_args
+ return (self.boothd_path, ) + self.args + self.final_args
def show_output(self, stdout, stderr):
if stdout:
diff --git a/test/clientenv.py b/test/clientenv.py
index 73b2791..141e33c 100644
--- a/test/clientenv.py
+++ b/test/clientenv.py
@@ -4,8 +4,8 @@ from boothrunner import BoothRunner
class ClientTestEnvironment(BoothTestEnvironment):
mode = 'client'
- def run_booth(self, config_text=None, config_file=None, lock_file=True, args=[],
- expected_exitcode=0, debug=False):
+ def run_booth(self, config_text=None, config_file=None, lock_file=True,
+ args=(), expected_exitcode=0, debug=False):
'''
Runs boothd.
diff --git a/test/serverenv.py b/test/serverenv.py
index 7b8915d..62c37d0 100644
--- a/test/serverenv.py
+++ b/test/serverenv.py
@@ -29,7 +29,7 @@ ticket="ticketB"
def run_booth(self, expected_exitcode, expected_daemon,
config_text=None, config_file=None, lock_file=True,
- args=[], debug=False, foreground=False):
+ args=(), debug=False, foreground=False):
'''
Runs boothd. Defaults to using a temporary lock file and the
standard config file path. There are four possible types of
@@ -52,7 +52,7 @@ ticket="ticketB"
True: pass a temporary lockfile parameter to booth via -l
string: pass the given lockfile path to booth via -l
args
- array of extra args to pass to booth
+ iterable of extra args to pass to booth
expected_exitcode
an integer, or False if booth is not expected to terminate
within the timeout
--
2.18.0.rc2