Tests: switched to using f-strings.
Previously, it was necessary to support older versions of Python for compatibility. F-strings were released in Python 3.6. Python 3.5 was marked as unsupported by the end of 2020, so now it's possible to start using f-strings safely for better readability and performance.
This commit is contained in:
@@ -12,13 +12,13 @@ class TestAccessLog(TestApplicationPython):
|
||||
super().load(script)
|
||||
|
||||
assert 'success' in self.conf(
|
||||
'"' + option.temp_dir + '/access.log"', 'access_log'
|
||||
f'"{option.temp_dir}/access.log"', 'access_log'
|
||||
), 'access_log configure'
|
||||
|
||||
def set_format(self, format):
|
||||
assert 'success' in self.conf(
|
||||
{
|
||||
'path': option.temp_dir + '/access.log',
|
||||
'path': f'{option.temp_dir}/access.log',
|
||||
'format': format,
|
||||
},
|
||||
'access_log',
|
||||
@@ -103,13 +103,13 @@ Connection: close
|
||||
is not None
|
||||
), 'ipv6'
|
||||
|
||||
def test_access_log_unix(self):
|
||||
def test_access_log_unix(self, temp_dir):
|
||||
self.load('empty')
|
||||
|
||||
addr = option.temp_dir + '/sock'
|
||||
addr = f'{temp_dir}/sock'
|
||||
|
||||
assert 'success' in self.conf(
|
||||
{"unix:" + addr: {"pass": "applications/empty"}}, 'listeners'
|
||||
{f'unix:{addr}': {"pass": "applications/empty"}}, 'listeners'
|
||||
)
|
||||
|
||||
self.get(sock_type='unix', addr=addr)
|
||||
@@ -248,14 +248,12 @@ Connection: close
|
||||
|
||||
assert self.search_in_log(r'/delete', 'access.log') is None, 'delete'
|
||||
|
||||
def test_access_log_change(self):
|
||||
def test_access_log_change(self, temp_dir):
|
||||
self.load('empty')
|
||||
|
||||
self.get()
|
||||
|
||||
assert 'success' in self.conf(
|
||||
'"' + option.temp_dir + '/new.log"', 'access_log'
|
||||
)
|
||||
assert 'success' in self.conf(f'"{temp_dir}/new.log"', 'access_log')
|
||||
|
||||
self.get()
|
||||
|
||||
@@ -286,19 +284,20 @@ Connection: close
|
||||
body = '0123456789' * 50
|
||||
self.post(url='/bbs', body=body, read_timeout=1)
|
||||
assert (
|
||||
self.wait_for_record(r'^\/bbs ' + str(len(body)) + r'$') is not None
|
||||
self.wait_for_record(fr'^\/bbs {len(body)}$') is not None
|
||||
), '$body_bytes_sent'
|
||||
|
||||
def test_access_log_incorrect(self, skip_alert):
|
||||
def test_access_log_incorrect(self, temp_dir, skip_alert):
|
||||
skip_alert(r'failed to apply new conf')
|
||||
|
||||
assert 'error' in self.conf(
|
||||
option.temp_dir + '/blah/access.log' 'access_log/path',
|
||||
f'{option.temp_dir}/blah/access.log',
|
||||
'access_log/path',
|
||||
), 'access_log path incorrect'
|
||||
|
||||
assert 'error' in self.conf(
|
||||
{
|
||||
'path': option.temp_dir + '/access.log',
|
||||
'path': f'{temp_dir}/access.log',
|
||||
'format': '$remote_add',
|
||||
},
|
||||
'access_log',
|
||||
|
||||
Reference in New Issue
Block a user