Tests: pathlib used where appropriate

Also fixed various pylint errors and style issues.
This commit is contained in:
Andrei Zeliankou
2024-01-15 15:48:58 +00:00
parent e95a91cbfa
commit 5a8337933d
72 changed files with 306 additions and 256 deletions

View File

@@ -1,5 +1,6 @@
import os
import signal
from pathlib import Path
from unit.applications.lang.python import ApplicationPython
from unit.log import Log
@@ -23,14 +24,14 @@ def test_usr1_access_log(search_in_file, temp_dir, unit_pid, wait_for_record):
assert waitforfiles(log_path), 'open'
os.rename(log_path, f'{temp_dir}/{log_new}')
Path(log_path).rename(f'{temp_dir}/{log_new}')
assert client.get()['status'] == 200
assert (
wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', log_new) is not None
), 'rename new'
assert not os.path.isfile(log_path), 'rename old'
assert not Path(log_path).is_file(), 'rename old'
os.kill(unit_pid, signal.SIGUSR1)
@@ -51,7 +52,7 @@ def test_usr1_unit_log(search_in_file, temp_dir, unit_pid, wait_for_record):
log_path = f'{temp_dir}/unit.log'
log_path_new = f'{temp_dir}/{log_new}'
os.rename(log_path, log_path_new)
Path(log_path).rename(log_path_new)
Log.swap(log_new)
@@ -60,7 +61,7 @@ def test_usr1_unit_log(search_in_file, temp_dir, unit_pid, wait_for_record):
assert client.post(body=body)['status'] == 200
assert wait_for_record(body, log_new) is not None, 'rename new'
assert not os.path.isfile(log_path), 'rename old'
assert not Path(log_path).is_file(), 'rename old'
os.kill(unit_pid, signal.SIGUSR1)
@@ -75,13 +76,10 @@ def test_usr1_unit_log(search_in_file, temp_dir, unit_pid, wait_for_record):
finally:
# merge two log files into unit.log to check alerts
with open(log_path, 'r', errors='ignore') as unit_log:
log = unit_log.read()
with open(log_path, 'w') as unit_log, open(
log_path_new, 'r', errors='ignore'
) as unit_log_new:
unit_log.write(unit_log_new.read())
unit_log.write(log)
path_log = Path(log_path)
log = path_log.read_text(encoding='utf-8', errors='ignore') + Path(
log_path_new
).read_text(encoding='utf-8', errors='ignore')
path_log.write_text(log, encoding='utf-8', errors='ignore')
Log.swap(log_new)