diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2024-01-15 15:48:58 +0000 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2024-01-15 15:48:58 +0000 |
commit | 5a8337933df1cf3aba967d86549e236dd9173386 (patch) | |
tree | 30842acf799fc521702b1c4b070332c72feaaa1c /test/test_asgi_lifespan.py | |
parent | e95a91cbfac018b9877d9e389e614e9f2a9f1313 (diff) | |
download | unit-5a8337933df1cf3aba967d86549e236dd9173386.tar.gz unit-5a8337933df1cf3aba967d86549e236dd9173386.tar.bz2 |
Tests: pathlib used where appropriate
Also fixed various pylint errors and style issues.
Diffstat (limited to 'test/test_asgi_lifespan.py')
-rw-r--r-- | test/test_asgi_lifespan.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/test/test_asgi_lifespan.py b/test/test_asgi_lifespan.py index 5df7475e..e09ea1cc 100644 --- a/test/test_asgi_lifespan.py +++ b/test/test_asgi_lifespan.py @@ -1,7 +1,8 @@ -import os +from pathlib import Path -from conftest import unit_stop from packaging import version + +from conftest import unit_stop from unit.applications.lang.python import ApplicationPython from unit.option import option @@ -14,32 +15,26 @@ client = ApplicationPython(load_module='asgi') def assert_cookies(prefix): for name in ['startup', 'shutdown']: - path = f'{option.test_dir}/python/lifespan/empty/{prefix}{name}' - exists = os.path.isfile(path) - if exists: - os.remove(path) + path = Path(f'{option.test_dir}/python/lifespan/empty/{prefix}{name}') + exists = path.is_file() + path.unlink(missing_ok=True) assert not exists, name - path = f'{option.test_dir}/python/lifespan/empty/{prefix}version' + path = Path(f'{option.test_dir}/python/lifespan/empty/{prefix}version') + versions = path.read_text(encoding='utf-8') + path.unlink() - with open(path, 'r') as f: - version = f.read() - - os.remove(path) - - assert version == '3.0 2.0', 'version' + assert versions == '3.0 2.0', 'versions' def setup_cookies(prefix): - base_dir = f'{option.test_dir}/python/lifespan/empty' - - os.chmod(base_dir, 0o777) + base_dir = Path(f'{option.test_dir}/python/lifespan/empty') + base_dir.chmod(0o777) for name in ['startup', 'shutdown', 'version']: - path = f'{option.test_dir}/python/lifespan/empty/{prefix}{name}' - open(path, 'a').close() - os.chmod(path, 0o777) + path = Path(f'{option.test_dir}/python/lifespan/empty/{prefix}{name}') + path.touch(0o777) def test_asgi_lifespan(): |