summaryrefslogtreecommitdiffhomepage
path: root/test/unit
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2023-05-10 10:29:16 -0700
committerKonstantin Pavlov <thresh@nginx.com>2023-05-10 10:29:16 -0700
commit69235c513277c64b513447d9b92c3c03d616f577 (patch)
tree0780c92ba28d92b547c85ea0bee5e3040e14dee2 /test/unit
parentb9bc222021e77bbdfb12576b3e315b962cf6b399 (diff)
parentfaf97dc06058de1c929af33a68adb34d3932b374 (diff)
downloadunit-1.30.0-1.tar.gz
unit-1.30.0-1.tar.bz2
Merged with the default branch.1.30.0-1
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/applications/lang/go.py32
-rw-r--r--test/unit/applications/lang/java.py36
-rw-r--r--test/unit/applications/lang/node.py14
-rw-r--r--test/unit/applications/lang/perl.py8
-rw-r--r--test/unit/applications/lang/php.py16
-rw-r--r--test/unit/applications/lang/python.py16
-rw-r--r--test/unit/applications/lang/ruby.py14
-rw-r--r--test/unit/applications/tls.py44
-rw-r--r--test/unit/applications/websockets.py4
-rw-r--r--test/unit/check/chroot.py2
-rw-r--r--test/unit/check/isolation.py30
-rw-r--r--test/unit/check/node.py2
-rw-r--r--test/unit/check/unix_abstract.py2
-rw-r--r--test/unit/control.py4
-rw-r--r--test/unit/http.py36
-rw-r--r--test/unit/log.py2
-rw-r--r--test/unit/utils.py4
17 files changed, 129 insertions, 137 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index 14e76362..557753a4 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -14,23 +14,21 @@ class TestApplicationGo(TestApplicationProto):
except subprocess.CalledProcessError:
return None
- temp_dir = option.temp_dir + '/go/'
+ temp_dir = f'{option.temp_dir}/go/'
if not os.path.exists(temp_dir):
os.mkdir(temp_dir)
- cache_dir = option.cache_dir + '/go-build'
+ cache_dir = f'{option.cache_dir}/go-build'
if not os.path.exists(cache_dir):
os.mkdir(cache_dir)
env = os.environ.copy()
- env['GOPATH'] = option.current_dir + '/build/go'
+ env['GOPATH'] = f'{option.current_dir}/build/go'
env['GOCACHE'] = cache_dir
- shutil.copy2(
- option.test_dir + '/go/' + script + '/' + name + '.go', temp_dir
- )
+ shutil.copy2(f'{option.test_dir}/go/{script}/{name}.go', temp_dir)
if static:
args = [
@@ -41,21 +39,21 @@ class TestApplicationGo(TestApplicationProto):
'-ldflags',
'-extldflags "-static"',
'-o',
- temp_dir + name,
- temp_dir + name + '.go',
+ f'{temp_dir}{name}',
+ f'{temp_dir}{name}.go',
]
else:
args = [
'go',
'build',
'-o',
- temp_dir + name,
- temp_dir + name + '.go',
+ f'{temp_dir}{name}',
+ f'{temp_dir}{name}.go',
]
- replace_path = option.current_dir + '/build/go/src/unit.nginx.org/go'
+ replace_path = f'{option.current_dir}/build/go/src/unit.nginx.org/go'
- with open(temp_dir + 'go.mod', 'w') as f:
+ with open(f'{temp_dir}go.mod', 'w') as f:
f.write(
f"""module test/app
require unit.nginx.org/go v0.0.0
@@ -64,7 +62,7 @@ replace unit.nginx.org/go => {replace_path}
)
if option.detailed:
- print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
+ print(f'\n$ GOPATH={env["GOPATH"]} {" ".join(args)}')
try:
output = subprocess.check_output(
@@ -82,18 +80,18 @@ replace unit.nginx.org/go => {replace_path}
def load(self, script, name='app', **kwargs):
static_build = False
- wdir = option.test_dir + "/go/" + script
- executable = option.temp_dir + "/go/" + name
+ wdir = f'{option.test_dir}/go/{script}'
+ executable = f'{option.temp_dir}/go/{name}'
if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
wdir = "/go/"
- executable = "/go/" + name
+ executable = f"/go/{name}"
static_build = True
TestApplicationGo.prepare_env(script, name, static=static_build)
conf = {
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {"*:7080": {"pass": f"applications/{script}"}},
"applications": {
script: {
"type": "external",
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
index c8936274..b6382cfe 100644
--- a/test/unit/applications/lang/java.py
+++ b/test/unit/applications/lang/java.py
@@ -12,10 +12,10 @@ class TestApplicationJava(TestApplicationProto):
application_type = "java"
def prepare_env(self, script):
- app_path = option.temp_dir + '/java'
- web_inf_path = app_path + '/WEB-INF/'
- classes_path = web_inf_path + 'classes/'
- script_path = option.test_dir + '/java/' + script + '/'
+ app_path = f'{option.temp_dir}/java'
+ web_inf_path = f'{app_path}/WEB-INF/'
+ classes_path = f'{web_inf_path}classes/'
+ script_path = f'{option.test_dir}/java/{script}/'
if not os.path.isdir(app_path):
os.makedirs(app_path)
@@ -23,7 +23,7 @@ class TestApplicationJava(TestApplicationProto):
src = []
for f in os.listdir(script_path):
- file_path = script_path + f
+ file_path = f'{script_path}{f}'
if f.endswith('.java'):
src.append(file_path)
@@ -36,7 +36,7 @@ class TestApplicationJava(TestApplicationProto):
if f == 'WEB-INF':
continue
- shutil.copytree(file_path, app_path + '/' + f)
+ shutil.copytree(file_path, f'{app_path}/{f}')
continue
if f == 'web.xml':
@@ -52,11 +52,11 @@ class TestApplicationJava(TestApplicationProto):
os.makedirs(classes_path)
classpath = (
- option.current_dir + '/build/tomcat-servlet-api-9.0.70.jar'
+ f'{option.current_dir}/build/tomcat-servlet-api-9.0.70.jar'
)
ws_jars = glob.glob(
- option.current_dir + '/build/websocket-api-java-*.jar'
+ f'{option.current_dir}/build/websocket-api-java*.jar'
)
if not ws_jars:
@@ -74,12 +74,12 @@ class TestApplicationJava(TestApplicationProto):
'-d',
classes_path,
'-classpath',
- classpath + ':' + ws_jars[0],
+ f'{classpath}:{ws_jars[0]}',
]
javac.extend(src)
if option.detailed:
- print("\n$ " + " ".join(javac))
+ print(f'\n$ {" ".join(javac)}')
try:
subprocess.check_output(javac, stderr=subprocess.STDOUT)
@@ -88,26 +88,24 @@ class TestApplicationJava(TestApplicationProto):
raise
except subprocess.CalledProcessError:
- pytest.fail('Can\'t run javac process.')
+ pytest.fail("Can't run javac process.")
def load(self, script, **kwargs):
self.prepare_env(script)
+ script_path = f'{option.test_dir}/java/{script}/'
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {"*:7080": {"pass": f"applications/{script}"}},
"applications": {
script: {
- "unit_jars": option.current_dir + '/build',
+ "unit_jars": f'{option.current_dir}/build',
"type": self.get_application_type(),
"processes": {"spare": 0},
- "working_directory": option.test_dir
- + '/java/'
- + script
- + '/',
- "webapp": option.temp_dir + '/java',
+ "working_directory": script_path,
+ "webapp": f'{option.temp_dir}/java',
}
},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index 5d05c70c..87d5a19c 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -13,16 +13,16 @@ class TestApplicationNode(TestApplicationProto):
def prepare_env(self, script):
# copy application
shutil.copytree(
- option.test_dir + '/node/' + script, option.temp_dir + '/node'
+ f'{option.test_dir}/node/{script}', f'{option.temp_dir}/node'
)
# copy modules
shutil.copytree(
- option.current_dir + '/node/node_modules',
- option.temp_dir + '/node/node_modules',
+ f'{option.current_dir}/node/node_modules',
+ f'{option.temp_dir}/node/node_modules',
)
- public_dir(option.temp_dir + '/node')
+ public_dir(f'{option.temp_dir}/node')
def load(self, script, name='app.js', **kwargs):
self.prepare_env(script)
@@ -43,17 +43,17 @@ class TestApplicationNode(TestApplicationProto):
self._load_conf(
{
"listeners": {
- "*:7080": {"pass": "applications/" + quote(script, '')}
+ "*:7080": {"pass": f"applications/{quote(script, '')}"}
},
"applications": {
script: {
"type": "external",
"processes": {"spare": 0},
- "working_directory": option.temp_dir + '/node',
+ "working_directory": f'{option.temp_dir}/node',
"executable": '/usr/bin/env',
"arguments": arguments,
}
},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py
index 58b867f0..19852363 100644
--- a/test/unit/applications/lang/perl.py
+++ b/test/unit/applications/lang/perl.py
@@ -6,19 +6,19 @@ class TestApplicationPerl(TestApplicationProto):
application_type = "perl"
def load(self, script, name='psgi.pl', **kwargs):
- script_path = option.test_dir + '/perl/' + script
+ script_path = f'{option.test_dir}/perl/{script}'
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {"*:7080": {"pass": f"applications/{script}"}},
"applications": {
script: {
"type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
- "script": script_path + '/' + name,
+ "script": f'{script_path}/{name}',
}
},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py
index 5319d2ca..1b94c3ae 100644
--- a/test/unit/applications/lang/php.py
+++ b/test/unit/applications/lang/php.py
@@ -9,18 +9,18 @@ class TestApplicationPHP(TestApplicationProto):
application_type = "php"
def load(self, script, index='index.php', **kwargs):
- script_path = option.test_dir + '/php/' + script
+ script_path = f'{option.test_dir}/php/{script}'
if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
rootfs = kwargs['isolation']['rootfs']
- if not os.path.exists(rootfs + '/app/php/'):
- os.makedirs(rootfs + '/app/php/')
+ if not os.path.exists(f'{rootfs}/app/php/'):
+ os.makedirs(f'{rootfs}/app/php/')
- if not os.path.exists(rootfs + '/app/php/' + script):
- shutil.copytree(script_path, rootfs + '/app/php/' + script)
+ if not os.path.exists(f'{rootfs}/app/php/{script}'):
+ shutil.copytree(script_path, f'{rootfs}/app/php/{script}')
- script_path = '/app/php/' + script
+ script_path = f'/app/php/{script}'
app = {
"type": self.get_application_type(),
@@ -41,8 +41,8 @@ class TestApplicationPHP(TestApplicationProto):
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {"*:7080": {"pass": f"applications/{script}"}},
"applications": {script: app},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
index 3768cf07..0bb69992 100644
--- a/test/unit/applications/lang/python.py
+++ b/test/unit/applications/lang/python.py
@@ -20,18 +20,18 @@ class TestApplicationPython(TestApplicationProto):
if script[0] == '/':
script_path = script
else:
- script_path = option.test_dir + '/python/' + script
+ script_path = f'{option.test_dir}/python/{script}'
if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
rootfs = kwargs['isolation']['rootfs']
- if not os.path.exists(rootfs + '/app/python/'):
- os.makedirs(rootfs + '/app/python/')
+ if not os.path.exists(f'{rootfs}/app/python/'):
+ os.makedirs(f'{rootfs}/app/python/')
- if not os.path.exists(rootfs + '/app/python/' + name):
- shutil.copytree(script_path, rootfs + '/app/python/' + name)
+ if not os.path.exists(f'{rootfs}/app/python/{name}'):
+ shutil.copytree(script_path, f'{rootfs}/app/python/{name}')
- script_path = '/app/python/' + name
+ script_path = f'/app/python/{name}'
app = {
"type": self.get_application_type(),
@@ -58,9 +58,9 @@ class TestApplicationPython(TestApplicationProto):
self._load_conf(
{
"listeners": {
- "*:7080": {"pass": "applications/" + quote(name, '')}
+ "*:7080": {"pass": f"applications/{quote(name, '')}"}
},
"applications": {name: app},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py
index 824bfe7f..e0712fc6 100644
--- a/test/unit/applications/lang/ruby.py
+++ b/test/unit/applications/lang/ruby.py
@@ -10,22 +10,22 @@ class TestApplicationRuby(TestApplicationProto):
def prepare_env(self, script):
shutil.copytree(
- option.test_dir + '/ruby/' + script,
- option.temp_dir + '/ruby/' + script,
+ f'{option.test_dir}/ruby/{script}',
+ f'{option.temp_dir}/ruby/{script}',
)
- public_dir(option.temp_dir + '/ruby/' + script)
+ public_dir(f'{option.temp_dir}/ruby/{script}')
def load(self, script, name='config.ru', **kwargs):
self.prepare_env(script)
- script_path = option.temp_dir + '/ruby/' + script
+ script_path = f'{option.temp_dir}/ruby/{script}'
app = {
"type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
- "script": script_path + '/' + name,
+ "script": f'{script_path}/{name}',
}
for key in [
@@ -36,8 +36,8 @@ class TestApplicationRuby(TestApplicationProto):
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + script}},
+ "listeners": {"*:7080": {"pass": f"applications/{script}"}},
"applications": {script: app},
},
- **kwargs
+ **kwargs,
)
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index 93400328..e5813312 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -22,13 +22,13 @@ class TestApplicationTLS(TestApplicationProto):
'-x509',
'-new',
'-subj',
- '/CN=' + name + '/',
+ f'/CN={name}/',
'-config',
- option.temp_dir + '/openssl.conf',
+ f'{option.temp_dir}/openssl.conf',
'-out',
- option.temp_dir + '/' + name + '.crt',
+ f'{option.temp_dir}/{name}.crt',
'-keyout',
- option.temp_dir + '/' + name + '.key',
+ f'{option.temp_dir}/{name}.key',
],
stderr=subprocess.STDOUT,
)
@@ -40,11 +40,11 @@ class TestApplicationTLS(TestApplicationProto):
if key is None:
key = crt
- key_path = option.temp_dir + '/' + key + '.key'
- crt_path = option.temp_dir + '/' + crt + '.crt'
+ key_path = f'{option.temp_dir}/{key}.key'
+ crt_path = f'{option.temp_dir}/{crt}.crt'
with open(key_path, 'rb') as k, open(crt_path, 'rb') as c:
- return self.conf(k.read() + c.read(), '/certificates/' + crt)
+ return self.conf(k.read() + c.read(), f'/certificates/{crt}')
def get_ssl(self, **kwargs):
return self.get(wrapper=self.context.wrap_socket, **kwargs)
@@ -52,54 +52,50 @@ class TestApplicationTLS(TestApplicationProto):
def post_ssl(self, **kwargs):
return self.post(wrapper=self.context.wrap_socket, **kwargs)
- def openssl_conf(self, rewrite=False, alt_names=[]):
- conf_path = option.temp_dir + '/openssl.conf'
+ def openssl_conf(self, rewrite=False, alt_names=None):
+ alt_names = alt_names or []
+ conf_path = f'{option.temp_dir}/openssl.conf'
if not rewrite and os.path.exists(conf_path):
return
# Generates alt_names section with dns names
- a_names = "[alt_names]\n"
+ a_names = '[alt_names]\n'
for i, k in enumerate(alt_names, 1):
k = k.split('|')
if k[0] == 'IP':
- a_names += "IP.%d = %s\n" % (i, k[1])
+ a_names += f'IP.{i} = {k[1]}\n'
else:
- a_names += "DNS.%d = %s\n" % (i, k[0])
+ a_names += f'DNS.{i} = {k[0]}\n'
# Generates section for sign request extension
- a_sec = """req_extensions = myca_req_extensions
+ a_sec = f'''req_extensions = myca_req_extensions
[ myca_req_extensions ]
subjectAltName = @alt_names
-{a_names}""".format(
- a_names=a_names
- )
+{a_names}'''
with open(conf_path, 'w') as f:
f.write(
- """[ req ]
+ f'''[ req ]
default_bits = 2048
encrypt_key = no
distinguished_name = req_distinguished_name
-{a_sec}
-[ req_distinguished_name ]""".format(
- a_sec=a_sec if alt_names else ""
- )
+{a_sec if alt_names else ""}
+[ req_distinguished_name ]'''
)
def load(self, script, name=None):
if name is None:
name = script
- script_path = option.test_dir + '/python/' + script
-
+ script_path = f'{option.test_dir}/python/{script}'
self._load_conf(
{
- "listeners": {"*:7080": {"pass": "applications/" + name}},
+ "listeners": {"*:7080": {"pass": f"applications/{name}"}},
"applications": {
name: {
"type": "python",
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index 15f212ff..a4b9287d 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -52,7 +52,7 @@ class TestApplicationWebsocket(TestApplicationProto):
while True:
rlist = select.select([sock], [], [], 60)[0]
if not rlist:
- pytest.fail('Can\'t read response from server.')
+ pytest.fail("Can't read response from server.")
resp += sock.recv(4096).decode()
@@ -77,7 +77,7 @@ class TestApplicationWebsocket(TestApplicationProto):
# For all current cases if the "read_timeout" was changed
# than test do not expect to get a response from server.
if read_timeout == 60:
- pytest.fail('Can\'t read response from server.')
+ pytest.fail("Can't read response from server.")
break
data += sock.recv(bytes - len(data))
diff --git a/test/unit/check/chroot.py b/test/unit/check/chroot.py
index 40b75058..1b7aae90 100644
--- a/test/unit/check/chroot.py
+++ b/test/unit/check/chroot.py
@@ -12,7 +12,7 @@ def check_chroot():
resp = http.put(
url='/config',
sock_type='unix',
- addr=option.temp_dir + '/control.unit.sock',
+ addr=f'{option.temp_dir}/control.unit.sock',
body=json.dumps(
{
"listeners": {"*:7080": {"pass": "routes"}},
diff --git a/test/unit/check/isolation.py b/test/unit/check/isolation.py
index 9bd835a3..4ebce893 100644
--- a/test/unit/check/isolation.py
+++ b/test/unit/check/isolation.py
@@ -27,8 +27,8 @@ def check_isolation():
"empty": {
"type": "external",
"processes": {"spare": 0},
- "working_directory": option.test_dir + "/go/empty",
- "executable": option.temp_dir + "/go/app",
+ "working_directory": f"{option.test_dir}/go/empty",
+ "executable": f"{option.test_dir}/go/app",
"isolation": {"namespaces": {"credential": True}},
},
},
@@ -41,8 +41,8 @@ def check_isolation():
"empty": {
"type": "python",
"processes": {"spare": 0},
- "path": option.test_dir + "/python/empty",
- "working_directory": option.test_dir + "/python/empty",
+ "path": f"{option.test_dir}/python/empty",
+ "working_directory": f"{option.test_dir}/python/empty",
"module": "wsgi",
"isolation": {"namespaces": {"credential": True}},
}
@@ -56,8 +56,8 @@ def check_isolation():
"phpinfo": {
"type": "php",
"processes": {"spare": 0},
- "root": option.test_dir + "/php/phpinfo",
- "working_directory": option.test_dir + "/php/phpinfo",
+ "root": f"{option.test_dir}/php/phpinfo",
+ "working_directory": f"{option.test_dir}/php/phpinfo",
"index": "index.php",
"isolation": {"namespaces": {"credential": True}},
}
@@ -73,8 +73,8 @@ def check_isolation():
"empty": {
"type": "ruby",
"processes": {"spare": 0},
- "working_directory": option.temp_dir + "/ruby/empty",
- "script": option.temp_dir + "/ruby/empty/config.ru",
+ "working_directory": f"{option.temp_dir}/ruby/empty",
+ "script": f"{option.temp_dir}/ruby/empty/config.ru",
"isolation": {"namespaces": {"credential": True}},
}
},
@@ -87,11 +87,11 @@ def check_isolation():
"listeners": {"*:7080": {"pass": "applications/empty"}},
"applications": {
"empty": {
- "unit_jars": option.current_dir + "/build",
+ "unit_jars": f"{option.current_dir}/build",
"type": "java",
"processes": {"spare": 0},
- "working_directory": option.test_dir + "/java/empty/",
- "webapp": option.temp_dir + "/java",
+ "working_directory": f"{option.temp_dir}/java/empty/",
+ "webapp": f"{option.temp_dir}/java",
"isolation": {"namespaces": {"credential": True}},
}
},
@@ -106,7 +106,7 @@ def check_isolation():
"basic": {
"type": "external",
"processes": {"spare": 0},
- "working_directory": option.temp_dir + "/node",
+ "working_directory": f"{option.temp_dir}/node",
"executable": "app.js",
"isolation": {"namespaces": {"credential": True}},
}
@@ -120,8 +120,8 @@ def check_isolation():
"body_empty": {
"type": "perl",
"processes": {"spare": 0},
- "working_directory": option.test_dir + "/perl/body_empty",
- "script": option.test_dir + "/perl/body_empty/psgi.pl",
+ "working_directory": f"{option.test_dir}/perl/body_empty",
+ "script": f"{option.test_dir}/perl/body_empty/psgi.pl",
"isolation": {"namespaces": {"credential": True}},
}
},
@@ -133,7 +133,7 @@ def check_isolation():
resp = http.put(
url='/config',
sock_type='unix',
- addr=option.temp_dir + '/control.unit.sock',
+ addr=f'{option.temp_dir}/control.unit.sock',
body=json.dumps(conf),
)
diff --git a/test/unit/check/node.py b/test/unit/check/node.py
index e053a749..dd59e7a4 100644
--- a/test/unit/check/node.py
+++ b/test/unit/check/node.py
@@ -3,7 +3,7 @@ import subprocess
def check_node(current_dir):
- if not os.path.exists(current_dir + '/node/node_modules'):
+ if not os.path.exists(f'{current_dir}/node/node_modules'):
return None
try:
diff --git a/test/unit/check/unix_abstract.py b/test/unit/check/unix_abstract.py
index 5d1f629e..aadde43a 100644
--- a/test/unit/check/unix_abstract.py
+++ b/test/unit/check/unix_abstract.py
@@ -12,7 +12,7 @@ def check_unix_abstract():
resp = http.put(
url='/config',
sock_type='unix',
- addr=option.temp_dir + '/control.unit.sock',
+ addr=f'{option.temp_dir}/control.unit.sock',
body=json.dumps(
{
"listeners": {"unix:@sock": {"pass": "routes"}},
diff --git a/test/unit/control.py b/test/unit/control.py
index 99436ca0..61b6edf4 100644
--- a/test/unit/control.py
+++ b/test/unit/control.py
@@ -21,7 +21,7 @@ def args_handler(conf_func):
url = args[1] if len(args) == 2 else url_default
- url = url if url.startswith('/') else url_default + '/' + url
+ url = url if url.startswith('/') else f'{url_default}/{url}'
arguments = (self, url) if conf is None else (self, conf, url)
return json.loads(conf_func(*arguments))
@@ -50,7 +50,7 @@ class TestControl(TestHTTP):
args = {
'url': url,
'sock_type': 'unix',
- 'addr': option.temp_dir + '/control.unit.sock',
+ 'addr': f'{option.temp_dir}/control.unit.sock',
}
if conf is not None:
diff --git a/test/unit/http.py b/test/unit/http.py
index c48a720f..6a267e26 100644
--- a/test/unit/http.py
+++ b/test/unit/http.py
@@ -53,13 +53,13 @@ class TestHTTP:
sock.connect(connect_args)
except (ConnectionRefusedError, FileNotFoundError):
sock.close()
- pytest.fail('Client can\'t connect to the server.')
+ pytest.fail("Client can't connect to the server.")
else:
sock = kwargs['sock']
if 'raw' not in kwargs:
- req = ' '.join([start_str, url, http]) + crlf
+ req = f'{start_str} {url} {http}{crlf}'
if body != b'':
if isinstance(body, str):
@@ -75,10 +75,10 @@ class TestHTTP:
for header, value in headers.items():
if isinstance(value, list):
for v in value:
- req += header + ': ' + str(v) + crlf
+ req += f'{header}: {v}{crlf}'
else:
- req += header + ': ' + str(value) + crlf
+ req += f'{header}: {value}{crlf}'
req = (req + crlf).encode() + body
@@ -151,12 +151,12 @@ class TestHTTP:
len_log = len(log)
if len_log > limit:
log = log[:limit]
- appendix = '(...logged %s of %s bytes)' % (limit, len_log)
+ appendix = f'(...logged {limit} of {len_log} bytes)'
if isinstance(log, bytes):
appendix = appendix.encode()
- log = log + appendix
+ log = f'{log}{appendix}'
return log
@@ -188,7 +188,7 @@ class TestHTTP:
# For all current cases if the "read_timeout" was changed
# than test do not expect to get a response from server.
if timeout == timeout_default:
- pytest.fail('Can\'t read response from server.')
+ pytest.fail("Can't read response from server.")
break
try:
@@ -263,7 +263,7 @@ class TestHTTP:
size = int(chunks.pop(0), 16)
except ValueError:
- pytest.fail('Invalid chunk size %s' % str(size))
+ pytest.fail(f'Invalid chunk size {size}')
if size == 0:
assert len(chunks) == 1, 'last zero size'
@@ -310,7 +310,7 @@ class TestHTTP:
def form_url_encode(self, fields):
data = "&".join(
- "%s=%s" % (name, value) for name, value in fields.items()
+ f'{name}={value}' for name, value in fields.items()
).encode()
return data, 'application/x-www-form-urlencoded'
@@ -341,21 +341,21 @@ class TestHTTP:
else:
pytest.fail('multipart requires a string or stream data')
- body += ("--%s\r\nContent-Disposition: form-data; name=\"%s\"") % (
- boundary,
- field,
+ body += (
+ f'--{boundary}\r\nContent-Disposition: form-data;'
+ f'name="{field}"'
)
if filename != '':
- body += "; filename=\"%s\"" % filename
+ body += f'; filename="{filename}"'
- body += "\r\n"
+ body += '\r\n'
if datatype != '':
- body += "Content-Type: %s\r\n" % datatype
+ body += f'Content-Type: {datatype}\r\n'
- body += "\r\n%s\r\n" % data
+ body += f'\r\n{data}\r\n'
- body += "--%s--\r\n" % boundary
+ body += f'--{boundary}--\r\n'
- return body.encode(), "multipart/form-data; boundary=%s" % boundary
+ return body.encode(), f'multipart/form-data; boundary={boundary}'
diff --git a/test/unit/log.py b/test/unit/log.py
index 7263443d..f984d7a1 100644
--- a/test/unit/log.py
+++ b/test/unit/log.py
@@ -20,4 +20,4 @@ class Log:
Log.pos[name] = pos
def get_path(name=UNIT_LOG):
- return Log.temp_dir + '/' + name
+ return f'{Log.temp_dir}/{name}'
diff --git a/test/unit/utils.py b/test/unit/utils.py
index d6590b97..985801e2 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -69,7 +69,7 @@ def waitforsocket(port):
except KeyboardInterrupt:
raise
- pytest.fail('Can\'t connect to the 127.0.0.1:' + str(port))
+ pytest.fail(f"Can't connect to the 127.0.0.1:{port}")
def check_findmnt():
@@ -125,7 +125,7 @@ def getns(nstype):
# read namespace id from symlink file:
# it points to: '<nstype>:[<ns id>]'
# # eg.: 'pid:[4026531836]'
- nspath = '/proc/self/ns/' + nstype
+ nspath = f'/proc/self/ns/{nstype}'
data = None
if os.path.exists(nspath):