Blame SOURCES/0006-test-avoid-dangerous-mutable-sticky-default-value.patch

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