]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/py: Fix test script for Python3 tempfile
authorPhil Sutter <phil@nwl.cc>
Tue, 29 Oct 2019 11:20:18 +0000 (12:20 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 29 Oct 2019 12:16:35 +0000 (13:16 +0100)
When instantiating a temporary file using tempfile's TemporaryFile()
constructor, the resulting object's 'name' attribute is of type int.
This in turn makes print_msg() puke while trying to concatenate string
and int using '+' operator.

Fix this by using format strings consequently, thereby cleaning up code
a bit.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/py/nft-test.py

index bc0849e0410b564f76687d5064a1cf513a91576c..ce42b5ddb1ccac42d34503d7ff7c479e38b8896d 100755 (executable)
@@ -115,12 +115,12 @@ def print_msg(reason, errstr, filename=None, lineno=None, color=None):
     '''
     Prints a message with nice colors, indicating file and line number.
     '''
+    color_errstr = "%s%s%s" % (color, errstr, Colors.ENDC)
     if filename and lineno:
-        sys.stderr.write(filename + ": " + color + errstr + Colors.ENDC + \
-              " line %d: %s" % (lineno + 1, reason))
+        sys.stderr.write("%s: %s line %d: %s\n" %
+                         (filename, color_errstr, lineno + 1, reason))
     else:
-        sys.stderr.write(color + errstr + Colors.ENDC + " %s" % reason)
-    sys.stderr.write("\n")
+        sys.stderr.write("%s %s\n" % (color_errstr, reason))
     sys.stderr.flush() # So that the message stay in the right place.